Skip to content

Commit ea3ebb5

Browse files
committed
rewrite translation to rmake
1 parent 5f1e861 commit ea3ebb5

File tree

3 files changed

+89
-79
lines changed

3 files changed

+89
-79
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ run-make/rlib-format-packed-bundled-libs/Makefile
2121
run-make/split-debuginfo/Makefile
2222
run-make/symbol-mangling-hashed/Makefile
2323
run-make/sysroot-crates-are-unstable/Makefile
24-
run-make/translation/Makefile
2524
run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile

tests/run-make/translation/Makefile

-78
This file was deleted.

tests/run-make/translation/rmake.rs

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
// Check that the test works normally, using the built-in fallback bundle.
12+
rustc().input("test.rs").run_fail().assert_stderr_contains("struct literal body without path");
13+
// Check that a primary bundle can be loaded and will be preferentially used
14+
// where possible.
15+
rustc()
16+
.arg("-Ztranslate-additional-ftl=working.ftl")
17+
.input("test.rs")
18+
.run_fail()
19+
.assert_stderr_contains("this is a test message");
20+
// Check that a primary bundle with a broken message (e.g. a interpolated
21+
// variable is missing) will use the fallback bundle.
22+
rustc()
23+
.arg("-Ztranslate-additional-ftl=missing.ftl")
24+
.input("test.rs")
25+
.run_fail()
26+
.assert_stderr_contains("struct literal body without path");
27+
// Check that a primary bundle without the desired message will use the fallback
28+
// bundle.
29+
rustc()
30+
.arg("-Ztranslate-additional-ftl=broken.ftl")
31+
.input("test.rs")
32+
.run_fail()
33+
.assert_stderr_contains("struct literal body without path");
34+
35+
// Check that a locale can be loaded from the sysroot given a language
36+
// identifier by making a local copy of the sysroot and adding the custom locale
37+
// to it.
38+
let sysroot = rustc().print("sysroot").run().stdout_utf8();
39+
let sysroot = sysroot.trim();
40+
rfs::create_dir("fakeroot");
41+
symlink_all_entries(&sysroot, "fakeroot");
42+
rfs::remove_file("fakeroot/lib");
43+
rfs::create_dir("fakeroot/lib");
44+
symlink_all_entries(path(&sysroot).join("lib"), "fakeroot/lib");
45+
rfs::remove_file("fakeroot/lib/rustlib");
46+
rfs::create_dir("fakeroot/lib/rustlib");
47+
symlink_all_entries(path(&sysroot).join("lib/rustlib"), "fakeroot/lib/rustlib");
48+
rfs::remove_file("fakeroot/lib/rustlib/src");
49+
rfs::create_dir("fakeroot/lib/rustlib/src");
50+
symlink_all_entries(path(&sysroot).join("lib/rustlib/src"), "fakeroot/lib/rustlib/src");
51+
// When download-rustc is enabled, `sysroot` will have a share directory. Delete the link to it.
52+
if path("fakeroot/share").exists() {
53+
rfs::remove_file("fakeroot/share");
54+
}
55+
rfs::create_dir_all("fakeroot/share/locale/zh-CN");
56+
rfs::create_symlink("working.ftl", "fakeroot/share/locale/zh-CN/basic-translation.ftl");
57+
rustc()
58+
.arg("-Ztranslate-lang=zh-CN")
59+
.input("test.rs")
60+
.sysroot("fakeroot")
61+
.run_fail()
62+
.assert_stderr_contains("this is a test message");
63+
64+
// Check that the compiler errors out when the sysroot requested cannot be
65+
// found. This test might start failing if there actually exists a Klingon
66+
// translation of rustc's error messages.
67+
rustc()
68+
.arg("-Ztranslate-lang=tlh")
69+
// .input("test.rs")
70+
.run_fail()
71+
.assert_stderr_contains("missing locale directory");
72+
73+
// Check that the compiler errors out when the directory for the locale in the
74+
// sysroot is actually a file.
75+
rfs::remove_dir_all("fakeroot/share/locale/zh-CN");
76+
rfs::create_file("fakeroot/share/locale/zh-CN");
77+
rustc()
78+
.arg("-Ztranslate-lang=zh-CN")
79+
.input("test.rs")
80+
.sysroot("fakeroot")
81+
.run_fail()
82+
.assert_stderr_contains("`$sysroot/share/locales/$locale` is not a directory");
83+
}
84+
85+
fn symlink_all_entries<P: AsRef<std::path::Path>>(dir: P, fakepath: &str) {
86+
for found_path in rfs::shallow_find_dir_entries(dir) {
87+
rfs::create_symlink(&found_path, path(fakepath).join(found_path.file_name().unwrap()));
88+
}
89+
}

0 commit comments

Comments
 (0)