Skip to content

Commit

Permalink
rewrite translation to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Aug 12, 2024
1 parent 5f1e861 commit ea3ebb5
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 79 deletions.
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ run-make/rlib-format-packed-bundled-libs/Makefile
run-make/split-debuginfo/Makefile
run-make/symbol-mangling-hashed/Makefile
run-make/sysroot-crates-are-unstable/Makefile
run-make/translation/Makefile
run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile
78 changes: 0 additions & 78 deletions tests/run-make/translation/Makefile

This file was deleted.

89 changes: 89 additions & 0 deletions tests/run-make/translation/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Various tests on Fluent bundles, useful to change the compiler's language
// to the one requested by the user. Check each comment header to learn the purpose
// of each test case.
// See https://github.com/rust-lang/rust/pull/95512

//@ needs-symlink

use run_make_support::{path, rfs, rustc};

fn main() {
// Check that the test works normally, using the built-in fallback bundle.
rustc().input("test.rs").run_fail().assert_stderr_contains("struct literal body without path");
// Check that a primary bundle can be loaded and will be preferentially used
// where possible.
rustc()
.arg("-Ztranslate-additional-ftl=working.ftl")
.input("test.rs")
.run_fail()
.assert_stderr_contains("this is a test message");
// Check that a primary bundle with a broken message (e.g. a interpolated
// variable is missing) will use the fallback bundle.
rustc()
.arg("-Ztranslate-additional-ftl=missing.ftl")
.input("test.rs")
.run_fail()
.assert_stderr_contains("struct literal body without path");
// Check that a primary bundle without the desired message will use the fallback
// bundle.
rustc()
.arg("-Ztranslate-additional-ftl=broken.ftl")
.input("test.rs")
.run_fail()
.assert_stderr_contains("struct literal body without path");

// 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.
let sysroot = rustc().print("sysroot").run().stdout_utf8();
let sysroot = sysroot.trim();
rfs::create_dir("fakeroot");
symlink_all_entries(&sysroot, "fakeroot");
rfs::remove_file("fakeroot/lib");
rfs::create_dir("fakeroot/lib");
symlink_all_entries(path(&sysroot).join("lib"), "fakeroot/lib");
rfs::remove_file("fakeroot/lib/rustlib");
rfs::create_dir("fakeroot/lib/rustlib");
symlink_all_entries(path(&sysroot).join("lib/rustlib"), "fakeroot/lib/rustlib");
rfs::remove_file("fakeroot/lib/rustlib/src");
rfs::create_dir("fakeroot/lib/rustlib/src");
symlink_all_entries(path(&sysroot).join("lib/rustlib/src"), "fakeroot/lib/rustlib/src");
// When download-rustc is enabled, `sysroot` will have a share directory. Delete the link to it.
if path("fakeroot/share").exists() {
rfs::remove_file("fakeroot/share");
}
rfs::create_dir_all("fakeroot/share/locale/zh-CN");
rfs::create_symlink("working.ftl", "fakeroot/share/locale/zh-CN/basic-translation.ftl");
rustc()
.arg("-Ztranslate-lang=zh-CN")
.input("test.rs")
.sysroot("fakeroot")
.run_fail()
.assert_stderr_contains("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.
rustc()
.arg("-Ztranslate-lang=tlh")
// .input("test.rs")
.run_fail()
.assert_stderr_contains("missing locale directory");

// Check that the compiler errors out when the directory for the locale in the
// sysroot is actually a file.
rfs::remove_dir_all("fakeroot/share/locale/zh-CN");
rfs::create_file("fakeroot/share/locale/zh-CN");
rustc()
.arg("-Ztranslate-lang=zh-CN")
.input("test.rs")
.sysroot("fakeroot")
.run_fail()
.assert_stderr_contains("`$sysroot/share/locales/$locale` is not a directory");
}

fn symlink_all_entries<P: AsRef<std::path::Path>>(dir: P, fakepath: &str) {
for found_path in rfs::shallow_find_dir_entries(dir) {
rfs::create_symlink(&found_path, path(fakepath).join(found_path.file_name().unwrap()));
}
}

0 comments on commit ea3ebb5

Please sign in to comment.