Skip to content

Commit eaefcc3

Browse files
committed
Add initial CI
Downloads ANTLR, builds the parser and uses it to test. Also runs shellcheck on the three scripts I wrote for this, cause why not. Still to do is definitely some expect-fail tests. Maybe also more languages? Probably at least Python.
1 parent 099c5f8 commit eaefcc3

File tree

6 files changed

+101
-0
lines changed

6 files changed

+101
-0
lines changed

.github/workflows/ci.yaml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI
2+
3+
on: push
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout commit
10+
uses: actions/checkout@v2
11+
- name: Run ShellCheck
12+
uses: ludeeus/[email protected]
13+
- name: Setup Java
14+
uses: actions/[email protected]
15+
with:
16+
java-version: 8 # ANTLR needs Java 8
17+
- name: Download ANTLR v4
18+
run: ./scripts/prereq.sh
19+
- name: Build wizparse
20+
run: ./scripts/build.sh
21+
- name: Run tests
22+
run: ./scripts/test.sh

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Generated noise
2+
*.class
3+
*.jar
4+
*.java
5+
16
# Python virtualenv
27
.venv/
38

Readme.md

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ Not yet implemented
1616
## Interpreter
1717
Not yet implemented
1818

19+
## Building & Testing
20+
Still a bit rough because it was designed for CI, but see the [scripts](scripts) folder.
21+
In short:
22+
1. Make sure you're on Linux. You're on your own on Windows.
23+
1. Make sure you have Java 8 and that it's the one you're currently using.
24+
For example, on Arch Linux, check with `archlinux-java status` and switch with `archlinux-java set`.
25+
1. Run `./scripts/prereq.sh`. This will download a copy of ANTLR.
26+
1. Run `./scripts/build.sh`. This will generate a Java parser and compile it.
27+
1. Run `./scripts/test.sh`. This will run all tests in the tests folder.
28+
1. If it worked, yo
29+
1930
## License
2031
wizparse is licensed under the MIT license. See [LICENSE](LICENSE) for the full text.
2132

scripts/build.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# This script generates and builds wizparse using ANTLR.
3+
4+
# Add antlr.jar to the classpath
5+
CLASSPATH=".:$(realpath scripts/antlr.jar):$CLASSPATH"
6+
export CLASSPATH
7+
8+
# Generate the parser and compile it
9+
java org.antlr.v4.Tool -o tmp wizards/wizard.g4
10+
# We rely on none of the .java files having spaces, so ignore this
11+
# shellcheck disable=SC2046
12+
javac $(find tmp -type f -iname "*.java" -printf '%p ') # separates with spaces

scripts/prereq.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
# This script downloads all build prerequisites for wizparse.
3+
4+
# Currently only the latest ANTLR release.
5+
curl https://www.antlr.org/download/antlr-4.8-complete.jar --output scripts/antlr.jar

scripts/test.sh

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
# This script runs a test parse on each test file, failing the CI if any files fail to parse.
3+
4+
# Check if stdout is a tty and supports color
5+
# If not, they will be undefined and hence resolve to empty strings
6+
if test -t 1
7+
then
8+
ncolors=$(tput colors)
9+
if test -n "$ncolors" && test "$ncolors" -ge 8
10+
then
11+
C_RED='\033[1;31m'
12+
C_GREEN='\033[1;32m'
13+
C_BLUE='\033[1;34m'
14+
C_YELLOW='\033[1;33m'
15+
C_NC='\033[0m'
16+
fi
17+
fi
18+
19+
# Add antlr.jar to the classpath
20+
CLASSPATH=".:$(realpath scripts/antlr.jar):$CLASSPATH"
21+
export CLASSPATH
22+
23+
# ANTLR can only handle local class files
24+
cd tmp/wizards || exit
25+
26+
num_tests=$(find ../../tests -type f -name '*.txt' -printf x | wc -c)
27+
echo -e "${C_BLUE}==>${C_NC} Testing $num_tests wizards"
28+
29+
for rel_test in ../../tests/*.txt
30+
do
31+
# Get rid of the .., looks better in logs
32+
real_test=$(realpath "$rel_test")
33+
echo -e " ${C_BLUE}::${C_NC} ${C_YELLOW}Current test wizard:${C_NC} $real_test"
34+
# TestRig doesn't set an abnormal return code, so analyze its stderr output
35+
java org.antlr.v4.gui.TestRig wizard parseWizard "$real_test" 2> parseErrors.txt
36+
if [ -s parseErrors.txt ] # exists and is not empty
37+
then
38+
# Since we swallowed the stderr output, print it back out
39+
echo -e "${C_BLUE}==>${C_NC} ${C_RED}Test failed, error message follows${C_NC}"
40+
echo "$(<parseErrors.txt)"
41+
exit 1 # fail the CI
42+
fi
43+
echo -e " ${C_BLUE}::${C_NC} ${C_GREEN}Test passed${C_NC}"
44+
done
45+
46+
echo -e "${C_BLUE}==>${C_NC} ${C_GREEN}All test passed${C_NC}"

0 commit comments

Comments
 (0)