forked from JMU-CS/less-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlj
executable file
·113 lines (103 loc) · 2.77 KB
/
lj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
# vim: set filetype=bash
GRADLE_WRAPPER="./gradlew"
help() {
echo "Usage: $0 [options] file"
echo ""
echo " Options:"
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
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
;;
v)
verbose=true
;;
\?)
echo "Unrecognized option $OPTARG" 1>&2
echo
help
exit
;;
esac
done
shift $((OPTIND - 1))
if ! $verbose; then
args="${args} -q"
fi
if [ $# == 0 ]; then
echo "Expecting a file" 1>&2
echo
help
exit
fi
args="${args} -Ptestfile=${1}"
"$GRADLE_WRAPPER" $args
compile_status="$?"
if [ "$compile_status" -gt "0" ]; then
exit
fi
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
# Ensure the exit code from the tests is the exit code of the script
if [ "$test_status" -gt "0" ]; then
exit 1
fi
fi
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