我正在爲我的應用程序編寫測試套件並使用bash腳本來檢查測試套件輸出是否與預期輸出匹配。下面是一段腳本:將輸入發送到bash的運行shell腳本
for filename in test/*.bcs ;
do
./BCSC $filename > /dev/null
NUMBER=`echo "$filename" | awk -F"[./]" '{print $2}'`
gcc -g -m32 -mstackrealign runtime.c $filename.s -o test/e$NUMBER
# run the file and diff against expected output
echo "Running test file... "$filename
test/e$NUMBER > test/e$NUMBER.out
if [ $NUMBER = "4" ]
then
# it's trying to read the line
# Pass some input to the file...
fi
diff test/e$NUMBER.out test/o$NUMBER.out
done
測試#4測試從標準輸入讀取輸入。我想測試腳本#4,如果是的話,傳遞一組樣本輸入。
我才意識到,你可以不喜歡它
test/e4 <test/e4.in> test/e4.out
其中e4.in具有樣本輸入。是否有另一種方法將輸入傳遞給正在運行的腳本?
對不起,我想'expect'類似的東西,我猜想,但不知道如何有條件地做,並在shell腳本。 – 2011-04-30 22:39:38