about summary refs log tree commit diff
path: root/src/tools/compiletest
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2020-01-24 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2020-01-27 12:08:53 +0100
commitd857f6f1aba6308cb4458ec1d210f722d55017cb (patch)
tree0f2ff64e94a65e9ed504927e3ce66ed7b2361d3c /src/tools/compiletest
parentbb6aac38131528384343e6724578a89bf8daf68f (diff)
downloadrust-d857f6f1aba6308cb4458ec1d210f722d55017cb.tar.gz
rust-d857f6f1aba6308cb4458ec1d210f722d55017cb.zip
compiletest: Add unit tests for EarlyProps
Diffstat (limited to 'src/tools/compiletest')
-rw-r--r--src/tools/compiletest/src/header/tests.rs156
1 files changed, 155 insertions, 1 deletions
diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs
index 2a1831d5ee8..b2d4ad382dd 100644
--- a/src/tools/compiletest/src/header/tests.rs
+++ b/src/tools/compiletest/src/header/tests.rs
@@ -1,4 +1,7 @@
-use super::*;
+use std::path::Path;
+
+use crate::common::{Config, Debugger};
+use crate::header::{parse_normalization_string, EarlyProps};
 
 #[test]
 fn test_parse_normalization_string() {
@@ -25,3 +28,154 @@ fn test_parse_normalization_string() {
     assert_eq!(first, Some("something (32 bits)".to_owned()));
     assert_eq!(s, " -> \"something ($WORD bits).");
 }
+
+fn config() -> Config {
+    let args = &[
+        "compiletest",
+        "--mode=ui",
+        "--compile-lib-path=",
+        "--run-lib-path=",
+        "--rustc-path=",
+        "--lldb-python=",
+        "--docck-python=",
+        "--src-base=",
+        "--build-base=",
+        "--stage-id=stage2",
+        "--cc=c",
+        "--cxx=c++",
+        "--cflags=",
+        "--llvm-components=",
+        "--llvm-cxxflags=",
+        "--android-cross-path=",
+        "--target=x86_64-unknown-linux-gnu",
+    ];
+    let args = args.iter().map(ToString::to_string).collect();
+    crate::parse_config(args)
+}
+
+fn parse_rs(config: &Config, contents: &str) -> EarlyProps {
+    let bytes = contents.as_bytes();
+    EarlyProps::from_reader(config, Path::new("a.rs"), bytes)
+}
+
+fn parse_makefile(config: &Config, contents: &str) -> EarlyProps {
+    let bytes = contents.as_bytes();
+    EarlyProps::from_reader(config, Path::new("Makefile"), bytes)
+}
+
+#[test]
+fn should_fail() {
+    let config = config();
+
+    assert!(!parse_rs(&config, "").should_fail);
+    assert!(parse_rs(&config, "// should-fail").should_fail);
+}
+
+#[test]
+fn revisions() {
+    let config = config();
+
+    assert_eq!(parse_rs(&config, "// revisions: a b c").revisions, vec!["a", "b", "c"],);
+    assert_eq!(
+        parse_makefile(&config, "# revisions: hello there").revisions,
+        vec!["hello", "there"],
+    );
+}
+
+#[test]
+fn aux_build() {
+    let config = config();
+
+    assert_eq!(
+        parse_rs(
+            &config,
+            r"
+        // aux-build: a.rs
+        // aux-build: b.rs
+        "
+        )
+        .aux,
+        vec!["a.rs", "b.rs"],
+    );
+}
+
+#[test]
+fn no_system_llvm() {
+    let mut config = config();
+
+    config.system_llvm = false;
+    assert!(!parse_rs(&config, "// no-system-llvm").ignore);
+
+    config.system_llvm = true;
+    assert!(parse_rs(&config, "// no-system-llvm").ignore);
+}
+
+#[test]
+fn ignore_target() {
+    let mut config = config();
+    config.target = "x86_64-unknown-linux-gnu".to_owned();
+
+    assert!(parse_rs(&config, "// ignore-x86_64-unknown-linux-gnu").ignore);
+    assert!(parse_rs(&config, "// ignore-x86_64").ignore);
+    assert!(parse_rs(&config, "// ignore-linux").ignore);
+    assert!(parse_rs(&config, "// ignore-gnu").ignore);
+    assert!(parse_rs(&config, "// ignore-64bit").ignore);
+
+    assert!(!parse_rs(&config, "// ignore-i686").ignore);
+    assert!(!parse_rs(&config, "// ignore-windows").ignore);
+    assert!(!parse_rs(&config, "// ignore-msvc").ignore);
+    assert!(!parse_rs(&config, "// ignore-32bit").ignore);
+}
+
+#[test]
+fn only_target() {
+    let mut config = config();
+    config.target = "x86_64-pc-windows-gnu".to_owned();
+
+    assert!(parse_rs(&config, "// only-i686").ignore);
+    assert!(parse_rs(&config, "// only-linux").ignore);
+    assert!(parse_rs(&config, "// only-msvc").ignore);
+    assert!(parse_rs(&config, "// only-32bit").ignore);
+
+    assert!(!parse_rs(&config, "// only-x86_64-pc-windows-gnu").ignore);
+    assert!(!parse_rs(&config, "// only-x86_64").ignore);
+    assert!(!parse_rs(&config, "// only-windows").ignore);
+    assert!(!parse_rs(&config, "// only-gnu").ignore);
+    assert!(!parse_rs(&config, "// only-64bit").ignore);
+}
+
+#[test]
+fn stage() {
+    let mut config = config();
+    config.stage_id = "stage1".to_owned();
+
+    assert!(parse_rs(&config, "// ignore-stage1").ignore);
+    assert!(!parse_rs(&config, "// ignore-stage2").ignore);
+}
+
+#[test]
+fn cross_compile() {
+    let mut config = config();
+    config.host = "x86_64-apple-darwin".to_owned();
+    config.target = "wasm32-unknown-unknown".to_owned();
+    assert!(parse_rs(&config, "// ignore-cross-compile").ignore);
+
+    config.target = config.host.clone();
+    assert!(!parse_rs(&config, "// ignore-cross-compile").ignore);
+}
+
+#[test]
+fn debugger() {
+    let mut config = config();
+    config.debugger = None;
+    assert!(!parse_rs(&config, "// ignore-cdb").ignore);
+
+    config.debugger = Some(Debugger::Cdb);
+    assert!(parse_rs(&config, "// ignore-cdb").ignore);
+
+    config.debugger = Some(Debugger::Gdb);
+    assert!(parse_rs(&config, "// ignore-gdb").ignore);
+
+    config.debugger = Some(Debugger::Lldb);
+    assert!(parse_rs(&config, "// ignore-lldb").ignore);
+}