summaryrefslogtreecommitdiffstats
path: root/src/test/run-make/translation
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/run-make/translation
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/run-make/translation')
-rw-r--r--src/test/run-make/translation/Makefile59
-rw-r--r--src/test/run-make/translation/basic-translation.ftl2
-rw-r--r--src/test/run-make/translation/basic-translation.rs18
3 files changed, 79 insertions, 0 deletions
diff --git a/src/test/run-make/translation/Makefile b/src/test/run-make/translation/Makefile
new file mode 100644
index 000000000..bfff75e7a
--- /dev/null
+++ b/src/test/run-make/translation/Makefile
@@ -0,0 +1,59 @@
+include ../../run-make-fulldeps/tools.mk
+
+# This test uses `ln -s` rather than copying to save testing time, but its
+# usage doesn't work on Windows.
+# ignore-windows
+
+SYSROOT:=$(shell $(RUSTC) --print sysroot)
+FAKEROOT=$(TMPDIR)/fakeroot
+
+all: normal custom sysroot
+
+normal: basic-translation.rs
+ $(RUSTC) $< 2>&1 | grep "struct literal body without path"
+
+custom: basic-translation.rs basic-translation.ftl
+ $(RUSTC) $< -Ztranslate-additional-ftl=$(CURDIR)/basic-translation.ftl 2>&1 | grep "this is a test message"
+
+# Check that a locale can be loaded from the sysroot given a language
+# identifier by making a local copy of the sysroot and adding the custom locale
+# to it.
+sysroot: basic-translation.rs basic-translation.ftl
+ mkdir $(FAKEROOT)
+ ln -s $(SYSROOT)/* $(FAKEROOT)
+ rm -f $(FAKEROOT)/lib
+ mkdir $(FAKEROOT)/lib
+ ln -s $(SYSROOT)/lib/* $(FAKEROOT)/lib
+ rm -f $(FAKEROOT)/lib/rustlib
+ mkdir $(FAKEROOT)/lib/rustlib
+ ln -s $(SYSROOT)/lib/rustlib/* $(FAKEROOT)/lib/rustlib
+ rm -f $(FAKEROOT)/lib/rustlib/src
+ mkdir $(FAKEROOT)/lib/rustlib/src
+ ln -s $(SYSROOT)/lib/rustlib/src/* $(FAKEROOT)/lib/rustlib/src
+ mkdir -p $(FAKEROOT)/share/locale/zh-CN/
+ ln -s $(CURDIR)/basic-translation.ftl $(FAKEROOT)/share/locale/zh-CN/basic-translation.ftl
+ $(RUSTC) $< --sysroot $(FAKEROOT) -Ztranslate-lang=zh-CN 2>&1 | grep "this is a test message"
+
+# Check that the compiler errors out when the sysroot requested cannot be
+# found. This test might start failing if there actually exists a Klingon
+# translation of rustc's error messages.
+sysroot-missing:
+ $(RUSTC) $< -Ztranslate-lang=tlh 2>&1 || grep "missing locale directory"
+
+# Check that the compiler errors out when the sysroot requested cannot be
+# found. This test might start failing if there actually exists a Klingon
+# translation of rustc's error messages.
+sysroot-invalid: basic-translation.rs basic-translation.ftl
+ mkdir $(FAKEROOT)
+ ln -s $(SYSROOT)/* $(FAKEROOT)
+ rm -f $(FAKEROOT)/lib
+ mkdir $(FAKEROOT)/lib
+ ln -s $(SYSROOT)/lib/* $(FAKEROOT)/lib
+ rm -f $(FAKEROOT)/lib/rustlib
+ mkdir $(FAKEROOT)/lib/rustlib
+ ln -s $(SYSROOT)/lib/rustlib/* $(FAKEROOT)/lib/rustlib
+ rm -f $(FAKEROOT)/lib/rustlib/src
+ mkdir $(FAKEROOT)/lib/rustlib/src
+ ln -s $(SYSROOT)/lib/rustlib/src/* $(FAKEROOT)/lib/rustlib/src
+ touch $(FAKEROOT)/share/locale/zh-CN/
+ $(RUSTC) $< --sysroot $(FAKEROOT) -Ztranslate-lang=zh-CN 2>&1 || grep "`\$sysroot/share/locales/\$locale` is not a directory"
diff --git a/src/test/run-make/translation/basic-translation.ftl b/src/test/run-make/translation/basic-translation.ftl
new file mode 100644
index 000000000..4681b879c
--- /dev/null
+++ b/src/test/run-make/translation/basic-translation.ftl
@@ -0,0 +1,2 @@
+parser-struct-literal-body-without-path = this is a test message
+ .suggestion = this is a test suggestion
diff --git a/src/test/run-make/translation/basic-translation.rs b/src/test/run-make/translation/basic-translation.rs
new file mode 100644
index 000000000..b8f5bff31
--- /dev/null
+++ b/src/test/run-make/translation/basic-translation.rs
@@ -0,0 +1,18 @@
+// Exact error being tested isn't relevant, it just needs to be known that it uses Fluent-backed
+// diagnostics.
+
+struct Foo {
+ val: (),
+}
+
+fn foo() -> Foo {
+ val: (),
+}
+
+fn main() {
+ let x = foo();
+ x.val == 42;
+ let x = {
+ val: (),
+ };
+}