]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_interface/tests.rs
Rollup merge of #68141 - euclio:replace-bindings-with-winapi, r=alexcrichton
[rust.git] / src / librustc_interface / tests.rs
index d4b5e833dfb23df34cf3304089b6df867c008b6a..ec75a1c6a3938d92df5d95ee847cf19270997473 100644 (file)
@@ -2,23 +2,23 @@
 
 use crate::interface::parse_cfgspecs;
 
-use rustc::lint;
+use rustc::lint::Level;
 use rustc::middle::cstore;
 use rustc::session::config::{build_configuration, build_session_options, to_crate_config};
-use rustc::session::config::{LtoCli, LinkerPluginLto, SwitchWithOptPath, ExternEntry};
+use rustc::session::config::{rustc_optgroups, ErrorOutputType, ExternLocation, Options, Passes};
+use rustc::session::config::{ExternEntry, LinkerPluginLto, LtoCli, SwitchWithOptPath};
 use rustc::session::config::{Externs, OutputType, OutputTypes, SymbolManglingVersion};
-use rustc::session::config::{rustc_optgroups, Options, ErrorOutputType, Passes, ExternLocation};
-use rustc::session::{build_session, Session};
 use rustc::session::search_paths::SearchPath;
+use rustc::session::{build_session, Session};
+use rustc_data_structures::fx::FxHashSet;
+use rustc_errors::{emitter::HumanReadableErrorType, registry, ColorConfig};
+use rustc_span::edition::{Edition, DEFAULT_EDITION};
+use rustc_span::symbol::sym;
+use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel};
 use std::collections::{BTreeMap, BTreeSet};
 use std::iter::FromIterator;
 use std::path::PathBuf;
-use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel};
-use syntax::symbol::sym;
-use syntax::edition::{Edition, DEFAULT_EDITION};
 use syntax;
-use rustc_data_structures::fx::FxHashSet;
-use rustc_errors::{ColorConfig, emitter::HumanReadableErrorType, registry};
 
 type CfgSpecs = FxHashSet<(String, Option<String>)>;
 
@@ -40,8 +40,7 @@ fn new_public_extern_entry<S, I>(locations: I) -> ExternEntry
     S: Into<String>,
     I: IntoIterator<Item = S>,
 {
-    let locations: BTreeSet<_> = locations.into_iter().map(|s| s.into())
-        .collect();
+    let locations: BTreeSet<_> = locations.into_iter().map(|s| s.into()).collect();
 
     ExternEntry {
         location: ExternLocation::ExactPaths(locations),
@@ -95,9 +94,8 @@ fn test_can_print_warnings() {
     });
 
     syntax::with_default_globals(|| {
-        let matches = optgroups()
-            .parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()])
-            .unwrap();
+        let matches =
+            optgroups().parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()]).unwrap();
         let (sess, _) = mk_session(matches);
         assert!(sess.diagnostic().can_emit_warnings());
     });
@@ -115,10 +113,8 @@ fn test_output_types_tracking_hash_different_paths() {
     let mut v2 = Options::default();
     let mut v3 = Options::default();
 
-    v1.output_types =
-        OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("./some/thing")))]);
-    v2.output_types =
-        OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("/some/thing")))]);
+    v1.output_types = OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("./some/thing")))]);
+    v2.output_types = OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("/some/thing")))]);
     v3.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
 
     assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
