]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_codegen_gcc/tests/lib.rs
New upstream version 1.62.1+dfsg1
[rustc.git] / compiler / rustc_codegen_gcc / tests / lib.rs
CommitLineData
c295e0f8
XL
1use std::{
2 env::{self, current_dir},
3 path::PathBuf,
4 process::Command,
5};
6
7use lang_tester::LangTester;
8use tempfile::TempDir;
9
10fn main() {
11 let tempdir = TempDir::new().expect("temp dir");
12 let current_dir = current_dir().expect("current dir");
13 let current_dir = current_dir.to_str().expect("current dir").to_string();
14 let gcc_path = include_str!("../gcc_path");
15 let gcc_path = gcc_path.trim();
16 env::set_var("LD_LIBRARY_PATH", gcc_path);
17 LangTester::new()
18 .test_dir("tests/run")
19 .test_file_filter(|path| path.extension().expect("extension").to_str().expect("to_str") == "rs")
20 .test_extract(|source| {
21 let lines =
22 source.lines()
23 .skip_while(|l| !l.starts_with("//"))
24 .take_while(|l| l.starts_with("//"))
25 .map(|l| &l[2..])
26 .collect::<Vec<_>>()
27 .join("\n");
28 Some(lines)
29 })
30 .test_cmds(move |path| {
31 // Test command 1: Compile `x.rs` into `tempdir/x`.
32 let mut exe = PathBuf::new();
33 exe.push(&tempdir);
34 exe.push(path.file_stem().expect("file_stem"));
35 let mut compiler = Command::new("rustc");
36 compiler.args(&[
37 &format!("-Zcodegen-backend={}/target/debug/librustc_codegen_gcc.so", current_dir),
38 "--sysroot", &format!("{}/build_sysroot/sysroot/", current_dir),
39 "-Zno-parallel-llvm",
40 "-C", "panic=abort",
41 "-C", "link-arg=-lc",
42 "-o", exe.to_str().expect("to_str"),
43 path.to_str().expect("to_str"),
44 ]);
45 // Test command 2: run `tempdir/x`.
46 let runtime = Command::new(exe);
47 vec![("Compiler", compiler), ("Run-time", runtime)]
48 })
49 .run();
50}