diff --git a/c2rust/tests/test_translator.rs b/c2rust/tests/test_translator.rs new file mode 100644 index 0000000000..2b33336fe6 --- /dev/null +++ b/c2rust/tests/test_translator.rs @@ -0,0 +1,18 @@ +use std::process::Command; + +#[test] +fn test_translator() { + let transpile_path = env!("CARGO_BIN_EXE_c2rust-transpile"); + + let mut cmd = Command::new("../scripts/test_translator.py"); + cmd.args(["../tests/unit", "--transpiler", transpile_path]); + + // `test_translator.py` needs to be able to re-select the toolchain for different editions. + cmd.env_remove("RUSTUP_TOOLCHAIN"); + + let status = cmd + .status() + .unwrap_or_else(|e| panic!("{cmd:?} failed: {e}")); + + assert!(status.success(), "{cmd:?} failed with {status}"); +} diff --git a/docs/README-developers.md b/docs/README-developers.md index 071aa02692..39fd6d5b2f 100644 --- a/docs/README-developers.md +++ b/docs/README-developers.md @@ -89,6 +89,33 @@ More details about tests can be found in the [tests folder](../tests/). *Note*: These run integration tests that invoke `c2rust transpile`. `cargo test` only runs unit tests and doc tests as of now. +Most tests are found in the [`tests`](../tests/) folder. + +Most tests can also be run with: + +```sh +cargo nextest run +``` + +which includes running the [`tests/unit`](../tests/unit) tests. +The tests in `tests/unit` can also be run manually using: + +```sh +./scripts/test_translator.py tests/unit +``` + +which also allows you to run with other options. + +The [`tests/integration`](../tests/integration) tests aren't run automatically by `cargo nextest run`. To run them, run: + +```sh +# Needs to be run from `tests/integration/` (or further inside) +# to correctly load the `pyproject.toml`. +cargo build --release +(export PATH=$PWD/target/release:$PATH && export C2RUST_DIR=$PWD && cd tests/integration && ./test.py curl json-c lua nginx zstd li +bxml2 python2 libmcs) +``` + ## Documentation Local documentation can be built with the normal `cargo doc` and `cargo doc --open`. diff --git a/scripts/run_ci_checks.sh b/scripts/run_ci_checks.sh index 293b51596f..fab20ddd2e 100755 --- a/scripts/run_ci_checks.sh +++ b/scripts/run_ci_checks.sh @@ -40,6 +40,8 @@ test() { cargo test --release --workspace } +# The tests executed by `test_translator.py` can also be invoked simply by running `cargo nextest run` in the main c2rust workspace. +# `cargo nextest run` even ensures that the repo tests use the latest version of `c2rust-transpile` binary # `test_translator.py` compiles translated code, # which has tons of warnings. # `RUSTFLAGS="-D warnings"` would be inherited by that, diff --git a/scripts/test_translator.py b/scripts/test_translator.py index dbb0a1ea62..65d2a99fdd 100755 --- a/scripts/test_translator.py +++ b/scripts/test_translator.py @@ -654,6 +654,10 @@ def main() -> None: desc = 'run regression / unit / feature tests.' parser = argparse.ArgumentParser(description=desc) parser.add_argument('directory', type=readable_directory) + parser.add_argument( + '--transpiler', dest='transpiler', + default=None, help='Override the path to the c2rust transpiler binary' + ) parser.add_argument( '--only-files', dest='regex_files', type=regex, default='.*', help="Regular expression to filter which tests to run" @@ -681,6 +685,10 @@ def main() -> None: args = parser.parse_args() c.update_args(args) + + if args.transpiler is not None: + c.TRANSPILER = args.transpiler + test_directories = get_testdirectories(args.directory, args.regex_files, args.keep, diff --git a/tests/unit/README.md b/tests/unit/README.md index 675fc64d1c..111f2ca2f1 100644 --- a/tests/unit/README.md +++ b/tests/unit/README.md @@ -66,6 +66,8 @@ $ ./scripts/test_translator.py --keep=all tests/unit $ ./scripts/test_translator.py --help ``` +*Note*: The tests in [`tests/unit`](../tests/unit) can also be executed by running `cargo nextest run` in the main c2rust workspace. + ## What happens under the hood This `tests/unit` directory contains regression, feature, and unit tests. A test directory goes through the following set of steps: