Skip to content

Commit a8e3750

Browse files
committed
errors: fix translation's run-make test
`run-make/translation` had some targets that weren't listed in `all` and thus weren't being tested - the behaviour that should have been being tested was basically correct fortunately. Signed-off-by: David Wood <[email protected]>
1 parent d1fcf61 commit a8e3750

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

compiler/rustc_errors/src/translation.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{DiagnosticArg, DiagnosticMessage, FluentBundle};
44
use rustc_data_structures::sync::Lrc;
55
use rustc_error_messages::FluentArgs;
66
use std::borrow::Cow;
7+
use std::env;
78
use std::error::Report;
89

910
/// Convert diagnostic arguments (a rustc internal type that exists to implement
@@ -94,8 +95,16 @@ pub trait Translate {
9495
// The primary bundle was present and translation succeeded
9596
Some(Ok(t)) => t,
9697

97-
// Always yeet out for errors on debug
98-
Some(Err(primary)) if cfg!(debug_assertions) => do yeet primary,
98+
// Always yeet out for errors on debug (unless
99+
// `RUSTC_TRANSLATION_NO_DEBUG_ASSERT` is set in the environment - this allows
100+
// local runs of the test suites, of builds with debug assertions, to test the
101+
// behaviour in a normal build).
102+
Some(Err(primary))
103+
if cfg!(debug_assertions)
104+
&& env::var("RUSTC_TRANSLATION_NO_DEBUG_ASSERT").is_err() =>
105+
{
106+
do yeet primary
107+
}
99108

100109
// If `translate_with_bundle` returns `Err` with the primary bundle, this is likely
101110
// just that the primary bundle doesn't contain the message being translated or

tests/run-make/translation/Makefile

+11-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ include ../../run-make-fulldeps/tools.mk
66

77
SYSROOT:=$(shell $(RUSTC) --print sysroot)
88
FAKEROOT=$(TMPDIR)/fakeroot
9+
RUSTC_LOG:=rustc_error_messages
10+
export RUSTC_TRANSLATION_NO_DEBUG_ASSERT:=1
911

10-
all: normal custom sysroot
12+
all: normal custom missing broken sysroot sysroot-invalid sysroot-missing
1113

1214
# Check that the test works normally, using the built-in fallback bundle.
1315
normal: test.rs
@@ -32,6 +34,7 @@ broken: test.rs broken.ftl
3234
# identifier by making a local copy of the sysroot and adding the custom locale
3335
# to it.
3436
sysroot: test.rs working.ftl
37+
rm -rf $(FAKEROOT)
3538
mkdir $(FAKEROOT)
3639
ln -s $(SYSROOT)/* $(FAKEROOT)
3740
rm -f $(FAKEROOT)/lib
@@ -51,12 +54,12 @@ sysroot: test.rs working.ftl
5154
# found. This test might start failing if there actually exists a Klingon
5255
# translation of rustc's error messages.
5356
sysroot-missing:
54-
$(RUSTC) $< -Ztranslate-lang=tlh 2>&1 || grep "missing locale directory"
57+
$(RUSTC) $< -Ztranslate-lang=tlh 2>&1 | grep "missing locale directory"
5558

56-
# Check that the compiler errors out when the sysroot requested cannot be
57-
# found. This test might start failing if there actually exists a Klingon
58-
# translation of rustc's error messages.
59+
# Check that the compiler errors out when the directory for the locale in the
60+
# sysroot is actually a file.
5961
sysroot-invalid: test.rs working.ftl
62+
rm -rf $(FAKEROOT)
6063
mkdir $(FAKEROOT)
6164
ln -s $(SYSROOT)/* $(FAKEROOT)
6265
rm -f $(FAKEROOT)/lib
@@ -68,5 +71,6 @@ sysroot-invalid: test.rs working.ftl
6871
rm -f $(FAKEROOT)/lib/rustlib/src
6972
mkdir $(FAKEROOT)/lib/rustlib/src
7073
ln -s $(SYSROOT)/lib/rustlib/src/* $(FAKEROOT)/lib/rustlib/src
71-
touch $(FAKEROOT)/share/locale/zh-CN/
72-
$(RUSTC) $< --sysroot $(FAKEROOT) -Ztranslate-lang=zh-CN 2>&1 || grep "`\$sysroot/share/locales/\$locale` is not a directory"
74+
mkdir -p $(FAKEROOT)/share/locale
75+
touch $(FAKEROOT)/share/locale/zh-CN
76+
$(RUSTC) $< --sysroot $(FAKEROOT) -Ztranslate-lang=zh-CN 2>&1 | grep "`\$sysroot/share/locales/\$locale` is not a directory"

0 commit comments

Comments
 (0)