Skip to content

Commit e70c5f4

Browse files
authored
Add support for multi-file tests (#76)
This PR adds support for writing multi translation-unit tests in the below format. All multi translation-unit tests go into `tests/multi-file`, one test per directory. `test.expectations` is an optional file that contains one of the following test expectations: no-compile, translation-fail, panic, nondet-result; or it can be empty if the test is successful: ``` tests/multi-file/ └── extern_functions ├── a.c ├── b.c ├── CMakeLists.txt ├── out │ ├── refcount │ │ └── extern_functions.rs │ └── unsafe │ └── extern_functions.rs └── test.expectations ``` I took this opportunity to refactor the logic inside `Cpp2RustTest.py` because the `multi-file` addition did not fit well into the current model. Now `Cpp2RustTest.py` is composed of: * `TestExpectations`: dataclass describing the expected output of the test: `should_panic, should_not_compile, should_not_translate, is_nondet_result, xfail`. For classic tests (ub, benchmarks, unit-tests), TestExpectations is populated from the comment line inside the source file, for multi-file tests, TestExpectations is populated from `test.expectatoins` * `TestContext`: dataclass that defines all test steps (`setup, translate, check_expected, build_cpp, build_rust, run_cpp, run_rust, compare`) and keeps test specific data as member variables, including `TestExpectations` * `Cpp2RustTest`: entry point of lit, contains `execute` (which calls directly into `TestContext`) `getTestsForPath` and `getTestsInDirectory` * free helper functions
1 parent 3d497fc commit e70c5f4

8 files changed

Lines changed: 442 additions & 182 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ add_custom_target("check-unit"
129129
${LIT_FLAGS}
130130
"${PROJECT_SOURCE_DIR}/tests/unit"
131131
"${PROJECT_SOURCE_DIR}/tests/ub"
132+
"${PROJECT_SOURCE_DIR}/tests/multi-file"
132133
DEPENDS cpp2rust libcc2rs
133134
USES_TERMINAL
134135
)

0 commit comments

Comments
 (0)