@@ -159,36 +155,18 @@ fn test_externs_tracking_hash_different_construction_order() {
     let mut v3 = Options::default();
 
     v1.externs = Externs::new(mk_map(vec![
-        (
-            String::from("a"),
-            new_public_extern_entry(vec!["b", "c"])
-        ),
-        (
-            String::from("d"),
-            new_public_extern_entry(vec!["e", "f"])
-        ),
+        (String::from("a"), new_public_extern_entry(vec!["b", "c"])),
+        (String::from("d"), new_public_extern_entry(vec!["e", "f"])),
     ]));
 
     v2.externs = Externs::new(mk_map(vec![
-        (
-            String::from("d"),
-            new_public_extern_entry(vec!["e", "f"])
-        ),
-        (
-            String::from("a"),
-            new_public_extern_entry(vec!["b", "c"])
-        ),
+        (String::from("d"), new_public_extern_entry(vec!["e", "f"])),
+        (String::from("a"), new_public_extern_entry(vec!["b", "c"])),
     ]));
 
     v3.externs = Externs::new(mk_map(vec![
-        (
-            String::from("a"),
-            new_public_extern_entry(vec!["b", "c"])
-        ),
-        (
-            String::from("d"),
-            new_public_extern_entry(vec!["f", "e"])
-        ),
+        (String::from("a"), new_public_extern_entry(vec!["b", "c"])),
+        (String::from("d"), new_public_extern_entry(vec!["f", "e"])),
     ]));
 
     assert_eq!(v1.dep_tracking_hash(), v2.dep_tracking_hash());
@@ -208,24 +186,24 @@ fn test_lints_tracking_hash_different_values() {
     let mut v3 = Options::default();
 
     v1.lint_opts = vec![
-        (String::from("a"), lint::Allow),
-        (String::from("b"), lint::Warn),
-        (String::from("c"), lint::Deny),
-        (String::from("d"), lint::Forbid),
+        (String::from("a"), Level::Allow),
+        (String::from("b"), Level::Warn),
+        (String::from("c"), Level::Deny),
+        (String::from("d"), Level::Forbid),
     ];
 
     v2.lint_opts = vec![
-        (String::from("a"), lint::Allow),
-        (String::from("b"), lint::Warn),
-        (String::from("X"), lint::Deny),
-        (String::from("d"), lint::Forbid),
+        (String::from("a"), Level::Allow),
+        (String::from("b"), Level::Warn),
+        (String::from("X"), Level::Deny),
+        (String::from("d"), Level::Forbid),
     ];
 
     v3.lint_opts = vec![
-        (String::from("a"), lint::Allow),
-        (String::from("b"), lint::Warn),
-        (String::from("c"), lint::Forbid),
-        (String::from("d"), lint::Deny),
+        (String::from("a"), Level::Allow),
+        (String::from("b"), Level::Warn),
+        (String::from("c"), Level::Forbid),
+        (String::from("d"), Level::Deny),
     ];
 
     assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
@@ -244,17 +222,17 @@ fn test_lints_tracking_hash_different_construction_order() {
     let mut v2 = Options::default();
 
     v1.lint_opts = vec![
-        (String::from("a"), lint::Allow),
-        (String::from("b"), lint::Warn),
-        (String::from("c"), lint::Deny),
-        (String::from("d"), lint::Forbid),
+        (String::from("a"), Level::Allow),
+        (String::from("b"), Level::Warn),
+        (String::from("c"), Level::Deny),
+        (String::from("d"), Level::Forbid),
     ];
 
     v2.lint_opts = vec![
-        (String::from("a"), lint::Allow),
-        (String::from("c"), lint::Deny),
-        (String::from("b"), lint::Warn),
-        (String::from("d"), lint::Forbid),
+        (String::from("a"), Level::Allow),
+        (String::from("c"), Level::Deny),
+        (String::from("b"), Level::Warn),
+        (String::from("d"), Level::Forbid),
     ];
 
     assert_eq!(v1.dep_tracking_hash(), v2.dep_tracking_hash());
@@ -277,49 +255,29 @@ fn test_search_paths_tracking_hash_different_order() {
     };
 
     // Reference
-    v1.search_paths
-        .push(SearchPath::from_cli_opt("native=abc", JSON));
-    v1.search_paths
-        .push(SearchPath::from_cli_opt("crate=def", JSON));
-    v1.search_paths
-        .push(SearchPath::from_cli_opt("dependency=ghi", JSON));
-    v1.search_paths
-        .push(SearchPath::from_cli_opt("framework=jkl", JSON));
-    v1.search_paths
-        .push(SearchPath::from_cli_opt("all=mno", JSON));
-
-    v2.search_paths
-        .push(SearchPath::from_cli_opt("native=abc", JSON));
-    v2.search_paths
-        .push(SearchPath::from_cli_opt("dependency=ghi", JSON));
-    v2.search_paths
-        .push(SearchPath::from_cli_opt("crate=def", JSON));
-    v2.search_paths
-        .push(SearchPath::from_cli_opt("framework=jkl", JSON));
-    v2.search_paths
-        .push(SearchPath::from_cli_opt("all=mno", JSON));
-
-    v3.search_paths
-        .push(SearchPath::from_cli_opt("crate=def", JSON));
-    v3.search_paths
-        .push(SearchPath::from_cli_opt("framework=jkl", JSON));
-    v3.search_paths
-        .push(SearchPath::from_cli_opt("native=abc", JSON));
-    v3.search_paths
-        .push(SearchPath::from_cli_opt("dependency=ghi", JSON));
-    v3.search_paths
-        .push(SearchPath::from_cli_opt("all=mno", JSON));
-
-    v4.search_paths
-        .push(SearchPath::from_cli_opt("all=mno", JSON));
-    v4.search_paths
-        .push(SearchPath::from_cli_opt("native=abc", JSON));
-    v4.search_paths
-        .push(SearchPath::from_cli_opt("crate=def", JSON));
-    v4.search_paths
-        .push(SearchPath::from_cli_opt("dependency=ghi", JSON));
-    v4.search_paths
-        .push(SearchPath::from_cli_opt("framework=jkl", JSON));
+    v1.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
+    v1.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
+    v1.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
+    v1.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
+    v1.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
+
+    v2.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
+    v2.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
+    v2.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
+    v2.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
+    v2.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
+
+    v3.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
+    v3.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
+    v3.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
+    v3.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
+    v3.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
+
+    v4.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
+    v4.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
+    v4.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
+    v4.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
+    v4.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
 
     assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash());
     assert!(v1.dep_tracking_hash() == v3.dep_tracking_hash());
@@ -363,11 +321,7 @@ fn test_native_libs_tracking_hash_different_values() {
     // Change new-name
     v4.libs = vec![
         (String::from("a"), None, Some(cstore::NativeStatic)),
-        (
-            String::from("b"),
-            Some(String::from("X")),
-            Some(cstore::NativeFramework),
-        ),
+        (String::from("b"), Some(String::from("X")), Some(cstore::NativeFramework)),
         (String::from("c"), None, Some(cstore::NativeUnknown)),
     ];
 
@@ -647,10 +601,6 @@ fn test_debugging_options_tracking_hash() {
     opts.debugging_opts.report_delayed_bugs = true;
     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
 
-    opts = reference.clone();
-    opts.debugging_opts.continue_parse_after_error = true;
-    assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
-
     opts = reference.clone();
     opts.debugging_opts.force_overflow_checks = Some(true);
     assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
@@ -686,9 +636,7 @@ fn test_edition_parsing() {
     let options = Options::default();
     assert!(options.edition == DEFAULT_EDITION);
 
-    let matches = optgroups()
-        .parse(&["--edition=2018".to_string()])
-        .unwrap();
+    let matches = optgroups().parse(&["--edition=2018".to_string()]).unwrap();
     let (sessopts, _) = build_session_options_and_crate_config(matches);
     assert!(sessopts.edition == Edition::Edition2018)
 }