所以我需要运行一堆 (maven) 测试,并将测试文件作为参数提供给 maven 任务。
像这样:
mvn clean test -Dtest=<filename>
并且测试文件通常被组织到不同的目录中。所以我正在尝试编写一个脚本来执行上面的“命令”并自动将给定目录中所有文件的名称提供给 -Dtest
.
所以我从一个名为“run_test”的 shellscript 开始:
#!/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 $?
我遇到困难的部分是如何获取文件名列表。 谢谢,
最佳答案
假设 $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
关于testing - 使用给定目录的输入运行特定程序的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10557615/