Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 65 additions & 37 deletions lj
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,41 @@ help() {
echo "Usage: $0 [options] file"
echo ""
echo " Options:"
echo " -h Print this help message and exit"
echo " -t Print type changes found by type inference"
echo " -v Print output from Gradle"
echo " -r Compile and run the program without testing"
echo " -t Compile and test the program without running"
echo " -h Print this help message and exit"
echo " --print-types Print type changes found by type inference"
echo " -v Print output from Gradle"
}

args="run"
verbose=false
while getopts :thv flag; do
running=true
testing=true
while getopts :rthv-: flag; do
case $flag in
-)
case "${OPTARG}" in
print-types)
args="${args} -PprintTypeChanges"
;;
*)
echo "Unrecognized option $OPTARG" 1>&2
echo
help
exit
;;
esac;;
r)
testing=false
;;
t)
running=false
;;
h)
help
exit
;;
t)
args="${args} -PprintTypeChanges"
;;
v)
verbose=true
;;
Expand All @@ -49,37 +68,46 @@ fi

args="${args} -Ptestfile=${1}"
"$GRADLE_WRAPPER" $args

# If the less-java file contains the string "main()", attempt to run it.
# Otherwise, release a warning and continue
parent=$(dirname $1)
base=$(basename $1)
name=${base%.*}
count=$(grep -c "main()" "$1")
if [ "$count" -gt "0" ];
then
if [ -e "$parent/$name.in" ];
then
java -cp generated Main < "$parent/$name.in"
else
java -cp generated Main
fi
else
echo "Warning: This program does not contain a main() function and will not be run"
compile_status="$?"
if [ "$compile_status" -gt "0" ]; then
exit
fi

# --class-path allows specifying where JUnit should look for tests
# --include-classname allows the name to be anything
# --disable-banner disables the banner asking contributing to JUnit
# --scan-class-path checks the full classpath for tests
# Get the output but do not print it yet
test_output="$(java -jar libs/junit-platform-console-standalone-1.4.2.jar --class-path ".:generated" --include-classname='.*' --disable-banner --scan-class-path)"
# Preserve the exit code of the tests
test_status="$?"
if $testing; then
# --class-path allows specifying where JUnit should look for tests
# --include-classname allows the name to be anything
# --disable-banner disables the banner asking contributing to JUnit
# --scan-class-path checks the full classpath for tests
# Get the output but do not print it yet
test_output="$(java -jar libs/junit-platform-console-standalone-1.4.2.jar --class-path ".:generated" --include-classname='.*' --disable-banner --scan-class-path)"
# Preserve the exit code of the tests
test_status="$?"

# The grep -v filter removes lines that are unnecessary or potentially
# confusing to an end user.
echo "$test_output" | grep -v -e '\[.*containers.*\]' -e 'JUnit Vintage' -e 'Test run finished after'
echo

# The grep -v filter removes lines that are unnecessary or potentially
# confusing to an end user.
echo "$test_output" | grep -v -e '\[.*containers.*\]' -e 'JUnit Vintage' -e 'Test run finished after'
# Ensure the exit code from the tests is the exit code of the script
if [ "$test_status" -gt "0" ]; then
exit 1
fi
fi

# Ensure the exit code from the tests is the exit code of the script
exit "$test_status"
if $running; then
# IF the less-java file contains the string "main()", attempt to run it.
# Otherwise, release a warning and continue
parent=$(dirname $1)
base=$(basename $1)
name=${base%.*}
count=$(grep -c "main()" "$1")
if [ "$count" -gt "0" ]; then
if [ -e "$parent/$name.in" ]; then
java -cp generated Main < "$parent/$name.in"
else
java -cp generated Main
fi
else
echo "Warning: This program does not contain a main() function and will not be run."
fi
fi
3 changes: 2 additions & 1 deletion tests/comp/outputs/3np1for.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Warning: This program does not contain a main() function and will not be run
╷
├─ JUnit Jupiter ✔
│ └─ Main ✔
Expand All @@ -13,3 +12,5 @@ Warning: This program does not contain a main() function and will not be run
[ 0 tests aborted ]
[ 4 tests successful ]
[ 0 tests failed ]

Warning: This program does not contain a main() function and will not be run.
3 changes: 2 additions & 1 deletion tests/comp/outputs/3np1while.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
1
╷
├─ JUnit Jupiter ✔
│ └─ Main ✔
Expand All @@ -15,3 +14,5 @@
[ 0 tests aborted ]
[ 6 tests successful ]
[ 0 tests failed ]

1
19 changes: 10 additions & 9 deletions tests/comp/outputs/abracadabra.exp
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
╷
├─ JUnit Jupiter ✔

[ 0 tests found ]
[ 0 tests skipped ]
[ 0 tests started ]
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]

1 Abracadabra
2 Abracadabra
3 Abracadabra
Expand All @@ -13,12 +23,3 @@
8 Abracadabra
9 Abracadabra
10 Abracadabra
╷
├─ JUnit Jupiter ✔

[ 0 tests found ]
[ 0 tests skipped ]
[ 0 tests started ]
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]
3 changes: 2 additions & 1 deletion tests/comp/outputs/different.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Warning: This program does not contain a main() function and will not be run
╷
├─ JUnit Jupiter ✔
│ └─ Main ✔
Expand All @@ -13,3 +12,5 @@ Warning: This program does not contain a main() function and will not be run
[ 0 tests aborted ]
[ 4 tests successful ]
[ 0 tests failed ]

