Skip to content
Open
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
18 changes: 18 additions & 0 deletions c2rust/tests/test_translator.rs
Original file line number Diff line number Diff line change
@@ -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");

Comment thread
kkysen marked this conversation as resolved.
let status = cmd
.status()
.unwrap_or_else(|e| panic!("{cmd:?} failed: {e}"));

assert!(status.success(), "{cmd:?} failed with {status}");
}
2 changes: 2 additions & 0 deletions docs/README-developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ 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.

*Note*: 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.

## Documentation

Local documentation can be built with the normal `cargo doc` and `cargo doc --open`.
Expand Down
2 changes: 2 additions & 0 deletions scripts/run_ci_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions scripts/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ $ ./scripts/test_translator.py --keep=all tests/unit
$ ./scripts/test_translator.py --help
```

*Note*: 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

## 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:
Expand Down