Skip to content

Commit af4bdbf

Browse files
committed
rewrite translation to rmake
1 parent 91661a5 commit af4bdbf

File tree

4 files changed

+124
-79
lines changed

4 files changed

+124
-79
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ run-make/macos-deployment-target/Makefile
1010
run-make/reproducible-build/Makefile
1111
run-make/split-debuginfo/Makefile
1212
run-make/symbol-mangling-hashed/Makefile
13-
run-make/translation/Makefile
1413
run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile

tests/run-make/libs-through-symlinks/rmake.rs

+3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
// checks that compilation succeeds through use of the symlink.
55
// See https://github.com/rust-lang/rust/issues/13890
66

7+
//@ needs-symlink
8+
79
use run_make_support::{cwd, path, rfs, rust_lib_name, rustc};
810

911
fn main() {
1012
rfs::create_dir("outdir");
1113
rustc().input("foo.rs").output(path("outdir").join(rust_lib_name("foo"))).run();
1214
rfs::create_symlink(path("outdir").join(rust_lib_name("foo")), rust_lib_name("foo"));
15+
// RUSTC_LOG is used for debugging and is not crucial to the test.
1316
rustc().env("RUSTC_LOG", "rustc_metadata::loader").input("bar.rs").run();
1417
}

tests/run-make/translation/Makefile

-78
This file was deleted.

tests/run-make/translation/rmake.rs

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Various tests on Fluent bundles, useful to change the compiler's language
2+
// to the one requested by the user. Check each comment header to learn the purpose
3+
// of each test case.
4+
// See https://github.com/rust-lang/rust/pull/95512
5+
6+
//@ needs-symlink
7+
8+
use run_make_support::{path, rfs, rustc};
9+
10+
fn main() {
11+
builtin_fallback_bundle();
12+
custom_bundle();
13+
interpolated_variable_missing();
14+
desired_message_missing();
15+
custom_locale_from_sysroot();
16+
no_locale_in_sysroot();
17+
locale_in_sysroot_is_invalid();
18+
}
19+
20+
fn builtin_fallback_bundle() {
21+
// Check that the test works normally, using the built-in fallback bundle.
22+
rustc().input("test.rs").run_fail().assert_stderr_contains("struct literal body without path");
23+
}
24+
25+
fn custom_bundle() {
26+
// Check that a primary bundle can be loaded and will be preferentially used
27+
// where possible.
28+
rustc()
29+
.env("RUSTC_TRANSLATION_NO_DEBUG_ASSERT", "1")
30+
.arg("-Ztranslate-additional-ftl=working.ftl")
31+
.input("test.rs")
32+
.run_fail()
33+
.assert_stderr_contains("this is a test message");
34+
}
35+
36+
fn interpolated_variable_missing() {
37+
// Check that a primary bundle with a broken message (e.g. a interpolated
38+
// variable is missing) will use the fallback bundle.
39+
rustc()
40+
.env("RUSTC_TRANSLATION_NO_DEBUG_ASSERT", "1")
41+
.arg("-Ztranslate-additional-ftl=missing.ftl")
42+
.input("test.rs")
43+
.run_fail()
44+
.assert_stderr_contains("struct literal body without path");
45+
}
46+
47+
fn desired_message_missing() {
48+
// Check that a primary bundle without the desired message will use the fallback
49+
// bundle.
50+
rustc()
51+
.env("RUSTC_TRANSLATION_NO_DEBUG_ASSERT", "1")
52+
.arg("-Ztranslate-additional-ftl=broken.ftl")
53+
.input("test.rs")
54+
.run_fail()
55+
.assert_stderr_contains("struct literal body without path");
56+
}
57+
58+
fn custom_locale_from_sysroot() {
59+
// Check that a locale can be loaded from the sysroot given a language
60+
// identifier by making a local copy of the sysroot and adding the custom locale
61+
// to it.
62+
let sysroot =
63+
rustc().env("RUSTC_TRANSLATION_NO_DEBUG_ASSERT", "1").print("sysroot").run().stdout_utf8();
64+
let sysroot = sysroot.trim();
65+
rfs::create_dir("fakeroot");
66+
symlink_all_entries(&sysroot, "fakeroot");
67+
rfs::remove_file("fakeroot/lib");
68+
rfs::create_dir("fakeroot/lib");
69+
symlink_all_entries(path(&sysroot).join("lib"), "fakeroot/lib");
70+
rfs::remove_file("fakeroot/lib/rustlib");
71+
rfs::create_dir("fakeroot/lib/rustlib");
72+
symlink_all_entries(path(&sysroot).join("lib/rustlib"), "fakeroot/lib/rustlib");
73+
rfs::remove_file("fakeroot/lib/rustlib/src");
74+
rfs::create_dir("fakeroot/lib/rustlib/src");
75+
symlink_all_entries(path(&sysroot).join("lib/rustlib/src"), "fakeroot/lib/rustlib/src");
76+
// When download-rustc is enabled, `sysroot` will have a share directory. Delete the link to it.
77+
if path("fakeroot/share").exists() {
78+
rfs::remove_file("fakeroot/share");
79+
}
80+
rfs::create_dir_all("fakeroot/share/locale/zh-CN");
81+
rfs::create_symlink("working.ftl", "fakeroot/share/locale/zh-CN/basic-translation.ftl");
82+
rustc()
83+
.env("RUSTC_TRANSLATION_NO_DEBUG_ASSERT", "1")
84+
.arg("-Ztranslate-lang=zh-CN")
85+
.input("test.rs")
86+
.sysroot("fakeroot")
87+
.run_fail()
88+
.assert_stderr_contains("this is a test message");
89+
}
90+
91+
fn no_locale_in_sysroot() {
92+
// Check that the compiler errors out when the sysroot requested cannot be
93+
// found. This test might start failing if there actually exists a Klingon
94+
// translation of rustc's error messages.
95+
rustc()
96+
.env("RUSTC_TRANSLATION_NO_DEBUG_ASSERT", "1")
97+
.arg("-Ztranslate-lang=tlh")
98+
// .input("test.rs")
99+
.run_fail()
100+
.assert_stderr_contains("missing locale directory");
101+
}
102+
103+
fn locale_in_sysroot_is_invalid() {
104+
// Check that the compiler errors out when the directory for the locale in the
105+
// sysroot is actually a file.
106+
rfs::remove_dir_all("fakeroot/share/locale/zh-CN");
107+
rfs::create_file("fakeroot/share/locale/zh-CN");
108+
rustc()
109+
.env("RUSTC_TRANSLATION_NO_DEBUG_ASSERT", "1")
110+
.arg("-Ztranslate-lang=zh-CN")
111+
.input("test.rs")
112+
.sysroot("fakeroot")
113+
.run_fail()
114+
.assert_stderr_contains("`$sysroot/share/locales/$locale` is not a directory");
115+
}
116+
117+
fn symlink_all_entries<P: AsRef<std::path::Path>>(dir: P, fakepath: &str) {
118+
for found_path in rfs::shallow_find_dir_entries(dir) {
119+
rfs::create_symlink(&found_path, path(fakepath).join(found_path.file_name().unwrap()));
120+
}
121+
}

0 commit comments

Comments
 (0)