Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reedeveris/clean up testing 103 #106

Merged
merged 1 commit into from
Mar 25, 2024
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
19 changes: 11 additions & 8 deletions tests/plcc/can-print-json-ast/prints-json-ast.bats
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#!/usr/bin/env bats

setup() {
mkdir ${BATS_TMPDIR}/json-test
}

teardown() {
cd ../..
rm -rf ${BATS_TMPDIR}/json-test
}

@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}"
cp -R "${BATS_TEST_DIRNAME}/${f}" "${BATS_TMPDIR}/json-test"
done

cp "${BATS_TEST_DIRNAME}"/* "$BATS_TMPDIR/"
cd "${BATS_TMPDIR}"
cd "${BATS_TMPDIR}/json-test"
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"
}
15 changes: 12 additions & 3 deletions tests/plcc/compiles-obj/compiles-obj.bats
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
#!/usr/bin/env bats

setup() {
mkdir ${BATS_TMPDIR}/obj-test
}

teardown() {
cd ../../../..
rm -rf ${BATS_TMPDIR}/obj-test
}

@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}"
# Copy the OBJ language to the temporary directory for this test
cp -R "${BATS_TEST_DIRNAME}/OBJ" "${BATS_TMPDIR}/obj-test"

# Change into the temporary OBJ directory.
cd "${BATS_TMPDIR}/OBJ"
cd "${BATS_TMPDIR}/obj-test/OBJ"

# Use plcc to generate the Java files from the OBJ grammar file.
plcc "grammar"
Expand Down
15 changes: 10 additions & 5 deletions tests/plcc/detects-illegal-tokens.bats
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#!/usr/bin/env bats

setup() {
mkdir ${BATS_TMPDIR}/illegal-tokens-test
}

teardown() {
rm -rf ${BATS_TMPDIR}/illegal-tokens-test
}

@test "PLCC detects illegal tokens." {
# GIVEN a grammar file with a bad token name
cat << EOF > "$BATS_TMPDIR/grammar"
cat << EOF > "${BATS_TMPDIR}/illegal-tokens-test/grammar"
token bad_token_name '.'
EOF

# WHEN plcc is ran on that grammar file
run plcc "$BATS_TMPDIR/grammar"
run plcc "${BATS_TMPDIR}/illegal-tokens-test/grammar"

# print stdout and stderr for debugging
echo "OUTPUT: $output"
Expand All @@ -18,7 +26,4 @@ EOF

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

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

setup() {
mkdir ${BATS_TMPDIR}/parse-test
}

teardown() {
rm -rf ${BATS_TMPDIR}/parse-test
}

@test "PLCC parses." {
cat << EOF > "$BATS_TMPDIR/grammar"
cat << EOF > "${BATS_TMPDIR}/parse-test/grammar"
A 'A'
B 'B'
skip OTHER '.'
Expand All @@ -10,11 +18,8 @@ skip OTHER '.'
<aaa> **= A
EOF

RESULT="$(cd "$BATS_TMPDIR" && plccmk -c grammar > /dev/null && echo "A asdf A fdsa A B" | parse -n)"
RESULT="$(cd "${BATS_TMPDIR}/parse-test" && plccmk -c grammar > /dev/null && echo "A asdf A fdsa A B" | parse -n)"

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

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

setup() {
mkdir ${BATS_TMPDIR}/scan-test
}

teardown() {
rm -rf ${BATS_TMPDIR}/scan-test
}

@test "PLCC scans." {
cat << EOF > "$BATS_TMPDIR/grammar"
cat << EOF > "${BATS_TMPDIR}/scan-test/grammar"
skip WHITESPACE '\s'
token FOO 'foo'
token BAR 'bar'
Expand All @@ -11,16 +19,13 @@ EOF
IN="foo bar \n foobar"

TOKENS="$(
cd "$BATS_TMPDIR" &&
plccmk -c "$BATS_TMPDIR/grammar" &&
cd "${BATS_TMPDIR}/scan-test" &&
plccmk -c "grammar" &&
OUT="$(echo "$IN" | scan)" &&
echo "$OUT"
)"

[[ "$TOKENS" =~ "FOO 'foo'" ]]
[[ "$TOKENS" =~ "BAR 'bar'" ]]
[[ "$TOKENS" =~ "ID 'foobar'" ]]

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