summaryrefslogtreecommitdiff
path: root/vendor/bitflags-1.3.2/tests/compile.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/bitflags-1.3.2/tests/compile.rs
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/bitflags-1.3.2/tests/compile.rs')
-rw-r--r--vendor/bitflags-1.3.2/tests/compile.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/vendor/bitflags-1.3.2/tests/compile.rs b/vendor/bitflags-1.3.2/tests/compile.rs
new file mode 100644
index 0000000..ed02d01
--- /dev/null
+++ b/vendor/bitflags-1.3.2/tests/compile.rs
@@ -0,0 +1,63 @@
+use std::{
+ fs,
+ ffi::OsStr,
+ io,
+ path::Path,
+};
+
+use walkdir::WalkDir;
+
+#[test]
+fn fail() {
+ prepare_stderr_files("tests/compile-fail").unwrap();
+
+ let t = trybuild::TestCases::new();
+ t.compile_fail("tests/compile-fail/**/*.rs");
+}
+
+#[test]
+fn pass() {
+ let t = trybuild::TestCases::new();
+ t.pass("tests/compile-pass/**/*.rs");
+}
+
+// Compiler messages may change between versions
+// We don't want to have to track these too closely for `bitflags`, but
+// having some message to check makes sure user-facing errors are sensical.
+//
+// The approach we use is to run the test on all compilers, but only check stderr
+// output on beta (which is the next stable release). We do this by default ignoring
+// any `.stderr` files in the `compile-fail` directory, and copying `.stderr.beta` files
+// when we happen to be running on a beta compiler.
+fn prepare_stderr_files(path: impl AsRef<Path>) -> io::Result<()> {
+ for entry in WalkDir::new(path) {
+ let entry = entry?;
+
+ if entry.path().extension().and_then(OsStr::to_str) == Some("beta") {
+ let renamed = entry.path().with_extension("");
+
+ // Unconditionally remove a corresponding `.stderr` file for a `.stderr.beta`
+ // file if it exists. On `beta` compilers, we'll recreate it. On other compilers,
+ // we don't want to end up checking it anyways.
+ if renamed.exists() {
+ fs::remove_file(&renamed)?;
+ }
+
+ rename_beta_stderr(entry.path(), renamed)?;
+ }
+ }
+
+ Ok(())
+}
+
+#[rustversion::beta]
+fn rename_beta_stderr(from: impl AsRef<Path>, to: impl AsRef<Path>) -> io::Result<()> {
+ fs::copy(from, to)?;
+
+ Ok(())
+}
+
+#[rustversion::not(beta)]
+fn rename_beta_stderr(_: impl AsRef<Path>, _: impl AsRef<Path>) -> io::Result<()> {
+ Ok(())
+}