about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorJane Losare-Lusby <jlusby@yaah.dev>2024-07-31 11:47:07 -0700
committerJane Losare-Lusby <jlusby@yaah.dev>2024-08-07 11:16:55 -0700
commit5212c759076c4b4ada74c86979bb298ec0a8a5fb (patch)
treef663f3c8e414eaf8b29cbe2daeb3a4b98e5b4c8c /tests
parent2b78d920964e1d70927bcd208529bda0e11120d0 (diff)
downloadrust-5212c759076c4b4ada74c86979bb298ec0a8a5fb.tar.gz
rust-5212c759076c4b4ada74c86979bb298ec0a8a5fb.zip
Add -Zerror-metrics=PATH to save diagnostic metadata to disk
Diffstat (limited to 'tests')
-rw-r--r--tests/run-make/dump-ice-to-disk/rmake.rs86
1 files changed, 71 insertions, 15 deletions
diff --git a/tests/run-make/dump-ice-to-disk/rmake.rs b/tests/run-make/dump-ice-to-disk/rmake.rs
index 2fb5c825064..a64103fa516 100644
--- a/tests/run-make/dump-ice-to-disk/rmake.rs
+++ b/tests/run-make/dump-ice-to-disk/rmake.rs
@@ -4,6 +4,10 @@
 // or full.
 // - Check that disabling ICE logging results in zero files created.
 // - Check that the ICE files contain some of the expected strings.
+// - exercise the -Zmetrics-dir nightly flag
+// - verify what happens when both the nightly flag and env variable are set
+// - test the RUST_BACKTRACE=0 behavior against the file creation
+
 // See https://github.com/rust-lang/rust/pull/108714
 
 use run_make_support::{cwd, has_extension, has_prefix, rfs, rustc, shallow_find_files};
@@ -11,8 +15,8 @@ use run_make_support::{cwd, has_extension, has_prefix, rfs, rustc, shallow_find_
 fn main() {
     rustc().input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail();
     let default = get_text_from_ice(".").lines().count();
-    clear_ice_files();
 
+    clear_ice_files();
     rustc().env("RUSTC_ICE", cwd()).input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail();
     let ice_text = get_text_from_ice(cwd());
     let default_set = ice_text.lines().count();
@@ -25,7 +29,28 @@ fn main() {
         ice_files.first().and_then(|f| f.file_name()).and_then(|n| n.to_str()).unwrap();
     // Ensure that the ICE dump path doesn't contain `:`, because they cause problems on Windows.
     assert!(!ice_file_name.contains(":"), "{ice_file_name}");
+    assert_eq!(default, default_set);
+    assert!(default > 0);
+    // Some of the expected strings in an ICE file should appear.
+    assert!(content.contains("thread 'rustc' panicked at"));
+    assert!(content.contains("stack backtrace:"));
+
+    test_backtrace_short(default);
+    test_backtrace_full(default);
+    test_backtrace_disabled(default);
+
+    clear_ice_files();
+    // The ICE dump is explicitly disabled. Therefore, this should produce no files.
+    rustc().env("RUSTC_ICE", "0").input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail();
+    let ice_files = shallow_find_files(cwd(), |path| {
+        has_prefix(path, "rustc-ice") && has_extension(path, "txt")
+    });
+    assert!(ice_files.is_empty()); // There should be 0 ICE files.
+
+    metrics_dir(default);
+}
 
+fn test_backtrace_short(baseline: usize) {
     clear_ice_files();
     rustc()
         .env("RUSTC_ICE", cwd())
@@ -34,6 +59,11 @@ fn main() {
         .arg("-Ztreat-err-as-bug=1")
         .run_fail();
     let short = get_text_from_ice(cwd()).lines().count();
+    // backtrace length in dump shouldn't be changed by RUST_BACKTRACE
+    assert_eq!(short, baseline);
+}
+
+fn test_backtrace_full(baseline: usize) {
     clear_ice_files();
     rustc()
         .env("RUSTC_ICE", cwd())
@@ -42,23 +72,49 @@ fn main() {
         .arg("-Ztreat-err-as-bug=1")
         .run_fail();
     let full = get_text_from_ice(cwd()).lines().count();
+    // backtrace length in dump shouldn't be changed by RUST_BACKTRACE
+    assert_eq!(full, baseline);
+}
+
+fn test_backtrace_disabled(baseline: usize) {
     clear_ice_files();
+    rustc()
+        .env("RUSTC_ICE", cwd())
+        .input("lib.rs")
+        .env("RUST_BACKTRACE", "0")
+        .arg("-Ztreat-err-as-bug=1")
+        .run_fail();
+    let disabled = get_text_from_ice(cwd()).lines().count();
+    // backtrace length in dump shouldn't be changed by RUST_BACKTRACE
+    assert_eq!(disabled, baseline);
+}
 
-    // The ICE dump is explicitly disabled. Therefore, this should produce no files.
-    rustc().env("RUSTC_ICE", "0").input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail();
-    let ice_files = shallow_find_files(cwd(), |path| {
-        has_prefix(path, "rustc-ice") && has_extension(path, "txt")
-    });
-    assert!(ice_files.is_empty()); // There should be 0 ICE files.
+fn metrics_dir(baseline: usize) {
+    test_flag_only(baseline);
+    test_flag_and_env(baseline);
+}
 
-    // The line count should not change.
-    assert_eq!(short, default_set);
-    assert_eq!(short, default);
-    assert_eq!(full, default_set);
-    assert!(default > 0);
-    // Some of the expected strings in an ICE file should appear.
-    assert!(content.contains("thread 'rustc' panicked at"));
-    assert!(content.contains("stack backtrace:"));
+fn test_flag_only(baseline: usize) {
+    clear_ice_files();
+    let metrics_arg = format!("-Zmetrics-dir={}", cwd().display());
+    rustc().input("lib.rs").arg("-Ztreat-err-as-bug=1").arg(metrics_arg).run_fail();
+    let output = get_text_from_ice(cwd()).lines().count();
+    assert_eq!(output, baseline);
+}
+
+fn test_flag_and_env(baseline: usize) {
+    clear_ice_files();
+    let metrics_arg = format!("-Zmetrics-dir={}", cwd().display());
+    let real_dir = cwd().join("actually_put_ice_here");
+    rfs::create_dir(real_dir.clone());
+    rustc()
+        .input("lib.rs")
+        .env("RUSTC_ICE", real_dir.clone())
+        .arg("-Ztreat-err-as-bug=1")
+        .arg(metrics_arg)
+        .run_fail();
+    let output = get_text_from_ice(real_dir).lines().count();
+    assert_eq!(output, baseline);
 }
 
 fn clear_ice_files() {