From 88966c477386db4ccabd18df3de52647d3540f96 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Sat, 7 Oct 2023 08:14:38 +0200 Subject: [PATCH] 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 f9043f214338..d48cbe0f2950 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 a09bdb1c5329..e51266c0880b 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 6121a91e9203..1d4e91113892 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`