@@ -7,22 +7,41 @@ help() {
77 echo " Usage: $0 [options] file"
88 echo " "
99 echo " Options:"
10- echo " -h Print this help message and exit"
11- echo " -t Print type changes found by type inference"
12- echo " -v Print output from Gradle"
10+ echo " -r Compile and run the program without testing"
11+ echo " -t Compile and test the program without running"
12+ echo " -h Print this help message and exit"
13+ echo " --print-types Print type changes found by type inference"
14+ echo " -v Print output from Gradle"
1315}
1416
1517args=" run"
1618verbose=false
17- while getopts :thv flag; do
19+ running=true
20+ testing=true
21+ while getopts :rthv-: flag; do
1822 case $flag in
23+ -)
24+ case " ${OPTARG} " in
25+ print-types)
26+ args=" ${args} -PprintTypeChanges"
27+ ;;
28+ * )
29+ echo " Unrecognized option $OPTARG " 1>&2
30+ echo
31+ help
32+ exit
33+ ;;
34+ esac ;;
35+ r)
36+ testing=false
37+ ;;
38+ t)
39+ running=false
40+ ;;
1941 h)
2042 help
2143 exit
2244 ;;
23- t)
24- args=" ${args} -PprintTypeChanges"
25- ;;
2645 v)
2746 verbose=true
2847 ;;
4968
5069args=" ${args} -Ptestfile=${1} "
5170" $GRADLE_WRAPPER " $args
52-
53- # If the less-java file contains the string "main()", attempt to run it.
54- # Otherwise, release a warning and continue
55- parent=$( dirname $1 )
56- base=$( basename $1 )
57- name=${base% .* }
58- count=$( grep -c " main()" " $1 " )
59- if [ " $count " -gt " 0" ];
60- then
61- if [ -e " $parent /$name .in" ];
62- then
63- java -cp generated Main < " $parent /$name .in"
64- else
65- java -cp generated Main
66- fi
67- else
68- echo " Warning: This program does not contain a main() function and will not be run"
71+ compile_status=" $? "
72+ if [ " $compile_status " -gt " 0" ]; then
73+ exit
6974fi
7075
71- # --class-path allows specifying where JUnit should look for tests
72- # --include-classname allows the name to be anything
73- # --disable-banner disables the banner asking contributing to JUnit
74- # --scan-class-path checks the full classpath for tests
75- # Get the output but do not print it yet
76- test_output=" $( java -jar libs/junit-platform-console-standalone-1.4.2.jar --class-path " .:generated" --include-classname=' .*' --disable-banner --scan-class-path) "
77- # Preserve the exit code of the tests
78- test_status=" $? "
76+ if $testing ; then
77+ # --class-path allows specifying where JUnit should look for tests
78+ # --include-classname allows the name to be anything
79+ # --disable-banner disables the banner asking contributing to JUnit
80+ # --scan-class-path checks the full classpath for tests
81+ # Get the output but do not print it yet
82+ test_output=" $( java -jar libs/junit-platform-console-standalone-1.4.2.jar --class-path " .:generated" --include-classname=' .*' --disable-banner --scan-class-path) "
83+ # Preserve the exit code of the tests
84+ test_status=" $? "
85+
86+ # The grep -v filter removes lines that are unnecessary or potentially
87+ # confusing to an end user.
88+ echo " $test_output " | grep -v -e ' \[.*containers.*\]' -e ' JUnit Vintage' -e ' Test run finished after'
89+ echo
7990
80- # The grep -v filter removes lines that are unnecessary or potentially
81- # confusing to an end user.
82- echo " $test_output " | grep -v -e ' \[.*containers.*\]' -e ' JUnit Vintage' -e ' Test run finished after'
91+ # Ensure the exit code from the tests is the exit code of the script
92+ if [ " $test_status " -gt " 0" ]; then
93+ exit 1
94+ fi
95+ fi
8396
84- # Ensure the exit code from the tests is the exit code of the script
85- exit " $test_status "
97+ if $running ; then
98+ # IF the less-java file contains the string "main()", attempt to run it.
99+ # Otherwise, release a warning and continue
100+ parent=$( dirname $1 )
101+ base=$( basename $1 )
102+ name=${base% .* }
103+ count=$( grep -c " main()" " $1 " )
104+ if [ " $count " -gt " 0" ]; then
105+ if [ -e " $parent /$name .in" ]; then
106+ java -cp generated Main < " $parent /$name .in"
107+ else
108+ java -cp generated Main
109+ fi
110+ else
111+ echo " Warning: This program does not contain a main() function and will not be run."
112+ fi
113+ fi
0 commit comments