From f96541e9a9be7a5b28191be9229d72c8bf47baa7 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Sat, 7 Oct 2023 08:17:20 +0200 Subject: [PATCH 1/3] tests/run-make: Remove wrong blessing advice run-make tests are not special but can be blessed like other tests, like this: ./x.py test --bless tests/run-make/unknown-mod-stdin --- tests/run-make/unknown-mod-stdin/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/run-make/unknown-mod-stdin/Makefile b/tests/run-make/unknown-mod-stdin/Makefile index c1931765382..bc468387a2c 100644 --- a/tests/run-make/unknown-mod-stdin/Makefile +++ b/tests/run-make/unknown-mod-stdin/Makefile @@ -5,7 +5,6 @@ include ../tools.mk all: echo 'mod unknown;' | $(RUSTC) --crate-type rlib - >$(TMPDIR)/unknown-mod.stdout 2>$(TMPDIR)/unknown-mod.stderr || echo "failed successfully" -# Bless like this: RUSTC_BLESS_TEST=1 ./x.py test tests/run-make/unknown-mod-stdin ifdef RUSTC_BLESS_TEST cp "$(TMPDIR)"/unknown-mod.stdout unknown-mod.stdout cp "$(TMPDIR)"/unknown-mod.stderr unknown-mod.stderr From 88966c477386db4ccabd18df3de52647d3540f96 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Sat, 7 Oct 2023 08:14:38 +0200 Subject: [PATCH 2/3] tests/run-make: Move RUSTC_TEST_OP to tools.mk To reduce duplication. A follow-up commit will begin using it in even more places. --- tests/run-make/metadata-dep-info/Makefile | 6 ------ tests/run-make/silly-file-names/Makefile | 6 ------ tests/run-make/tools.mk | 22 ++++++++++++++++++++++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/tests/run-make/metadata-dep-info/Makefile b/tests/run-make/metadata-dep-info/Makefile index f9043f21433..d48cbe0f295 100644 --- a/tests/run-make/metadata-dep-info/Makefile +++ b/tests/run-make/metadata-dep-info/Makefile @@ -1,11 +1,5 @@ include ../tools.mk -ifdef RUSTC_BLESS_TEST - RUSTC_TEST_OP = cp -else - RUSTC_TEST_OP = $(DIFF) -endif - all: $(RUSTC) --emit=metadata,dep-info --crate-type lib dash-separated.rs -C extra-filename=_something-extra # Strip TMPDIR since it is a machine specific absolute path diff --git a/tests/run-make/silly-file-names/Makefile b/tests/run-make/silly-file-names/Makefile index a09bdb1c532..e51266c0880 100644 --- a/tests/run-make/silly-file-names/Makefile +++ b/tests/run-make/silly-file-names/Makefile @@ -3,12 +3,6 @@ include ../tools.mk -ifdef RUSTC_BLESS_TEST - RUSTC_TEST_OP = cp -else - RUSTC_TEST_OP = $(DIFF) -endif - all: echo '"comes from a file with a name that begins with <"' > "$(TMPDIR)/"' > "$(TMPDIR)/trailing-gt>" diff --git a/tests/run-make/tools.mk b/tests/run-make/tools.mk index 6121a91e920..1d4e9111389 100644 --- a/tests/run-make/tools.mk +++ b/tests/run-make/tools.mk @@ -21,6 +21,28 @@ CGREP := "$(S)/src/etc/cat-and-grep.sh" # diff with common flags for multi-platform diffs against text output DIFF := diff -u --strip-trailing-cr +# With RUSTC_TEST_OP you can elegantly support blessing of run-make tests. Do +# like this in a Makefile recipe: +# +# "$(TMPDIR)"/your-test > "$(TMPDIR)"/your-test.run.stdout +# $(RUSTC_TEST_OP) "$(TMPDIR)"/your-test.run.stdout your-test.run.stdout +# +# When running the test normally with +# +# ./x test tests/run-make/your-test +# +# the actual output will be diffed against the expected output. When running in +# bless-mode with +# +# ./x test --bless tests/run-make/your-test +# +# the actual output will be blessed as the expected output. +ifdef RUSTC_BLESS_TEST + RUSTC_TEST_OP = cp +else + RUSTC_TEST_OP = $(DIFF) +endif + # Some of the Rust CI platforms use `/bin/dash` to run `shell` script in # Makefiles. Other platforms, including many developer platforms, default to # `/bin/bash`. (In many cases, `make` is actually using `/bin/sh`, but `sh` From d9a7afec8b079b16b6b6f2e23e1f375bc37b4abf Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Sat, 7 Oct 2023 08:23:10 +0200 Subject: [PATCH 3/3] tests/run-make: Use RUSTC_TEST_OP in more places --- tests/run-make/const_fn_mir/Makefile | 7 +------ tests/run-make/overwrite-input/Makefile | 10 ++-------- .../raw-dylib-alt-calling-convention/Makefile | 12 ++---------- tests/run-make/raw-dylib-import-name-type/Makefile | 7 +------ tests/run-make/raw-dylib-inline-cross-dylib/Makefile | 7 +------ tests/run-make/raw-dylib-link-ordinal/Makefile | 7 +------ tests/run-make/raw-dylib-stdcall-ordinal/Makefile | 7 +------ tests/run-make/unknown-mod-stdin/Makefile | 10 ++-------- 8 files changed, 11 insertions(+), 56 deletions(-) diff --git a/tests/run-make/const_fn_mir/Makefile b/tests/run-make/const_fn_mir/Makefile index 6d72c122723..3399446130d 100644 --- a/tests/run-make/const_fn_mir/Makefile +++ b/tests/run-make/const_fn_mir/Makefile @@ -3,9 +3,4 @@ include ../tools.mk all: $(RUSTC) main.rs --emit=mir -o "$(TMPDIR)"/dump.mir - -ifdef RUSTC_BLESS_TEST - cp "$(TMPDIR)"/dump.mir dump.mir -else - $(DIFF) dump.mir "$(TMPDIR)"/dump.mir -endif + $(RUSTC_TEST_OP) "$(TMPDIR)"/dump.mir dump.mir diff --git a/tests/run-make/overwrite-input/Makefile b/tests/run-make/overwrite-input/Makefile index c62b5aab190..721bf62b26b 100644 --- a/tests/run-make/overwrite-input/Makefile +++ b/tests/run-make/overwrite-input/Makefile @@ -3,11 +3,5 @@ include ../tools.mk all: $(RUSTC) main.rs -o main.rs 2> $(TMPDIR)/file.stderr || echo "failed successfully" $(RUSTC) main.rs -o . 2> $(TMPDIR)/folder.stderr || echo "failed successfully" - -ifdef RUSTC_BLESS_TEST - cp "$(TMPDIR)"/file.stderr file.stderr - cp "$(TMPDIR)"/folder.stderr folder.stderr -else - $(DIFF) file.stderr "$(TMPDIR)"/file.stderr - $(DIFF) folder.stderr "$(TMPDIR)"/folder.stderr -endif + $(RUSTC_TEST_OP) "$(TMPDIR)"/file.stderr file.stderr + $(RUSTC_TEST_OP) "$(TMPDIR)"/folder.stderr folder.stderr diff --git a/tests/run-make/raw-dylib-alt-calling-convention/Makefile b/tests/run-make/raw-dylib-alt-calling-convention/Makefile index 1744c431f9c..14d23a5d201 100644 --- a/tests/run-make/raw-dylib-alt-calling-convention/Makefile +++ b/tests/run-make/raw-dylib-alt-calling-convention/Makefile @@ -16,17 +16,9 @@ else endif "$(TMPDIR)"/driver > "$(TMPDIR)"/output.txt -ifdef RUSTC_BLESS_TEST - cp "$(TMPDIR)"/output.txt output.txt -else - $(DIFF) output.txt "$(TMPDIR)"/output.txt -endif + $(RUSTC_TEST_OP) "$(TMPDIR)"/output.txt output.txt ifdef IS_MSVC "$(TMPDIR)"/driver true > "$(TMPDIR)"/output.msvc.txt -ifdef RUSTC_BLESS_TEST - cp "$(TMPDIR)"/output.msvc.txt output.msvc.txt -else - $(DIFF) output.msvc.txt "$(TMPDIR)"/output.msvc.txt -endif + $(RUSTC_TEST_OP) "$(TMPDIR)"/output.msvc.txt output.msvc.txt endif diff --git a/tests/run-make/raw-dylib-import-name-type/Makefile b/tests/run-make/raw-dylib-import-name-type/Makefile index 67152329807..901d3e861c2 100644 --- a/tests/run-make/raw-dylib-import-name-type/Makefile +++ b/tests/run-make/raw-dylib-import-name-type/Makefile @@ -14,9 +14,4 @@ else $(CC) "$(TMPDIR)"/extern.obj extern.gnu.def --no-leading-underscore -shared -o "$(TMPDIR)"/extern.dll endif "$(TMPDIR)"/driver > "$(TMPDIR)"/output.txt - -ifdef RUSTC_BLESS_TEST - cp "$(TMPDIR)"/output.txt output.txt -else - $(DIFF) output.txt "$(TMPDIR)"/output.txt -endif + $(RUSTC_TEST_OP) "$(TMPDIR)"/output.txt output.txt diff --git a/tests/run-make/raw-dylib-inline-cross-dylib/Makefile b/tests/run-make/raw-dylib-inline-cross-dylib/Makefile index 6d1d04bfd37..195b5fda56f 100644 --- a/tests/run-make/raw-dylib-inline-cross-dylib/Makefile +++ b/tests/run-make/raw-dylib-inline-cross-dylib/Makefile @@ -27,9 +27,4 @@ else $(CC) "$(TMPDIR)"/extern_2.obj -shared -o "$(TMPDIR)"/extern_2.dll endif $(call RUN,driver) > "$(TMPDIR)"/output.txt - -ifdef RUSTC_BLESS_TEST - cp "$(TMPDIR)"/output.txt output.txt -else - $(DIFF) output.txt "$(TMPDIR)"/output.txt -endif + $(RUSTC_TEST_OP) "$(TMPDIR)"/output.txt output.txt diff --git a/tests/run-make/raw-dylib-link-ordinal/Makefile b/tests/run-make/raw-dylib-link-ordinal/Makefile index 374a0b59de3..49e959cdb5b 100644 --- a/tests/run-make/raw-dylib-link-ordinal/Makefile +++ b/tests/run-make/raw-dylib-link-ordinal/Makefile @@ -14,9 +14,4 @@ else $(CC) "$(TMPDIR)"/exporter.obj exporter.def -shared -o "$(TMPDIR)"/exporter.dll endif "$(TMPDIR)"/driver > "$(TMPDIR)"/output.txt - -ifdef RUSTC_BLESS_TEST - cp "$(TMPDIR)"/output.txt output.txt -else - $(DIFF) output.txt "$(TMPDIR)"/output.txt -endif + $(RUSTC_TEST_OP) "$(TMPDIR)"/output.txt output.txt diff --git a/tests/run-make/raw-dylib-stdcall-ordinal/Makefile b/tests/run-make/raw-dylib-stdcall-ordinal/Makefile index 178c15ab3de..70e4de62c1a 100644 --- a/tests/run-make/raw-dylib-stdcall-ordinal/Makefile +++ b/tests/run-make/raw-dylib-stdcall-ordinal/Makefile @@ -15,9 +15,4 @@ else $(CC) "$(TMPDIR)"/exporter.obj exporter-gnu.def -shared -o "$(TMPDIR)"/exporter.dll endif "$(TMPDIR)"/driver > "$(TMPDIR)"/actual_output.txt - -ifdef RUSTC_BLESS_TEST - cp "$(TMPDIR)"/actual_output.txt expected_output.txt -else - $(DIFF) expected_output.txt "$(TMPDIR)"/actual_output.txt -endif + $(RUSTC_TEST_OP) "$(TMPDIR)"/actual_output.txt expected_output.txt diff --git a/tests/run-make/unknown-mod-stdin/Makefile b/tests/run-make/unknown-mod-stdin/Makefile index bc468387a2c..313b0ba837e 100644 --- a/tests/run-make/unknown-mod-stdin/Makefile +++ b/tests/run-make/unknown-mod-stdin/Makefile @@ -4,11 +4,5 @@ include ../tools.mk all: echo 'mod unknown;' | $(RUSTC) --crate-type rlib - >$(TMPDIR)/unknown-mod.stdout 2>$(TMPDIR)/unknown-mod.stderr || echo "failed successfully" - -ifdef RUSTC_BLESS_TEST - cp "$(TMPDIR)"/unknown-mod.stdout unknown-mod.stdout - cp "$(TMPDIR)"/unknown-mod.stderr unknown-mod.stderr -else - $(DIFF) unknown-mod.stdout "$(TMPDIR)"/unknown-mod.stdout - $(DIFF) unknown-mod.stderr "$(TMPDIR)"/unknown-mod.stderr -endif + $(RUSTC_TEST_OP) "$(TMPDIR)"/unknown-mod.stdout unknown-mod.stdout + $(RUSTC_TEST_OP) "$(TMPDIR)"/unknown-mod.stderr unknown-mod.stderr