Skip to content

Commit 77eacae

Browse files
committed
compiletest: Unconfigure tests during normal build
1 parent b990c6d commit 77eacae

File tree

9 files changed

+183
-174
lines changed

9 files changed

+183
-174
lines changed

src/tools/compiletest/src/header.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ use log::*;
88

99
use crate::common::{self, CompareMode, Config, Mode, PassMode};
1010
use crate::util;
11-
1211
use crate::extract_gdb_version;
1312

13+
#[cfg(test)]
14+
mod tests;
15+
1416
/// Whether to ignore the test.
1517
#[derive(Clone, Copy, PartialEq, Debug)]
1618
pub enum Ignore {
@@ -969,29 +971,3 @@ fn parse_normalization_string(line: &mut &str) -> Option<String> {
969971
*line = &line[end + 1..];
970972
Some(result)
971973
}
972-
973-
#[test]
974-
fn test_parse_normalization_string() {
975-
let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\".";
976-
let first = parse_normalization_string(&mut s);
977-
assert_eq!(first, Some("something (32 bits)".to_owned()));
978-
assert_eq!(s, " -> \"something ($WORD bits)\".");
979-
980-
// Nothing to normalize (No quotes)
981-
let mut s = "normalize-stderr-32bit: something (32 bits) -> something ($WORD bits).";
982-
let first = parse_normalization_string(&mut s);
983-
assert_eq!(first, None);
984-
assert_eq!(s, r#"normalize-stderr-32bit: something (32 bits) -> something ($WORD bits)."#);
985-
986-
// Nothing to normalize (Only a single quote)
987-
let mut s = "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits).";
988-
let first = parse_normalization_string(&mut s);
989-
assert_eq!(first, None);
990-
assert_eq!(s, "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits).");
991-
992-
// Nothing to normalize (Three quotes)
993-
let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits).";
994-
let first = parse_normalization_string(&mut s);
995-
assert_eq!(first, Some("something (32 bits)".to_owned()));
996-
assert_eq!(s, " -> \"something ($WORD bits).");
997-
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use super::*;
2+
3+
#[test]
4+
fn test_parse_normalization_string() {
5+
let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\".";
6+
let first = parse_normalization_string(&mut s);
7+
assert_eq!(first, Some("something (32 bits)".to_owned()));
8+
assert_eq!(s, " -> \"something ($WORD bits)\".");
9+
10+
// Nothing to normalize (No quotes)
11+
let mut s = "normalize-stderr-32bit: something (32 bits) -> something ($WORD bits).";
12+
let first = parse_normalization_string(&mut s);
13+
assert_eq!(first, None);
14+
assert_eq!(s, r#"normalize-stderr-32bit: something (32 bits) -> something ($WORD bits)."#);
15+
16+
// Nothing to normalize (Only a single quote)
17+
let mut s = "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits).";
18+
let first = parse_normalization_string(&mut s);
19+
assert_eq!(first, None);
20+
assert_eq!(s, "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits).");
21+
22+
// Nothing to normalize (Three quotes)
23+
let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits).";
24+
let first = parse_normalization_string(&mut s);
25+
assert_eq!(first, Some("something (32 bits)".to_owned()));
26+
assert_eq!(s, " -> \"something ($WORD bits).");
27+
}

src/tools/compiletest/src/main.rs

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ use log::*;
2525

2626
use self::header::{EarlyProps, Ignore};
2727

28+
#[cfg(test)]
29+
mod tests;
30+
2831
pub mod common;
2932
pub mod errors;
3033
pub mod header;
@@ -1093,53 +1096,3 @@ fn extract_lldb_version(full_version_line: Option<String>) -> (Option<String>, b
10931096
fn is_blacklisted_lldb_version(version: &str) -> bool {
10941097
version == "350"
10951098
}
1096-
1097-
#[test]
1098-
fn test_extract_gdb_version() {
1099-
macro_rules! test { ($($expectation:tt: $input:tt,)*) => {{$(
1100-
assert_eq!(extract_gdb_version($input), Some($expectation));
1101-
)*}}}
1102-
1103-
test! {
1104-
7000001: "GNU gdb (GDB) CentOS (7.0.1-45.el5.centos)",
1105-
1106-
7002000: "GNU gdb (GDB) Red Hat Enterprise Linux (7.2-90.el6)",
1107-
1108-
7004000: "GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04",
1109-
7004001: "GNU gdb (GDB) 7.4.1-debian",
1110-
1111-
7006001: "GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-80.el7",
1112-
1113-
7007001: "GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1",
1114-
7007001: "GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1",
1115-
7007001: "GNU gdb (GDB) Fedora 7.7.1-21.fc20",
1116-
1117-
7008000: "GNU gdb (GDB; openSUSE 13.2) 7.8",
1118-
7009001: "GNU gdb (GDB) Fedora 7.9.1-20.fc22",
1119-
7010001: "GNU gdb (GDB) Fedora 7.10.1-31.fc23",
1120-
1121-
7011000: "GNU gdb (Ubuntu 7.11-0ubuntu1) 7.11",
1122-
7011001: "GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1",
1123-
7011001: "GNU gdb (Debian 7.11.1-2) 7.11.1",
1124-
7011001: "GNU gdb (GDB) Fedora 7.11.1-86.fc24",
1125-
7011001: "GNU gdb (GDB; openSUSE Leap 42.1) 7.11.1",
1126-
7011001: "GNU gdb (GDB; openSUSE Tumbleweed) 7.11.1",
1127-
1128-
7011090: "7.11.90",
1129-
7011090: "GNU gdb (Ubuntu 7.11.90.20161005-0ubuntu1) 7.11.90.20161005-git",
1130-
1131-
7012000: "7.12",
1132-
7012000: "GNU gdb (GDB) 7.12",
1133-
7012000: "GNU gdb (GDB) 7.12.20161027-git",
1134-
7012050: "GNU gdb (GDB) 7.12.50.20161027-git",
1135-
}
1136-
}
1137-
1138-
#[test]
1139-
fn is_test_test() {
1140-
assert_eq!(true, is_test(&OsString::from("a_test.rs")));
1141-
assert_eq!(false, is_test(&OsString::from(".a_test.rs")));
1142-
assert_eq!(false, is_test(&OsString::from("a_cat.gif")));
1143-
assert_eq!(false, is_test(&OsString::from("#a_dog_gif")));
1144-
assert_eq!(false, is_test(&OsString::from("~a_temp_file")));
1145-
}

src/tools/compiletest/src/runtest.rs

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ use log::*;
3535
use crate::extract_gdb_version;
3636
use crate::is_android_gdb_target;
3737

38+
#[cfg(test)]
39+
mod tests;
40+
3841
#[cfg(windows)]
3942
fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
4043
use std::sync::Mutex;
@@ -3706,68 +3709,3 @@ fn read2_abbreviated(mut child: Child) -> io::Result<Output> {
37063709
stderr: stderr.into_bytes(),
37073710
})
37083711
}
3709-
3710-
#[cfg(test)]
3711-
mod tests {
3712-
use super::TestCx;
3713-
3714-
#[test]
3715-
fn normalize_platform_differences() {
3716-
assert_eq!(
3717-
TestCx::normalize_platform_differences(r"$DIR\foo.rs"),
3718-
"$DIR/foo.rs"
3719-
);
3720-
assert_eq!(
3721-
TestCx::normalize_platform_differences(r"$BUILD_DIR\..\parser.rs"),
3722-
"$BUILD_DIR/../parser.rs"
3723-
);
3724-
assert_eq!(
3725-
TestCx::normalize_platform_differences(r"$DIR\bar.rs hello\nworld"),
3726-
r"$DIR/bar.rs hello\nworld"
3727-
);
3728-
assert_eq!(
3729-
TestCx::normalize_platform_differences(r"either bar\baz.rs or bar\baz\mod.rs"),
3730-
r"either bar/baz.rs or bar/baz/mod.rs",
3731-
);
3732-
assert_eq!(
3733-
TestCx::normalize_platform_differences(r"`.\some\path.rs`"),
3734-
r"`./some/path.rs`",
3735-
);
3736-
assert_eq!(
3737-
TestCx::normalize_platform_differences(r"`some\path.rs`"),
3738-
r"`some/path.rs`",
3739-
);
3740-
assert_eq!(
3741-
TestCx::normalize_platform_differences(r"$DIR\path-with-dashes.rs"),
3742-
r"$DIR/path-with-dashes.rs"
3743-
);
3744-
assert_eq!(
3745-
TestCx::normalize_platform_differences(r"$DIR\path_with_underscores.rs"),
3746-
r"$DIR/path_with_underscores.rs",
3747-
);
3748-
assert_eq!(
3749-
TestCx::normalize_platform_differences(r"$DIR\foo.rs:12:11"), "$DIR/foo.rs:12:11",
3750-
);
3751-
assert_eq!(
3752-
TestCx::normalize_platform_differences(r"$DIR\path with spaces 'n' quotes"),
3753-
"$DIR/path with spaces 'n' quotes",
3754-
);
3755-
assert_eq!(
3756-
TestCx::normalize_platform_differences(r"$DIR\file_with\no_extension"),
3757-
"$DIR/file_with/no_extension",
3758-
);
3759-
3760-
assert_eq!(TestCx::normalize_platform_differences(r"\n"), r"\n");
3761-
assert_eq!(TestCx::normalize_platform_differences(r"{ \n"), r"{ \n");
3762-
assert_eq!(TestCx::normalize_platform_differences(r"`\]`"), r"`\]`");
3763-
assert_eq!(TestCx::normalize_platform_differences(r#""\{""#), r#""\{""#);
3764-
assert_eq!(
3765-
TestCx::normalize_platform_differences(r#"write!(&mut v, "Hello\n")"#),
3766-
r#"write!(&mut v, "Hello\n")"#
3767-
);
3768-
assert_eq!(
3769-
TestCx::normalize_platform_differences(r#"println!("test\ntest")"#),
3770-
r#"println!("test\ntest")"#,
3771-
);
3772-
}
3773-
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use super::*;
2+
3+
#[test]
4+
fn normalize_platform_differences() {
5+
assert_eq!(
6+
TestCx::normalize_platform_differences(r"$DIR\foo.rs"),
7+
"$DIR/foo.rs"
8+
);
9+
assert_eq!(
10+
TestCx::normalize_platform_differences(r"$BUILD_DIR\..\parser.rs"),
11+
"$BUILD_DIR/../parser.rs"
12+
);
13+
assert_eq!(
14+
TestCx::normalize_platform_differences(r"$DIR\bar.rs hello\nworld"),
15+
r"$DIR/bar.rs hello\nworld"
16+
);
17+
assert_eq!(
18+
TestCx::normalize_platform_differences(r"either bar\baz.rs or bar\baz\mod.rs"),
19+
r"either bar/baz.rs or bar/baz/mod.rs",
20+
);
21+
assert_eq!(
22+
TestCx::normalize_platform_differences(r"`.\some\path.rs`"),
23+
r"`./some/path.rs`",
24+
);
25+
assert_eq!(
26+
TestCx::normalize_platform_differences(r"`some\path.rs`"),
27+
r"`some/path.rs`",
28+
);
29+
assert_eq!(
30+
TestCx::normalize_platform_differences(r"$DIR\path-with-dashes.rs"),
31+
r"$DIR/path-with-dashes.rs"
32+
);
33+
assert_eq!(
34+
TestCx::normalize_platform_differences(r"$DIR\path_with_underscores.rs"),
35+
r"$DIR/path_with_underscores.rs",
36+
);
37+
assert_eq!(
38+
TestCx::normalize_platform_differences(r"$DIR\foo.rs:12:11"), "$DIR/foo.rs:12:11",
39+
);
40+
assert_eq!(
41+
TestCx::normalize_platform_differences(r"$DIR\path with spaces 'n' quotes"),
42+
"$DIR/path with spaces 'n' quotes",
43+
);
44+
assert_eq!(
45+
TestCx::normalize_platform_differences(r"$DIR\file_with\no_extension"),
46+
"$DIR/file_with/no_extension",
47+
);
48+
49+
assert_eq!(TestCx::normalize_platform_differences(r"\n"), r"\n");
50+
assert_eq!(TestCx::normalize_platform_differences(r"{ \n"), r"{ \n");
51+
assert_eq!(TestCx::normalize_platform_differences(r"`\]`"), r"`\]`");
52+
assert_eq!(TestCx::normalize_platform_differences(r#""\{""#), r#""\{""#);
53+
assert_eq!(
54+
TestCx::normalize_platform_differences(r#"write!(&mut v, "Hello\n")"#),
55+
r#"write!(&mut v, "Hello\n")"#
56+
);
57+
assert_eq!(
58+
TestCx::normalize_platform_differences(r#"println!("test\ntest")"#),
59+
r#"println!("test\ntest")"#,
60+
);
61+
}

src/tools/compiletest/src/tests.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use super::*;
2+
3+
#[test]
4+
fn test_extract_gdb_version() {
5+
macro_rules! test { ($($expectation:tt: $input:tt,)*) => {{$(
6+
assert_eq!(extract_gdb_version($input), Some($expectation));
7+
)*}}}
8+
9+
test! {
10+
7000001: "GNU gdb (GDB) CentOS (7.0.1-45.el5.centos)",
11+
12+
7002000: "GNU gdb (GDB) Red Hat Enterprise Linux (7.2-90.el6)",
13+
14+
7004000: "GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04",
15+
7004001: "GNU gdb (GDB) 7.4.1-debian",
16+
17+
7006001: "GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-80.el7",
18+
19+
7007001: "GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1",
20+
7007001: "GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1",
21+
7007001: "GNU gdb (GDB) Fedora 7.7.1-21.fc20",
22+
23+
7008000: "GNU gdb (GDB; openSUSE 13.2) 7.8",
24+
7009001: "GNU gdb (GDB) Fedora 7.9.1-20.fc22",
25+
7010001: "GNU gdb (GDB) Fedora 7.10.1-31.fc23",
26+
27+
7011000: "GNU gdb (Ubuntu 7.11-0ubuntu1) 7.11",
28+
7011001: "GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1",
29+
7011001: "GNU gdb (Debian 7.11.1-2) 7.11.1",
30+
7011001: "GNU gdb (GDB) Fedora 7.11.1-86.fc24",
31+
7011001: "GNU gdb (GDB; openSUSE Leap 42.1) 7.11.1",
32+
7011001: "GNU gdb (GDB; openSUSE Tumbleweed) 7.11.1",
33+
34+
7011090: "7.11.90",
35+
7011090: "GNU gdb (Ubuntu 7.11.90.20161005-0ubuntu1) 7.11.90.20161005-git",
36+
37+
7012000: "7.12",
38+
7012000: "GNU gdb (GDB) 7.12",
39+
7012000: "GNU gdb (GDB) 7.12.20161027-git",
40+
7012050: "GNU gdb (GDB) 7.12.50.20161027-git",
41+
}
42+
}
43+
44+
#[test]
45+
fn is_test_test() {
46+
assert_eq!(true, is_test(&OsString::from("a_test.rs")));
47+
assert_eq!(false, is_test(&OsString::from(".a_test.rs")));
48+
assert_eq!(false, is_test(&OsString::from("a_cat.gif")));
49+
assert_eq!(false, is_test(&OsString::from("#a_dog_gif")));
50+
assert_eq!(false, is_test(&OsString::from("~a_temp_file")));
51+
}

src/tools/compiletest/src/util.rs

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use crate::common::Config;
55

66
use log::*;
77

8+
#[cfg(test)]
9+
mod tests;
10+
811
/// Conversion table from triple OS name to Rust SYSNAME
912
const OS_TABLE: &'static [(&'static str, &'static str)] = &[
1013
("android", "android"),
@@ -157,34 +160,3 @@ impl PathBufExt for PathBuf {
157160
}
158161
}
159162
}
160-
161-
#[test]
162-
#[should_panic(expected = "Cannot determine Architecture from triple")]
163-
fn test_get_arch_failure() {
164-
get_arch("abc");
165-
}
166-
167-
#[test]
168-
fn test_get_arch() {
169-
assert_eq!("x86_64", get_arch("x86_64-unknown-linux-gnu"));
170-
assert_eq!("x86_64", get_arch("amd64"));
171-
assert_eq!("nvptx64", get_arch("nvptx64-nvidia-cuda"));
172-
}
173-
174-
#[test]
175-
#[should_panic(expected = "Cannot determine OS from triple")]
176-
fn test_matches_os_failure() {
177-
matches_os("abc", "abc");
178-
}
179-
180-
#[test]
181-
fn test_matches_os() {
182-
assert!(matches_os("x86_64-unknown-linux-gnu", "linux"));
183-
assert!(matches_os("wasm32-unknown-unknown", "emscripten"));
184-
assert!(matches_os("wasm32-unknown-unknown", "wasm32-bare"));
185-
assert!(!matches_os("wasm32-unknown-unknown", "windows"));
186-
assert!(matches_os("thumbv6m0-none-eabi", "none"));
187-
assert!(matches_os("riscv32imc-unknown-none-elf", "none"));
188-
assert!(matches_os("nvptx64-nvidia-cuda", "cuda"));
189-
assert!(matches_os("x86_64-fortanix-unknown-sgx", "sgx"));
190-
}

0 commit comments

Comments
 (0)