Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to make sure we never break recursive types #443

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
63 changes: 61 additions & 2 deletions tests/lang_tests_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ use boml::Toml;
/// Controls the compile options (e.g., optimization level) used to compile
/// test code.
#[allow(dead_code)] // Each test crate picks one variant
#[derive(Clone, Copy)]
pub enum Profile {
Debug,
Release,
}

pub fn main_inner(profile: Profile) {
let tempdir = TempDir::new().expect("temp dir");
let current_dir = current_dir().expect("current dir");
let current_dir = current_dir.to_str().expect("current dir").to_string();
let tempdir2 = TempDir::new().expect("temp dir");

let toml = Toml::parse(include_str!("../config.toml"))
.expect("Failed to parse `config.toml`");
let gcc_path = if let Ok(gcc_path) = toml.get_string("gcc-path") {
Expand Down Expand Up @@ -71,6 +72,9 @@ pub fn main_inner(profile: Profile) {
Some(lines)
})
.test_cmds(move |path| {
let current_dir = current_dir().expect("current dir");
let current_dir = current_dir.to_str().expect("current dir").to_string();

// Test command 1: Compile `x.rs` into `tempdir/x`.
let mut exe = PathBuf::new();
exe.push(&tempdir);
Expand All @@ -79,6 +83,7 @@ pub fn main_inner(profile: Profile) {
compiler.args(&[
&format!("-Zcodegen-backend={}/target/debug/librustc_codegen_gcc.so", current_dir),
"--sysroot", &format!("{}/build_sysroot/sysroot/", current_dir),
"--edition", "2021",
"-Zno-parallel-llvm",
"-C", "link-arg=-lc",
"-o", exe.to_str().expect("to_str"),
Expand Down Expand Up @@ -145,4 +150,58 @@ pub fn main_inner(profile: Profile) {
}
})
.run();

LangTester::new()
.test_dir("tests/lib")
.test_file_filter(filter)
.test_extract(|source| {
let lines =
source.lines()
.skip_while(|l| !l.starts_with("//"))
.take_while(|l| l.starts_with("//"))
.map(|l| &l[2..])
.collect::<Vec<_>>()
.join("\n");
Some(lines)
})
.test_cmds(move |path| {
let current_dir = current_dir().expect("current dir");
let current_dir = current_dir.to_str().expect("current dir").to_string();

// Test command 1: Compile `x.rs` into `tempdir2/x`.
let mut exe = PathBuf::new();
exe.push(&tempdir2);
exe.push(path.file_stem().expect("file_stem"));
let mut compiler = Command::new("rustc");
compiler.args(&[
&format!("-Zcodegen-backend={}/target/debug/librustc_codegen_gcc.so", current_dir),
"--sysroot", &format!("{}/build_sysroot/sysroot/", current_dir),
"--edition", "2021",
"--crate-type", "lib",
"-Zno-parallel-llvm",
"-C", "link-arg=-lc",
"-o", exe.to_str().expect("to_str"),
path.to_str().expect("to_str"),
]);

if let Some(flags) = option_env!("TEST_FLAGS") {
for flag in flags.split_whitespace() {
compiler.arg(&flag);
}
}
match profile {
Profile::Debug => {}
Profile::Release => {
compiler.args(&[
"-C", "opt-level=3",
"-C", "lto=no",
]);
}
}

vec![
("Compiler", compiler),
]
})
.run();
}
Loading
Loading