Skip to content

Commit 462beed

Browse files
authored
Merge pull request #101 from MrBartWolf/options
Changed lj to work with running and testing only options.
2 parents 9177dab + 519a580 commit 462beed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+198
-125
lines changed

lj

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1517
args="run"
1618
verbose=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
;;
@@ -49,37 +68,46 @@ fi
4968

5069
args="${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
6974
fi
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

tests/comp/outputs/3np1for.exp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Warning: This program does not contain a main() function and will not be run
21
╷
32
├─ JUnit Jupiter ✔
43
│ └─ Main ✔
@@ -13,3 +12,5 @@ Warning: This program does not contain a main() function and will not be run
1312
[ 0 tests aborted ]
1413
[ 4 tests successful ]
1514
[ 0 tests failed ]
15+
16+
Warning: This program does not contain a main() function and will not be run.

tests/comp/outputs/3np1while.exp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
1
21
╷
32
├─ JUnit Jupiter ✔
43
│ └─ Main ✔
@@ -15,3 +14,5 @@
1514
[ 0 tests aborted ]
1615
[ 6 tests successful ]
1716
[ 0 tests failed ]
17+
18+
1

tests/comp/outputs/abracadabra.exp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
╷
2+
├─ JUnit Jupiter ✔
3+
4+
[ 0 tests found ]
5+
[ 0 tests skipped ]
6+
[ 0 tests started ]
7+
[ 0 tests aborted ]
8+
[ 0 tests successful ]
9+
[ 0 tests failed ]
10+
111
1 Abracadabra
212
2 Abracadabra
313
3 Abracadabra
@@ -13,12 +23,3 @@
1323
8 Abracadabra
1424
9 Abracadabra
1525
10 Abracadabra
16-
╷
17-
├─ JUnit Jupiter ✔
18-
19-
[ 0 tests found ]
20-
[ 0 tests skipped ]
21-
[ 0 tests started ]
22-
[ 0 tests aborted ]
23-
[ 0 tests successful ]
24-
[ 0 tests failed ]

tests/comp/outputs/different.exp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Warning: This program does not contain a main() function and will not be run
21
╷
32
├─ JUnit Jupiter ✔
43
│ └─ Main ✔
@@ -13,3 +12,5 @@ Warning: This program does not contain a main() function and will not be run
1312
[ 0 tests aborted ]
1413
[ 4 tests successful ]
1514
[ 0 tests failed ]
15+
16+
Warning: This program does not contain a main() function and will not be run.

tests/comp/outputs/fizzbuzz.exp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
╷
2+
├─ JUnit Jupiter ✔
3+
4+
[ 0 tests found ]
5+
[ 0 tests skipped ]
6+
[ 0 tests started ]
7+
[ 0 tests aborted ]
8+
[ 0 tests successful ]
9+
[ 0 tests failed ]
10+
111
1
212
Fizz
313
Buzz
@@ -19,12 +29,3 @@ Fizz
1929
Buzz
2030
Fizz
2131
7
22-
╷
23-
├─ JUnit Jupiter ✔
24-
25-
[ 0 tests found ]
26-
[ 0 tests skipped ]
27-
[ 0 tests started ]
28-
[ 0 tests aborted ]
29-
[ 0 tests successful ]
30-
[ 0 tests failed ]

tests/comp/outputs/oddgnome.exp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Warning: This program does not contain a main() function and will not be run
21
╷
32
├─ JUnit Jupiter ✔
43
│ └─ Main ✔
@@ -10,3 +9,5 @@ Warning: This program does not contain a main() function and will not be run
109
[ 0 tests aborted ]
1110
[ 1 tests successful ]
1211
[ 0 tests failed ]
12+
13+
Warning: This program does not contain a main() function and will not be run.

tests/io/outputs/add.exp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
17╷
1+
╷
22
├─ JUnit Jupiter ✔
33

44
[ 0 tests found ]
@@ -7,3 +7,5 @@
77
[ 0 tests aborted ]
88
[ 0 tests successful ]
99
[ 0 tests failed ]
10+
11+
17

tests/io/outputs/collections.exp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
enter 3 space-separated words
2-
[dog, flapjack, potable]╷
1+
╷
32
├─ JUnit Jupiter ✔
43

54
[ 0 tests found ]
@@ -8,3 +7,6 @@ enter 3 space-separated words
87
[ 0 tests aborted ]
98
[ 0 tests successful ]
109
[ 0 tests failed ]
10+
11+
enter 3 space-separated words
12+
[dog, flapjack, potable]

tests/io/outputs/for-loop.exp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
abc╷
1+
╷
22
├─ JUnit Jupiter ✔
33

44
[ 0 tests found ]
@@ -7,3 +7,5 @@ abc╷
77
[ 0 tests aborted ]
88
[ 0 tests successful ]
99
[ 0 tests failed ]
10+
11+
abc

0 commit comments

Comments
 (0)