From ae6a9d4ba484f8f5bb9cbebf6da6d179bef519e1 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 11 Apr 2018 17:18:22 +0200 Subject: Change output of `compiletest` to include the compare-mode when present. E.g. when running with `--compare-mode=nll`, then each test line will look like e.g.: ``` test [ui (nll)] ui/issue-10969.rs ... ok ``` --- src/tools/compiletest/src/common.rs | 2 +- src/tools/compiletest/src/main.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/tools') diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 41fc67a66f4..365b47447f2 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -101,7 +101,7 @@ pub enum CompareMode { } impl CompareMode { - fn to_str(&self) -> &'static str { + pub(crate) fn to_str(&self) -> &'static str { match *self { CompareMode::Nll => "nll" } diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index ae4f4aa4046..f61ab7bae45 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -728,7 +728,11 @@ pub fn make_test_name(config: &Config, testpaths: &TestPaths) -> test::TestName let path = PathBuf::from(config.src_base.file_name().unwrap()) .join(&testpaths.relative_dir) .join(&testpaths.file.file_name().unwrap()); - test::DynTestName(format!("[{}] {}", config.mode, path.display())) + let mode_suffix = match config.compare_mode { + Some(ref mode) => format!(" ({})", mode.to_str()), + None => format!(""), + }; + test::DynTestName(format!("[{}{}] {}", config.mode, mode_suffix, path.display())) } pub fn make_test_closure(config: &Config, testpaths: &TestPaths) -> test::TestFn { -- cgit 1.4.1-3-g733a5 From 02a7809f1c10ceab7ffe4652f1211cdc3c6fd4c1 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 11 Apr 2018 17:28:14 +0200 Subject: Generate separate stamp files for `--compare-mode=nll`, and also use them. :) --- src/tools/compiletest/src/main.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/tools') diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index f61ab7bae45..37f7af0abe8 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -626,7 +626,7 @@ pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn // Debugging emscripten code doesn't make sense today let ignore = early_props.ignore - || (!up_to_date(config, testpaths, &early_props) && config.compare_mode.is_none()) + || !up_to_date(config, testpaths, &early_props) || (config.mode == DebugInfoGdb || config.mode == DebugInfoLldb) && config.target.contains("emscripten"); @@ -642,10 +642,15 @@ pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn } fn stamp(config: &Config, testpaths: &TestPaths) -> PathBuf { + let mode_suffix = match config.compare_mode { + Some(ref mode) => format!("-{}", mode.to_str()), + None => format!(""), + }; let stamp_name = format!( - "{}-{}.stamp", + "{}-{}{}.stamp", testpaths.file.file_name().unwrap().to_str().unwrap(), - config.stage_id + config.stage_id, + mode_suffix ); config .build_base -- cgit 1.4.1-3-g733a5 From 33bcb4ed16b01abeaa762c99e452da82c9c6275f Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 18 Apr 2018 14:41:29 +0200 Subject: When running under compare-mode=nll, generate expected output to `foo.nll.stderr` This allows easy revision of the update-references.sh script (included here) so that it can update the expected output for nll rather than stderr. It also reminds the rustc developer via the filename that they are looking at output generated under comapre-mode=nll. One could argue that there is still a problem with the strategy encoded here: if we reach a scenario where a change to the compiler brings the output under AST and NLL modes back into sync, this code will continue to still generate output to distinct `foo.stderr` and `foo.nll.stderr` files, and will continue to copy those two files back to corresponding distinct files in the source tree, even if the *content* of the two files is now the same. * Arguably the "right thing" to do in that case is to remove the `foo.nll.stderr` file entirely. * However, I think the real answer is that we will probably want to double-check such cases by hand anyway. We should be regularly double-checking the diffs between `foo.stderr` and `foo.nll.stderr`, and if we see a zero-diff case, then we should evaluate whether that is correct, and if so, remove the file by hand.) * In any case, I think the default behavior encoded here (or at least *intended* to be encoded here) is superior to the alternative of *only* generating a `foo.nll.stderr` file if one already existed in the source tree at the time that `compiletest` was invoked (and otherwise unconditionally generating a `foo.stderr` file, as was the behavior prior to this commit), because that alternative is more likely to cause rustc developers to overwrite a `foo.stderr` file with the stderr output from a compare-mode=nll run, which will then break the *normal* `compiletest` run and probably be much more confusing for the average rustc developer. --- src/test/ui/update-references.sh | 6 ++++++ src/tools/compiletest/src/runtest.rs | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'src/tools') diff --git a/src/test/ui/update-references.sh b/src/test/ui/update-references.sh index c2c842fcc49..cfe9a43707c 100755 --- a/src/test/ui/update-references.sh +++ b/src/test/ui/update-references.sh @@ -33,6 +33,7 @@ shift while [[ "$1" != "" ]]; do STDERR_NAME="${1/%.rs/.stderr}" + STDERR_NLL_NAME="${1/%.rs/.nll.stderr}" STDOUT_NAME="${1/%.rs/.stdout}" shift if [ -f $BUILD_DIR/$STDOUT_NAME ] && \ @@ -45,4 +46,9 @@ while [[ "$1" != "" ]]; do echo updating $MYDIR/$STDERR_NAME cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME fi + if [ -f $BUILD_DIR/$STDERR_NLL_NAME ] && \ + ! (diff $BUILD_DIR/$STDERR_NLL_NAME $MYDIR/$STDERR_NLL_NAME >& /dev/null); then + echo updating $MYDIR/$STDERR_NLL_NAME + cp $BUILD_DIR/$STDERR_NLL_NAME $MYDIR/$STDERR_NLL_NAME + fi done diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index e79aefb7236..c16dbd0272a 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2811,7 +2811,7 @@ impl<'test> TestCx<'test> { normalized } - fn load_expected_output(&self, kind: &str) -> String { + fn expected_output_path(&self, kind: &str) -> PathBuf { let mut path = expected_output_path(&self.testpaths, self.revision, &self.config.compare_mode, @@ -2822,6 +2822,11 @@ impl<'test> TestCx<'test> { path = expected_output_path(&self.testpaths, self.revision, &None, kind); } + path + } + + fn load_expected_output(&self, kind: &str) -> String { + let path = self.expected_output_path(kind); if path.exists() { match self.load_expected_output_from_path(&path) { Ok(x) => x, @@ -2875,7 +2880,8 @@ impl<'test> TestCx<'test> { } } - let output_file = self.output_base_name().with_extension(kind); + let expected_output_path = self.expected_output_path(kind); + let output_file = self.output_base_name().with_file_name(&expected_output_path); match File::create(&output_file).and_then(|mut f| f.write_all(actual.as_bytes())) { Ok(()) => {} Err(e) => self.fatal(&format!( -- cgit 1.4.1-3-g733a5