因此,我需要运行一系列( maven )测试,并将testfiles作为参数提供给maven任务。
如下所示:
mvn clean test -Dtest=<filename>
测试文件通常被组织到不同的目录中。因此,我正在尝试编写一个脚本,它将执行上面的“命令”,并自动将给定目录中所有文件的名称提供给-Dtest。
所以我从一个名为‘run_test’的So脚本开始:
#!/bin/sh
if test $# -lt 2; then
echo "$0: insufficient arguments on the command line." >&1
echo "usage: $0 run_test dirctory" >&1
exit 1
fi
for file in allFiles <<<<<<< what should I put here? Can I somehow iterate thru the list of all files' name in the given directory put the file name here?
do mvn clean test -Dtest= $file
exit $?我被卡住的部分是如何获得文件名列表。谢谢,
发布于 2012-05-12 03:52:39
假设$1包含目录名(验证用户输入是一个单独的问题),那么
for file in $1/*
do
[[ -f $file ]] && mvn clean test -Dtest=$file
done将在所有文件上运行命令。如果想要递归到子目录中,则需要使用find命令
for file in $(find $1 -type f)
do
etc...
done发布于 2012-05-12 03:50:44
#! /bin/sh
# Set IFS to newline to minimise problems with whitespace in file/directory
# names. If we also need to deal with newlines, we will need to use
# find -print0 | xargs -0 instead of a for loop.
IFS="
"
if ! [[ -d "${1}" ]]; then
echo "Please supply a directory name" > &2
exit 1
else
# We use find rather than glob expansion in case there are nested directories.
# We sort the filenames so that we execute the tests in a predictable order.
for pathname in $(find "${1}" -type f | LC_ALL=C sort) do
mvn clean test -Dtest="${pathname}" || break
done
fi
# exit $? would be superfluous (it is the default)https://stackoverflow.com/questions/10557615
复制相似问题