@@ -5,6 +5,9 @@ JS_SLANG="node node_modules/js-slang/dist/repl/repl.js"
55SOURCEFILES=src/* /* .js
66SOURCE_TEST=" src/test/framework/main.js"
77
8+ DEFAULT_CHAP=4
9+ DEFAULT_VARIANT=" default"
10+
811red=` tput setaf 1`
912green=` tput setaf 2`
1013normal=` tput setaf 7`
@@ -14,11 +17,14 @@ failed=0
1417
1518# $1 is the source file to be tested
1619# $2 is the test file
20+ # $3 is the chapter
21+ # $4 is the variant
22+
1723test_source () {
1824
1925 # run concatenation of source and test case
2026 # compare the result with the commented last line in test case
21- DIFF=$( diff <( $JS_SLANG -e --chapter=4 " $( cat $1 $2 ) " ) \
27+ DIFF=$( diff <( $JS_SLANG -e --chapter=$3 --variant= $ 4 " $( cat $1 $2 ) " ) \
2228 <( cat $2 | tail -1 | cut -c4-) )
2329
2430 if [ " $DIFF " = " " ]
@@ -29,18 +35,17 @@ $DIFF"
2935
3036}
3137
32- # $1 is the source file to be tested
33- # $2 is the Source test file which uses the source-test framework
3438test_source_framework () {
39+
3540 # run concatenation of source-test framework, source and test files
36- RESULTS=$( $JS_SLANG -e --chapter=4 " $( cat $SOURCE_TEST $1 $2 ) " )
41+ RESULTS=$( $JS_SLANG -e --chapter=$3 --variant= $ 4 " $( cat $SOURCE_TEST $1 $2 ) " )
3742
3843 # retrieve names for tests that passed
3944 while read test_name
4045 do
4146 passed=$(( $passed + 1 ))
4247 echo " ${green} PASS $2 $test_name "
43- done < <( echo ${RESULTS} | grep -o ' \w* PASSED' | awk -F ' PASSED' ' {print $1}' )
48+ done < <( echo ${RESULTS} | grep -o ' \w* PASSED' | awk -F ' PASSED' ' { print $1 }' )
4449
4550 # retrieve names and error messages for tests that failed
4651 while read test_info
@@ -64,11 +69,17 @@ main() {
6469 # call test_source on each test case in __tests__
6570 for i in " $DIR /__tests__/$( basename ${s} .js) " .*
6671 do
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 )
72+ # check if first line of test file contains 'chap=' and retrieve its value. Set to the default chapter if it does not
73+ chap=$( awk -F ' chap=' ' FNR==1{ if ($0~"chap=") { print $2 } else { print ' $DEFAULT_CHAP ' } }' $i | awk -F ' ' ' { print $1 }' )
74+
75+ # check if first line of test file contains 'variant=' and retrieve its value. Set to the default variant if it does not
76+ variant=$( awk -F ' variant=' ' FNR==1{ if ($0~"variant=") { print $2 } else { print ' $DEFAULT_VARIANT ' } }' $i | awk -F ' ' ' { print $1 }' )
77+
78+ # check if first line of test file contains 'source-test'
79+ use_source_test=$( awk ' FNR==1{ if ($0~"source-test") print "yes" }' $i )
6980 if [[ $use_source_test == " yes" ]]
70- then test_source_framework $s $i
71- else test_source $s $i
81+ then test_source_framework $s $i $chap $variant
82+ else test_source $s $i $chap $variant
7283 fi
7384 done
7485 fi
0 commit comments