Skip to content

Commit

Permalink
test: clean up tests (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneyJackson authored Apr 11, 2024
1 parent 7976dfc commit 460d1e7
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 88 deletions.
31 changes: 20 additions & 11 deletions bin/test/functionality.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@ set -euo pipefail

SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PROJECT_ROOT="$( cd "${SCRIPT_DIR}/../.." &> /dev/null && pwd )"
cd "${PROJECT_ROOT}"

tests/run

function run_local_tests() {
cd "${PROJECT_ROOT}"
tests/run.bash
}

LANGUAGES_VERSION="${LANGUAGES_VERSION:-}"
cd /tmp

rm -rf languages
git clone https://github.com/ourPLCC/languages.git
if [ -n "${LANGUAGES_VERSION}" ] ; then
git -C ./languages checkout "${LANGUAGES_VERSION}"
fi
languages/bin/test.bash
rm -rf languages
function run_language_tests() {
LANGUAGES_VERSION="${LANGUAGES_VERSION:-}"
cd /tmp

rm -rf languages
git clone https://github.com/ourPLCC/languages.git
if [ -n "${LANGUAGES_VERSION}" ] ; then
git -C ./languages checkout "${LANGUAGES_VERSION}"
fi
languages/bin/test.bash
rm -rf languages
}


run_local_tests
run_language_tests
14 changes: 0 additions & 14 deletions bin/test/languages.bash

This file was deleted.

16 changes: 2 additions & 14 deletions tests/plcc/can-print-json-ast/prints-json-ast.bats
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
#!/usr/bin/env bats

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

teardown() {
cd ../..
rm -rf ${BATS_TMPDIR}/json-test
}
load '../../relocate_to_temp.bash'

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

cd "${BATS_TMPDIR}/json-test"
relocate_to_temp
plccmk --json_ast given-grammar.lang
parse -n --json_ast < given-program.lang > result.json
diff expected.json result.json
Expand Down
25 changes: 4 additions & 21 deletions tests/plcc/compiles-obj/compiles-obj.bats
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
#!/usr/bin/env bats

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

teardown() {
cd ../../../..
rm -rf ${BATS_TMPDIR}/obj-test
}
load '../../relocate_to_temp.bash'

@test "PLCC compiles the OBJ language." {
# 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-test/OBJ"

# Use plcc to generate the Java files from the OBJ grammar file.
plcc "grammar"

# Change into the generated Java file.
cd Java
relocate_to_temp

# Compile the Java files.
run javac *.java
cd OBJ
run plccmk grammar

# Print stdout and stderr for debugging.
echo "OUTPUT: $output"
Expand Down
14 changes: 5 additions & 9 deletions tests/plcc/detects-illegal-tokens.bats
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
#!/usr/bin/env bats

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

teardown() {
rm -rf ${BATS_TMPDIR}/illegal-tokens-test
}
load '../relocate_to_temp.bash'

@test "PLCC detects illegal tokens." {
relocate_to_temp

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

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

# print stdout and stderr for debugging
echo "OUTPUT: $output"
Expand Down
14 changes: 5 additions & 9 deletions tests/plcc/parses.bats
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#!/usr/bin/env bats

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

teardown() {
rm -rf ${BATS_TMPDIR}/parse-test
}
load '../relocate_to_temp.bash'

@test "PLCC parses." {
cat << EOF > "${BATS_TMPDIR}/parse-test/grammar"
relocate_to_temp

cat << EOF > grammar
A 'A'
B 'B'
skip OTHER '.'
Expand All @@ -18,7 +14,7 @@ skip OTHER '.'
<aaa> **= A
EOF

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

echo "RESULT: $RESULT"
[[ "$RESULT" =~ .*OK.* ]]
Expand Down
15 changes: 5 additions & 10 deletions tests/plcc/scans-tokens.bats
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#!/usr/bin/env bats

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

teardown() {
rm -rf ${BATS_TMPDIR}/scan-test
}
load '../relocate_to_temp.bash'

@test "PLCC scans." {
cat << EOF > "${BATS_TMPDIR}/scan-test/grammar"
relocate_to_temp

cat << EOF > grammar
skip WHITESPACE '\s'
token FOO 'foo'
token BAR 'bar'
Expand All @@ -19,8 +15,7 @@ EOF
IN="foo bar \n foobar"

TOKENS="$(
cd "${BATS_TMPDIR}/scan-test" &&
plccmk -c "grammar" &&
plccmk -c grammar &&
OUT="$(echo "$IN" | scan)" &&
echo "$OUT"
)"
Expand Down
4 changes: 4 additions & 0 deletions tests/relocate_to_temp.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function relocate_to_temp () {
cd "${BATS_TEST_TMPDIR}"
cp -R "${BATS_TEST_DIRNAME}/"* .
}
File renamed without changes.

0 comments on commit 460d1e7

Please sign in to comment.