Skip to content

Commit 3244d12

Browse files
committed
Get compile-test tests for configuration working
1 parent bb2f6a5 commit 3244d12

19 files changed

+173
-3
lines changed

tests/compile-test.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
extern crate compiletest_rs as compiletest;
44
extern crate test;
55

6+
use std::ffi::OsStr;
7+
use std::fs;
8+
use std::error::Error;
69
use std::env::{set_var, var};
710
use std::path::{Path, PathBuf};
811

@@ -30,7 +33,7 @@ fn rustc_lib_path() -> PathBuf {
3033
option_env!("RUSTC_LIB_PATH").unwrap().into()
3134
}
3235

33-
fn config(dir: &'static str, mode: &'static str) -> compiletest::Config {
36+
fn config(mode: &str, dir: &str) -> compiletest::Config {
3437
let mut config = compiletest::Config::default();
3538

3639
let cfg_mode = mode.parse().expect("Invalid mode");
@@ -61,8 +64,38 @@ fn config(dir: &'static str, mode: &'static str) -> compiletest::Config {
6164
config
6265
}
6366

64-
fn run_mode(dir: &'static str, mode: &'static str) {
65-
compiletest::run_tests(&config(dir, mode));
67+
fn run_mode(mode: &str, dir: &str) {
68+
compiletest::run_tests(&config(mode, dir));
69+
}
70+
71+
fn run_ui_toml() -> Result<(), Box<Error>> {
72+
let base = PathBuf::from("tests/ui-toml/").canonicalize()?;
73+
for dir in fs::read_dir(&base)? {
74+
let dir = dir?;
75+
if !dir.file_type()?.is_dir() {
76+
continue;
77+
}
78+
let dir_path = dir.path();
79+
set_var("CARGO_MANIFEST_DIR", &dir_path);
80+
let config = config("ui", "ui-toml");
81+
for file in fs::read_dir(&dir_path)? {
82+
let file = file?;
83+
let file_path = file.path();
84+
if !file.file_type()?.is_file() {
85+
continue;
86+
}
87+
if file_path.extension() != Some(OsStr::new("rs")) {
88+
continue;
89+
}
90+
let paths = compiletest::common::TestPaths {
91+
file: file_path,
92+
base: base.clone(),
93+
relative_dir: dir_path.file_name().unwrap().into(),
94+
};
95+
compiletest::runtest::run(config.clone(), &paths);
96+
}
97+
}
98+
Ok(())
6699
}
67100

68101
fn prepare_env() {
@@ -76,4 +109,5 @@ fn compile_test() {
76109
prepare_env();
77110
run_mode("run-pass", "run-pass");
78111
run_mode("ui", "ui");
112+
run_ui_toml().unwrap();
79113
}
File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: error reading Clippy's configuration file `$DIR/clippy.toml`: expected an equals, found an identifier at line 1
2+
3+
error: aborting due to previous error
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: error reading Clippy's configuration file `$DIR/clippy.toml`: invalid type: integer `42`, expected a sequence
2+
3+
error: aborting due to previous error
4+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
error: use of a blacklisted/placeholder name `toto`
2+
--> $DIR/conf_french_blacklisted_name.rs:9:9
3+
|
4+
9 | fn test(toto: ()) {}
5+
| ^^^^
6+
|
7+
= note: `-D blacklisted-name` implied by `-D warnings`
8+
9+
error: use of a blacklisted/placeholder name `toto`
10+
--> $DIR/conf_french_blacklisted_name.rs:12:9
11+
|
12+
12 | let toto = 42;
13+
| ^^^^
14+
15+
error: use of a blacklisted/placeholder name `tata`
16+
--> $DIR/conf_french_blacklisted_name.rs:13:9
17+
|
18+
13 | let tata = 42;
19+
| ^^^^
20+
21+
error: use of a blacklisted/placeholder name `titi`
22+
--> $DIR/conf_french_blacklisted_name.rs:14:9
23+
|
24+
14 | let titi = 42;
25+
| ^^^^
26+
27+
error: use of a blacklisted/placeholder name `toto`
28+
--> $DIR/conf_french_blacklisted_name.rs:20:10
29+
|
30+
20 | (toto, Some(tata), titi @ Some(_)) => (),
31+
| ^^^^
32+
33+
error: use of a blacklisted/placeholder name `tata`
34+
--> $DIR/conf_french_blacklisted_name.rs:20:21
35+
|
36+
20 | (toto, Some(tata), titi @ Some(_)) => (),
37+
| ^^^^
38+
39+
error: use of a blacklisted/placeholder name `titi`
40+
--> $DIR/conf_french_blacklisted_name.rs:20:28
41+
|
42+
20 | (toto, Some(tata), titi @ Some(_)) => (),
43+
| ^^^^
44+
45+
error: aborting due to 7 previous errors
46+

0 commit comments

Comments
 (0)