Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions c2rust/tests/test_translator_uses_current_transpiler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::process::Command;

#[test]
fn test_translator_uses_current_transpiler() {
Comment thread
chiragdhawan24 marked this conversation as resolved.
Outdated
let transpile_path = env!("CARGO_BIN_EXE_c2rust-transpile");

let status = Command::new("python")
Comment thread
ahomescu marked this conversation as resolved.
Outdated
.arg("../scripts/test_translator.py")
Comment thread
kkysen marked this conversation as resolved.
Outdated
.arg("../tests/unit")
.arg("--transpiler")
.arg(transpile_path)
.status()
.expect("failed to run python script");

assert!(
status.success(),
"test_translator.py failed with status: {}",
status
Comment thread
kkysen marked this conversation as resolved.
Outdated
);
}
14 changes: 12 additions & 2 deletions scripts/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ def run(self) -> List[TestOutcome]:
args += ["--target", self.target]

retcode, stdout, stderr = cargo[args].run(retcode=None)
Comment thread
kkysen marked this conversation as resolved.

if retcode != 0:
_, lib_file_path_short = os.path.split(lib_file.path)

Expand All @@ -591,7 +591,7 @@ def run(self) -> List[TestOutcome]:
if "... ok" in line:
self.print_status(Colors.OKGREEN, "OK", "{}".format(line))
sys.stdout.write('\n')

# Don't distinguish between expected and unexpected failures.
# `#[should_panic]` is used for that instead of `// xfail` now.
# Also, `cargo test -- --format json` is unstable, so it's easier to just parse very simply.
Expand Down 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 All @@ -689,11 +697,13 @@ def main() -> None:

logging.debug("args: %s", " ".join(sys.argv))


Comment thread
kkysen marked this conversation as resolved.
Outdated
# Set whether we are using nix.
C2RUST_USE_NIX=args.use_nix

# check that the binaries have been built first
bins = [c.TRANSPILER]

for b in bins:
if not os.path.isfile(b):
msg = b + " not found; run cargo build --release first?"
Expand Down
Loading