2012-05-11 3 views
0

mavenタスクへの引数としてテストファイルを提供して、たくさんの(maven)テストを実行する必要があります。与えられたディレクトリからの入力で特定のプログラムを実行するスクリプト

このような何か:

mvn clean test -Dtest=<filename>

とテストファイルは、通常、異なるディレクトリに編成されています。だから私は上記の 'コマンド'を実行し、指定されたディレクトリ内のすべてのファイルの名前を自動的に-Dtestに送るスクリプトを作成しようとしています。

だから私は「RUN_TEST」と呼ばれるシェルスクリプトで始まっ:私が捕まってしまった部分は、ファイル名のリストを取得する方法である

#!/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

$1は、(ユーザー入力の検証は別の問題である)ディレクトリ名が含まれ、その後、

for file in $1/* 
do 
    [[ -f $file ]] && mvn clean test -Dtest=$file 
done 

は、すべてのファイルでCOMANDを実行しますと仮定。あなたがサブディレクトリに再帰したいなら、あなたは<ディレクトリ>引数は、私だけのディレクトリの名前ではなく、場所を与えたらどうfindコマンド

for file in $(find $1 -type f) 
do 
    etc... 
done 
+0

を使用する必要があります。言い換えれば、私は与えられたディレクトリが '/ 'のどこかにあることを確かに知っています。それはどこにでもある可能性があります。だから、私は '$($ 1 -typeを見つける)'(ディレクトリの場合は?)の 'for file 'を使うべきですか? –

+0

'[[-f $ file]]'の意味は何ですか? –

+0

上記のうちの1つを 'for dir in $(find。-type d -name $ 1);で囲みます。 do ... inner loop ... done' –

1
#! /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) 
関連する問題