Skip to content

Commit 33bcb4e

Browse files
committed
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.
1 parent 1a4326d commit 33bcb4e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/test/ui/update-references.sh

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ shift
3333

3434
while [[ "$1" != "" ]]; do
3535
STDERR_NAME="${1/%.rs/.stderr}"
36+
STDERR_NLL_NAME="${1/%.rs/.nll.stderr}"
3637
STDOUT_NAME="${1/%.rs/.stdout}"
3738
shift
3839
if [ -f $BUILD_DIR/$STDOUT_NAME ] && \
@@ -45,4 +46,9 @@ while [[ "$1" != "" ]]; do
4546
echo updating $MYDIR/$STDERR_NAME
4647
cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME
4748
fi
49+
if [ -f $BUILD_DIR/$STDERR_NLL_NAME ] && \
50+
! (diff $BUILD_DIR/$STDERR_NLL_NAME $MYDIR/$STDERR_NLL_NAME >& /dev/null); then
51+
echo updating $MYDIR/$STDERR_NLL_NAME
52+
cp $BUILD_DIR/$STDERR_NLL_NAME $MYDIR/$STDERR_NLL_NAME
53+
fi
4854
done

src/tools/compiletest/src/runtest.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -2811,7 +2811,7 @@ impl<'test> TestCx<'test> {
28112811
normalized
28122812
}
28132813

2814-
fn load_expected_output(&self, kind: &str) -> String {
2814+
fn expected_output_path(&self, kind: &str) -> PathBuf {
28152815
let mut path = expected_output_path(&self.testpaths,
28162816
self.revision,
28172817
&self.config.compare_mode,
@@ -2822,6 +2822,11 @@ impl<'test> TestCx<'test> {
28222822
path = expected_output_path(&self.testpaths, self.revision, &None, kind);
28232823
}
28242824

2825+
path
2826+
}
2827+
2828+
fn load_expected_output(&self, kind: &str) -> String {
2829+
let path = self.expected_output_path(kind);
28252830
if path.exists() {
28262831
match self.load_expected_output_from_path(&path) {
28272832
Ok(x) => x,
@@ -2875,7 +2880,8 @@ impl<'test> TestCx<'test> {
28752880
}
28762881
}
28772882

2878-
let output_file = self.output_base_name().with_extension(kind);
2883+
let expected_output_path = self.expected_output_path(kind);
2884+
let output_file = self.output_base_name().with_file_name(&expected_output_path);
28792885
match File::create(&output_file).and_then(|mut f| f.write_all(actual.as_bytes())) {
28802886
Ok(()) => {}
28812887
Err(e) => self.fatal(&format!(

0 commit comments

Comments
 (0)