Warning: This program does not contain a main() function and will not be run.
19 changes: 10 additions & 9 deletions tests/comp/outputs/fizzbuzz.exp
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
╷
├─ JUnit Jupiter ✔

[ 0 tests found ]
[ 0 tests skipped ]
[ 0 tests started ]
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]

1
Fizz
Buzz
Expand All @@ -19,12 +29,3 @@ Fizz
Buzz
Fizz
7
╷
├─ JUnit Jupiter ✔

[ 0 tests found ]
[ 0 tests skipped ]
[ 0 tests started ]
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]
3 changes: 2 additions & 1 deletion tests/comp/outputs/oddgnome.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Warning: This program does not contain a main() function and will not be run
╷
├─ JUnit Jupiter ✔
│ └─ Main ✔
Expand All @@ -10,3 +9,5 @@ Warning: This program does not contain a main() function and will not be run
[ 0 tests aborted ]
[ 1 tests successful ]
[ 0 tests failed ]

Warning: This program does not contain a main() function and will not be run.
4 changes: 3 additions & 1 deletion tests/io/outputs/add.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
17╷
╷
├─ JUnit Jupiter ✔

[ 0 tests found ]
Expand All @@ -7,3 +7,5 @@
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]

17
6 changes: 4 additions & 2 deletions tests/io/outputs/collections.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
enter 3 space-separated words
[dog, flapjack, potable]╷
╷
├─ JUnit Jupiter ✔

[ 0 tests found ]
Expand All @@ -8,3 +7,6 @@ enter 3 space-separated words
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]

enter 3 space-separated words
[dog, flapjack, potable]
4 changes: 3 additions & 1 deletion tests/io/outputs/for-loop.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
abc╷
╷
├─ JUnit Jupiter ✔

[ 0 tests found ]
Expand All @@ -7,3 +7,5 @@ abc╷
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]

abc
3 changes: 2 additions & 1 deletion tests/io/outputs/hello-world.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Hello, World!
╷
├─ JUnit Jupiter ✔

Expand All @@ -8,3 +7,5 @@ Hello, World!
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]

Hello, World!
11 changes: 6 additions & 5 deletions tests/io/outputs/input.exp
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
Integer: 5
Double: 3.14
Character: x
Word: hello
Line: This is a line-based test.
╷
├─ JUnit Jupiter ✔

Expand All @@ -12,3 +7,9 @@ Line: This is a line-based test.
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]

Integer: 5
Double: 3.14
Character: x
Word: hello
Line: This is a line-based test.
3 changes: 2 additions & 1 deletion tests/io/outputs/input2.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
how are you?
╷
├─ JUnit Jupiter ✔

Expand All @@ -8,3 +7,5 @@ how are you?
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]

how are you?
9 changes: 5 additions & 4 deletions tests/io/outputs/print.exp
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
1atrue
1
true
ahi
╷
├─ JUnit Jupiter ✔

Expand All @@ -11,3 +7,8 @@ ahi
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]

1atrue
1
true
ahi
13 changes: 7 additions & 6 deletions tests/io/outputs/sum.exp
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
Enter positive integers to sum, one per line (-1 to exit):
3
4
9
11
Sum: 11
╷
├─ JUnit Jupiter ✔

Expand All @@ -13,3 +7,10 @@ Sum: 11
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]

Enter positive integers to sum, one per line (-1 to exit):
3
4
9
11
Sum: 11
3 changes: 2 additions & 1 deletion tests/outputs/add.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Warning: This program does not contain a main() function and will not be run
╷
├─ JUnit Jupiter ✔
│ └─ Main ✔
Expand All @@ -13,3 +12,5 @@ Warning: This program does not contain a main() function and will not be run
[ 0 tests aborted ]
[ 4 tests successful ]
[ 0 tests failed ]

Warning: This program does not contain a main() function and will not be run.
3 changes: 2 additions & 1 deletion tests/outputs/adder.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Warning: This program does not contain a main() function and will not be run
╷
├─ JUnit Jupiter ✔
│ └─ Main ✔
Expand All @@ -12,3 +11,5 @@ Warning: This program does not contain a main() function and will not be run
[ 0 tests aborted ]
[ 3 tests successful ]
[ 0 tests failed ]

Warning: This program does not contain a main() function and will not be run.
3 changes: 2 additions & 1 deletion tests/outputs/bracket-access.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Warning: This program does not contain a main() function and will not be run
╷
├─ JUnit Jupiter ✔
│ └─ Main ✔
Expand All @@ -10,3 +9,5 @@ Warning: This program does not contain a main() function and will not be run
[ 0 tests aborted ]
[ 1 tests successful ]
[ 0 tests failed ]

Warning: This program does not contain a main() function and will not be run.
3 changes: 2 additions & 1 deletion tests/outputs/car.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Warning: This program does not contain a main() function and will not be run
╷
├─ JUnit Jupiter ✔
│ └─ Main ✔
Expand All @@ -11,3 +10,5 @@ Warning: This program does not contain a main() function and will not be run
[ 0 tests aborted ]
[ 2 tests successful ]
[ 0 tests failed ]

Warning: This program does not contain a main() function and will not be run.
3 changes: 2 additions & 1 deletion tests/outputs/collections.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Warning: This program does not contain a main() function and will not be run
╷
├─ JUnit Jupiter ✔
│ └─ Main ✔
Expand Down Expand Up @@ -38,3 +37,5 @@ Warning: This program does not contain a main() function and will not be run
[ 0 tests aborted ]
[ 29 tests successful ]
[ 0 tests failed ]

Warning: This program does not contain a main() function and will not be run.
Loading