Skip to content

Commit

Permalink
all tests except compiles-4-section
Browse files Browse the repository at this point in the history
  • Loading branch information
reedeveris committed Mar 6, 2024
1 parent d577c07 commit 968b84e
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 31 deletions.
14 changes: 8 additions & 6 deletions tests/plcc/can-print-json-ast/prints-json-ast.bats
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/usr/bin/env bats

teardown() {
rm -rf ${BATS_TMPDIR}/expected.json
rm -rf ${BATS_TMPDIR}/given-grammar.lang
rm -rf ${BATS_TMPDIR}/given-program.lang
rm -rf ${BATS_TMPDIR}/result.json
rm -rf ${BATS_TMPDIR}/Java
}

@test "PLCC can print JSON AST." {
FILES="expected.json given-grammar.lang given-program.lang"
for f in $FILES ; do
cp "${BATS_TEST_DIRNAME}/${f}" "${BATS_TMPDIR}"
done

cp "${BATS_TEST_DIRNAME}"/* "$BATS_TMPDIR/"
cd "${BATS_TMPDIR}"
plccmk --json_ast given-grammar.lang
parse -n --json_ast < given-program.lang > result.json
diff expected.json result.json

for f in $FILES ; do
rm "${BATS_TMPDIR}/${f}"
done
rm "${BATS_TMPDIR}/result.json"
}
10 changes: 6 additions & 4 deletions tests/plcc/compiles-4-section/compiles-4-section.bats
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env bats

@test "PLCC compiles the OBJ language." {
teardown() {
rm -rf "$BATS_TMPDIR/OBJ"
}

@test "PLCC compiles with 4 sections." {
# Copy the OBJ language to the temp directory for this test
cp -R "${BATS_TEST_DIRNAME}/OBJ" "${BATS_TMPDIR}"

Expand All @@ -14,14 +18,12 @@
cd Java

# Compile the Java files.
run javac *.java
run javac -cp /../../../../../lib/jackson/* *.java

# Print stdout and stderr for debugging.
echo "OUTPUT: $output"
echo "ERROR: $error"

# Assert success.
[ "$status" -eq 0 ]

rm -rf "$BATS_TMPDIR/OBJ"
}
6 changes: 4 additions & 2 deletions tests/plcc/compiles-obj/compiles-obj.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bats

teardown() {
rm -rf "$BATS_TMPDIR/OBJ"
}

@test "PLCC compiles the OBJ language." {
# Copy the OBJ language to the temp directory for this test
cp -R "${BATS_TEST_DIRNAME}/OBJ" "${BATS_TMPDIR}"
Expand All @@ -22,6 +26,4 @@

# Assert success.
[ "$status" -eq 0 ]

rm -rf "$BATS_TMPDIR/OBJ"
}
7 changes: 4 additions & 3 deletions tests/plcc/detects-illegal-tokens.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bats

teardown() {
rm -rf ${BATS_TMPDIR}/grammar
}

@test "PLCC detects illegal tokens." {
# GIVEN a grammar file with a bad token name
cat << EOF > "$BATS_TMPDIR/grammar"
Expand All @@ -18,7 +22,4 @@ EOF

# AND plcc reports that there is an "illegal token name"
[[ "$output" = *"illegal token name"* ]]

# cleanup
rm "$BATS_TMPDIR/grammar"
}
14 changes: 8 additions & 6 deletions tests/plcc/generate-python.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/usr/bin/env bats

teardown() {
rm -rf ${BATS_TMPDIR}/grammar
rm -rf ${BATS_TMPDIR}/Java
rm -rf ${BATS_TMPDIR}/Python
}

@test "Creates Python directory when 4th section detected." {
cat << EOF > "$BATS_TMPDIR/grammar"
A 'A'
Expand All @@ -12,12 +18,8 @@ skip OTHER '.'
%
EOF

RESULT="$(cd "$BATS_TMPDIR" && plccmk -c grammar)"
RESULT="$(cd "$BATS_TMPDIR" && plccmk --json_ast grammar)"

echo "RESULT: $RESULT"
[[ -d $BATS_TMPDIR/Python ]]

rm -rf "$BATS_TMPDIR/grammar"
rm -rf "$BATS_TMPDIR/Java"
rm -rf "$BATS_TMPDIR/Python"
}
}
10 changes: 6 additions & 4 deletions tests/plcc/no-4th-section.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/usr/bin/env bats

teardown() {
rm -rf ${BATS_TMPDIR}/grammar
rm -rf ${BATS_TMPDIR}/Java
}

@test "Functions correctly when no 4th section exists." {
cat << EOF > "$BATS_TMPDIR/grammar"
A 'A'
Expand All @@ -15,7 +20,4 @@ EOF

echo "RESULT: $RESULT"
[[ ! -d $BATS_TMPDIR/Python ]]

rm -rf "$BATS_TMPDIR/grammar"
rm -rf "$BATS_TMPDIR/Java"
}
}
8 changes: 5 additions & 3 deletions tests/plcc/parses.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/usr/bin/env bats

teardown() {
rm -rf ${BATS_TMPDIR}/grammar
rm -rf ${BATS_TMPDIR}/Java
}

@test "PLCC parses." {
cat << EOF > "$BATS_TMPDIR/grammar"
A 'A'
Expand All @@ -14,7 +19,4 @@ EOF

echo "RESULT: $RESULT"
[[ "$RESULT" =~ .*OK.* ]]

rm -rf "$BATS_TMPDIR/grammar"
rm -rf "$BATS_TMPDIR/Java"
}
8 changes: 5 additions & 3 deletions tests/plcc/scans-tokens.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/usr/bin/env bats

teardown() {
rm -rf ${BATS_TMPDIR}/grammar
rm -rf ${BATS_TMPDIR}/Java
}

@test "PLCC scans." {
cat << EOF > "$BATS_TMPDIR/grammar"
skip WHITESPACE '\s'
Expand All @@ -20,7 +25,4 @@ EOF
[[ "$TOKENS" =~ "FOO 'foo'" ]]
[[ "$TOKENS" =~ "BAR 'bar'" ]]
[[ "$TOKENS" =~ "ID 'foobar'" ]]

rm -rf "$BATS_TMPDIR/grammar"
rm -rf "$BATS_TMPDIR/Java"
}

0 comments on commit 968b84e

Please sign in to comment.