Skip to content

Commit cf6a86f

Browse files
committed
Add test to make sure we never break recursive types
1 parent e69f125 commit cf6a86f

File tree

2 files changed

+243541
-2
lines changed

2 files changed

+243541
-2
lines changed

tests/lang_tests_common.rs

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ use boml::Toml;
1212
/// Controls the compile options (e.g., optimization level) used to compile
1313
/// test code.
1414
#[allow(dead_code)] // Each test crate picks one variant
15+
#[derive(Clone, Copy)]
1516
pub enum Profile {
1617
Debug,
1718
Release,
1819
}
1920

2021
pub fn main_inner(profile: Profile) {
2122
let tempdir = TempDir::new().expect("temp dir");
22-
let current_dir = current_dir().expect("current dir");
23-
let current_dir = current_dir.to_str().expect("current dir").to_string();
23+
let tempdir2 = TempDir::new().expect("temp dir");
24+
2425
let toml = Toml::parse(include_str!("../config.toml"))
2526
.expect("Failed to parse `config.toml`");
2627
let gcc_path = if let Ok(gcc_path) = toml.get_string("gcc-path") {
@@ -71,6 +72,9 @@ pub fn main_inner(profile: Profile) {
7172
Some(lines)
7273
})
7374
.test_cmds(move |path| {
75+
let current_dir = current_dir().expect("current dir");
76+
let current_dir = current_dir.to_str().expect("current dir").to_string();
77+
7478
// Test command 1: Compile `x.rs` into `tempdir/x`.
7579
let mut exe = PathBuf::new();
7680
exe.push(&tempdir);
@@ -79,6 +83,7 @@ pub fn main_inner(profile: Profile) {
7983
compiler.args(&[
8084
&format!("-Zcodegen-backend={}/target/debug/librustc_codegen_gcc.so", current_dir),
8185
"--sysroot", &format!("{}/build_sysroot/sysroot/", current_dir),
86+
"--edition", "2021",
8287
"-Zno-parallel-llvm",
8388
"-C", "link-arg=-lc",
8489
"-o", exe.to_str().expect("to_str"),
@@ -145,4 +150,58 @@ pub fn main_inner(profile: Profile) {
145150
}
146151
})
147152
.run();
153+
154+
LangTester::new()
155+
.test_dir("tests/lib")
156+
.test_file_filter(filter)
157+
.test_extract(|source| {
158+
let lines =
159+
source.lines()
160+
.skip_while(|l| !l.starts_with("//"))
161+
.take_while(|l| l.starts_with("//"))
162+
.map(|l| &l[2..])
163+
.collect::<Vec<_>>()
164+
.join("\n");
165+
Some(lines)
166+
})
167+
.test_cmds(move |path| {
168+
let current_dir = current_dir().expect("current dir");
169+
let current_dir = current_dir.to_str().expect("current dir").to_string();
170+
171+
// Test command 1: Compile `x.rs` into `tempdir2/x`.
172+
let mut exe = PathBuf::new();
173+
exe.push(&tempdir2);
174+
exe.push(path.file_stem().expect("file_stem"));
175+
let mut compiler = Command::new("rustc");
176+
compiler.args(&[
177+
&format!("-Zcodegen-backend={}/target/debug/librustc_codegen_gcc.so", current_dir),
178+
"--sysroot", &format!("{}/build_sysroot/sysroot/", current_dir),
179+
"--edition", "2021",
180+
"--crate-type", "lib",
181+
"-Zno-parallel-llvm",
182+
"-C", "link-arg=-lc",
183+
"-o", exe.to_str().expect("to_str"),
184+
path.to_str().expect("to_str"),
185+
]);
186+
187+
if let Some(flags) = option_env!("TEST_FLAGS") {
188+
for flag in flags.split_whitespace() {
189+
compiler.arg(&flag);
190+
}
191+
}
192+
match profile {
193+
Profile::Debug => {}
194+
Profile::Release => {
195+
compiler.args(&[
196+
"-C", "opt-level=3",
197+
"-C", "lto=no",
198+
]);
199+
}
200+
}
201+
202+
vec![
203+
("Compiler", compiler),
204+
]
205+
})
206+
.run();
148207
}

0 commit comments

Comments
 (0)