Skip to content

Commit a2e6f44

Browse files
committed
add support for testing multiple source files
1 parent c7a4e65 commit a2e6f44

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

scripts/test.sh

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ JS_SLANG="node node_modules/js-slang/dist/repl/repl.js"
44

55
SOURCEFILES=src/*/*.js
66
SOURCE_TEST="src/test/framework/main.js"
7-
SOURCE_TEST_FILENAME="source-test.js"
87

98
red=`tput setaf 1`
109
green=`tput setaf 2`
@@ -33,7 +32,7 @@ $DIFF"
3332
# $1 is the source file to be tested
3433
# $2 is the Source test file which uses the source-test framework
3534
test_source_framework() {
36-
# run concatenation of source-test framework and test file
35+
# run concatenation of source-test framework, source and test files
3736
RESULTS=$($JS_SLANG -e --chapter=4 "$(cat $SOURCE_TEST $1 $2)")
3837

3938
# retrieve names for tests that passed
@@ -65,17 +64,14 @@ main() {
6564
# call test_source on each test case in __tests__
6665
for i in "$DIR/__tests__/$(basename ${s} .js)".*
6766
do
68-
test_source $s $i
69-
done
70-
71-
# check if source-test framework is being used
72-
TEST_PATH="$DIR/__tests__/$SOURCE_TEST_FILENAME"
73-
if [ -e $TEST_PATH ]
74-
then
75-
test_source_framework $s $TEST_PATH
76-
fi
67+
# check if first line of test file contains '// source-test'
68+
use_source_test=$(awk 'FNR==1{if ($0~"//[[:space:]]*source-test") print "yes";}' $i)
69+
if [[ $use_source_test == "yes" ]]
70+
then test_source_framework $s $i
71+
else test_source $s $i
72+
fi
73+
done
7774
fi
78-
7975
done
8076
}
8177

0 commit comments

Comments
 (0)