Skip to content

Commit 4d56a75

Browse files
committed
add more tests and cleanup testing setup code
1 parent dd683c9 commit 4d56a75

15 files changed

Lines changed: 78 additions & 46 deletions

File tree

.github/workflows/c-cpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
run: make clean && make -j4 CXX="ccache clang++" debug
3333

3434
- name: run tests
35-
run: pip install -U pytest pytest-cov && make clean && make -j4 CXX="ccache clang++" test
35+
run: pip install -U pytest pytest-cov && make clean && make -j4 CXX="ccache clang++" profile
3636

3737
- name: ccache stats
3838
run: ccache -s

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ BISONFLAGS=-t -d --defines=${OUT_DIR}/parser.tab.h -Wconflicts-rr -Wcounterexamp
2424
ifeq ($(MAKECMDGOALS), test)
2525
CXXFLAGS += -fprofile-arcs -ftest-coverage -g -fprofile-instr-generate -fcoverage-mapping
2626
CXXLINKING += -lgcov
27-
else
28-
CXXFLAGS += -DENABLE_UI
27+
#else
28+
# CXXFLAGS += -DENABLE_UI
2929
endif
3030

3131
ifeq ($(MAKECMDGOALS), release)
@@ -61,15 +61,17 @@ release: lsystems
6161
debug: lsystems
6262

6363
test: lsystems tests/run_tests.py
64-
LLVM_PROFILE_FILE="build/lsystems.profraw" pytest tests/run_tests.py
64+
@LLVM_PROFILE_FILE="build/lsystems.profraw" pytest tests/run_tests.py
65+
66+
profile: test
6567
@llvm-profdata merge -output=build/lsystems.profdata build/lsystems.profraw
6668
@llvm-cov show build/lsystems -instr-profile=build/lsystems.profdata -format=html -output-dir=build/coverage_report
6769
@llvm-cov report build/lsystems -instr-profile=build/lsystems.profdata
6870

6971
lsystems: ${OUT_DIR}/lsystems ${OBJ_SHADER}
7072

7173
run: lsystems examples/default.lsy
72-
${OUT_DIR}/lsystems examples/default.lsy
74+
@${OUT_DIR}/lsystems examples/default.lsy
7375

7476
${OUT_DIR}/lsystems: ${OBJ} ${OUT_SHADERS} ${OUT_DIR}/lex.yy.cpp ${OUT_DIR}/parser.tab.o
7577
@echo -e "${COLOR_LINK}[CLANG]${COLOR_RESET} Linking executable ${COLOR_LINK}${COLOR_BOLD}$(@F)${COLOR_RESET}"

tests/failure/missing_context.lsy

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/run_tests.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,37 @@
55
# Path to the executable
66
LSYS_EXE = pathlib.Path(__file__).parent.parent / "build" / "lsystems"
77

8-
def collect_test_cases(folder, expect_success=True):
8+
def collect_test_cases(folder, expect_success):
99
input_dir = pathlib.Path(__file__).parent / folder
1010
test_cases = []
11-
for ls_file in input_dir.glob("*.lsy"):
11+
for ls_file in input_dir.rglob("*.lsy"):
1212
expected_file = ls_file.with_suffix(".expected")
13-
test_cases.append((ls_file, expected_file, expect_success))
13+
test_name = str(ls_file.relative_to(input_dir))
14+
test_cases.append(pytest.param(ls_file, expected_file, expect_success, id=test_name))
1415
return test_cases
1516

16-
@pytest.mark.parametrize("ls_file, expected_file, expect_success", collect_test_cases("success", expect_success=True))
17-
def test_success_cases(ls_file, expected_file, expect_success):
17+
def run_test_case(ls_file, expected_file, expect_success):
1818
result = subprocess.run(
19-
[str(LSYS_EXE), str(pathlib.Path(ls_file))],
19+
[str(LSYS_EXE), str(ls_file)],
2020
stdout=subprocess.PIPE,
2121
stderr=subprocess.PIPE,
2222
timeout=2
2323
)
2424
output = result.stdout.decode("utf-8")
25-
expected = expected_file.read_text(encoding="utf-8")
25+
if expect_success:
26+
expected = expected_file.read_text(encoding="utf-8")
27+
assert result.returncode == 0, f"{ls_file} failed unexpectedly"
28+
assert output == expected, f"{ls_file} output mismatch"
29+
else:
30+
output += result.stderr.decode("utf-8")
31+
expected = expected_file.read_text(encoding="utf-8")
32+
assert result.returncode != 0, f"{ls_file} should fail but succeeded"
33+
assert expected in output, f"{ls_file} error message mismatch"
2634

27-
assert result.returncode == 0, f"{ls_file.name} failed unexpectedly"
28-
assert output == expected, f"{ls_file.name} output mismatch"
35+
@pytest.mark.parametrize("ls_file, expected_file, expect_success", collect_test_cases("success", expect_success=True))
36+
def test_success_cases(ls_file, expected_file, expect_success):
37+
run_test_case(ls_file, expected_file, expect_success)
2938

3039
@pytest.mark.parametrize("ls_file, expected_file, expect_success", collect_test_cases("failure", expect_success=False))
3140
def test_failure_cases(ls_file, expected_file, expect_success):
32-
result = subprocess.run(
33-
[str(LSYS_EXE), str(pathlib.Path(ls_file))],
34-
stdout=subprocess.PIPE,
35-
stderr=subprocess.PIPE,
36-
timeout=2
37-
)
38-
output = result.stdout.decode("utf-8") + result.stderr.decode("utf-8")
39-
expected = expected_file.read_text(encoding="utf-8")
40-
41-
assert result.returncode != 0, f"{ls_file.name} should fail but succeeded"
42-
assert expected in output, f"{ls_file.name} error message mismatch"
41+
run_test_case(ls_file, expected_file, expect_success)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
node: a < a > b --> b
2+
node: b < a > a --> b
3+
node: b < a > b --> A
4+
node: * < b > * --> a
5+
config:
6+
derivation: 5
7+
angle factor: 60
8+
scale factor: 1
9+
axiom: baaaaaaaaab
10+
ignore: c
11+
12+
derivation 0/5: baaaaaaaaab
13+
derivation 1/5: abaaaaaaaba
14+
derivation 2/5: aabaaaaabaa
15+
derivation 3/5: ababaaababa
16+
derivation 4/5: aaAababaAaa
17+
derivation 5/5: aaAaaAaaAaa
18+
aaAaaAaaAaa

0 commit comments

Comments
 (0)