build(rust): vendor googletest crate
This commit was merged in pull request #76.
This commit is contained in:
28
third_party/crates/autocfg-1.5.1/tests/no_std.rs
vendored
Normal file
28
third_party/crates/autocfg-1.5.1/tests/no_std.rs
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
extern crate autocfg;
|
||||
|
||||
use std::env;
|
||||
|
||||
mod support;
|
||||
|
||||
/// Tests that we can control the use of `#![no_std]`.
|
||||
#[test]
|
||||
fn no_std() {
|
||||
// Clear the CI `TARGET`, if any, so we're just dealing with the
|
||||
// host target which always has `std` available.
|
||||
env::remove_var("TARGET");
|
||||
|
||||
// Use the same path as this test binary.
|
||||
let out = support::out_dir();
|
||||
|
||||
let mut ac = autocfg::AutoCfg::with_dir(out.as_ref()).unwrap();
|
||||
assert!(!ac.no_std());
|
||||
assert!(ac.probe_path("std::mem"));
|
||||
|
||||
// `#![no_std]` was stabilized in Rust 1.6
|
||||
if ac.probe_rustc_version(1, 6) {
|
||||
ac.set_no_std(true);
|
||||
assert!(ac.no_std());
|
||||
assert!(!ac.probe_path("std::mem"));
|
||||
assert!(ac.probe_path("core::mem"));
|
||||
}
|
||||
}
|
||||
34
third_party/crates/autocfg-1.5.1/tests/rustflags.rs
vendored
Normal file
34
third_party/crates/autocfg-1.5.1/tests/rustflags.rs
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
extern crate autocfg;
|
||||
|
||||
use std::env;
|
||||
|
||||
mod support;
|
||||
|
||||
/// Tests that autocfg uses the RUSTFLAGS or CARGO_ENCODED_RUSTFLAGS
|
||||
/// environment variables when running rustc.
|
||||
#[test]
|
||||
fn test_with_sysroot() {
|
||||
let dir = support::exe_dir();
|
||||
let out = support::out_dir();
|
||||
|
||||
// If we have encoded rustflags, they take precedence, even if empty.
|
||||
env::set_var("CARGO_ENCODED_RUSTFLAGS", "");
|
||||
env::set_var("RUSTFLAGS", &format!("-L {}", dir.display()));
|
||||
let ac = autocfg::AutoCfg::with_dir(out.as_ref()).unwrap();
|
||||
assert!(ac.probe_sysroot_crate("std"));
|
||||
assert!(!ac.probe_sysroot_crate("autocfg"));
|
||||
|
||||
// Now try again with useful encoded args.
|
||||
env::set_var(
|
||||
"CARGO_ENCODED_RUSTFLAGS",
|
||||
&format!("-L\x1f{}", dir.display()),
|
||||
);
|
||||
let ac = autocfg::AutoCfg::with_dir(out.as_ref()).unwrap();
|
||||
assert!(ac.probe_sysroot_crate("autocfg"));
|
||||
|
||||
// Try the old-style RUSTFLAGS, ensuring HOST != TARGET.
|
||||
env::remove_var("CARGO_ENCODED_RUSTFLAGS");
|
||||
env::set_var("HOST", "lol");
|
||||
let ac = autocfg::AutoCfg::with_dir(out.as_ref()).unwrap();
|
||||
assert!(ac.probe_sysroot_crate("autocfg"));
|
||||
}
|
||||
21
third_party/crates/autocfg-1.5.1/tests/support/mod.rs
vendored
Normal file
21
third_party/crates/autocfg-1.5.1/tests/support/mod.rs
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
use std::borrow::Cow;
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// The directory containing this test binary.
|
||||
pub fn exe_dir() -> PathBuf {
|
||||
let exe = env::current_exe().unwrap();
|
||||
exe.parent().unwrap().to_path_buf()
|
||||
}
|
||||
|
||||
/// The directory to use for test probes.
|
||||
pub fn out_dir() -> Cow<'static, Path> {
|
||||
if let Some(tmpdir) = option_env!("CARGO_TARGET_TMPDIR") {
|
||||
Cow::Borrowed(tmpdir.as_ref())
|
||||
} else if let Some(tmpdir) = env::var_os("TESTS_TARGET_DIR") {
|
||||
Cow::Owned(tmpdir.into())
|
||||
} else {
|
||||
// Use the same path as this test binary.
|
||||
Cow::Owned(exe_dir())
|
||||
}
|
||||
}
|
||||
189
third_party/crates/autocfg-1.5.1/tests/tests.rs
vendored
Normal file
189
third_party/crates/autocfg-1.5.1/tests/tests.rs
vendored
Normal file
@@ -0,0 +1,189 @@
|
||||
extern crate autocfg;
|
||||
|
||||
use autocfg::AutoCfg;
|
||||
|
||||
mod support;
|
||||
|
||||
fn core_std(ac: &AutoCfg, path: &str) -> String {
|
||||
let krate = if ac.no_std() { "core" } else { "std" };
|
||||
format!("{}::{}", krate, path)
|
||||
}
|
||||
|
||||
fn assert_std(ac: &AutoCfg, probe_result: bool) {
|
||||
assert_eq!(!ac.no_std(), probe_result);
|
||||
}
|
||||
|
||||
fn assert_min(ac: &AutoCfg, major: usize, minor: usize, probe_result: bool) {
|
||||
assert_eq!(ac.probe_rustc_version(major, minor), probe_result);
|
||||
}
|
||||
|
||||
fn autocfg_for_test() -> AutoCfg {
|
||||
AutoCfg::with_dir(support::out_dir().as_ref()).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn autocfg_version() {
|
||||
let ac = autocfg_for_test();
|
||||
assert!(ac.probe_rustc_version(1, 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_add() {
|
||||
let ac = autocfg_for_test();
|
||||
let add = core_std(&ac, "ops::Add");
|
||||
let add_rhs = add.clone() + "<i32>";
|
||||
let add_rhs_output = add.clone() + "<i32, Output = i32>";
|
||||
let dyn_add_rhs_output = "dyn ".to_string() + &*add_rhs_output;
|
||||
assert!(ac.probe_path(&add));
|
||||
assert!(ac.probe_trait(&add));
|
||||
assert!(ac.probe_trait(&add_rhs));
|
||||
assert!(ac.probe_trait(&add_rhs_output));
|
||||
assert_min(&ac, 1, 27, ac.probe_type(&dyn_add_rhs_output));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_as_ref() {
|
||||
let ac = autocfg_for_test();
|
||||
let as_ref = core_std(&ac, "convert::AsRef");
|
||||
let as_ref_str = as_ref.clone() + "<str>";
|
||||
let dyn_as_ref_str = "dyn ".to_string() + &*as_ref_str;
|
||||
assert!(ac.probe_path(&as_ref));
|
||||
assert!(ac.probe_trait(&as_ref_str));
|
||||
assert!(ac.probe_type(&as_ref_str));
|
||||
assert_min(&ac, 1, 27, ac.probe_type(&dyn_as_ref_str));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_i128() {
|
||||
let ac = autocfg_for_test();
|
||||
let i128_path = core_std(&ac, "i128");
|
||||
assert_min(&ac, 1, 26, ac.probe_path(&i128_path));
|
||||
assert_min(&ac, 1, 26, ac.probe_type("i128"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_sum() {
|
||||
let ac = autocfg_for_test();
|
||||
let sum = core_std(&ac, "iter::Sum");
|
||||
let sum_i32 = sum.clone() + "<i32>";
|
||||
let dyn_sum_i32 = "dyn ".to_string() + &*sum_i32;
|
||||
assert_min(&ac, 1, 12, ac.probe_path(&sum));
|
||||
assert_min(&ac, 1, 12, ac.probe_trait(&sum));
|
||||
assert_min(&ac, 1, 12, ac.probe_trait(&sum_i32));
|
||||
assert_min(&ac, 1, 12, ac.probe_type(&sum_i32));
|
||||
assert_min(&ac, 1, 27, ac.probe_type(&dyn_sum_i32));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_std() {
|
||||
let ac = autocfg_for_test();
|
||||
assert_std(&ac, ac.probe_sysroot_crate("std"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_alloc() {
|
||||
let ac = autocfg_for_test();
|
||||
assert_min(&ac, 1, 36, ac.probe_sysroot_crate("alloc"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_bad_sysroot_crate() {
|
||||
let ac = autocfg_for_test();
|
||||
assert!(!ac.probe_sysroot_crate("doesnt_exist"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_no_std() {
|
||||
let ac = autocfg_for_test();
|
||||
assert!(ac.probe_type("i32"));
|
||||
assert!(ac.probe_type("[i32]"));
|
||||
assert_std(&ac, ac.probe_type("Vec<i32>"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_expression() {
|
||||
let ac = autocfg_for_test();
|
||||
assert!(ac.probe_expression(r#""test".trim_left()"#));
|
||||
assert_min(&ac, 1, 30, ac.probe_expression(r#""test".trim_start()"#));
|
||||
assert_std(&ac, ac.probe_expression("[1, 2, 3].to_vec()"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_constant() {
|
||||
let ac = autocfg_for_test();
|
||||
assert!(ac.probe_constant("1 + 2 + 3"));
|
||||
assert_min(
|
||||
&ac,
|
||||
1,
|
||||
33,
|
||||
ac.probe_constant("{ let x = 1 + 2 + 3; x * x }"),
|
||||
);
|
||||
assert_min(&ac, 1, 39, ac.probe_constant(r#""test".len()"#));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_raw() {
|
||||
let ac = autocfg_for_test();
|
||||
let prefix = if ac.no_std() { "#![no_std]\n" } else { "" };
|
||||
let f = |s| format!("{}{}", prefix, s);
|
||||
|
||||
// This attribute **must** be used at the crate level.
|
||||
assert!(ac.probe_raw(&f("#![no_builtins]")).is_ok());
|
||||
|
||||
assert!(ac.probe_raw(&f("#![deny(dead_code)] fn x() {}")).is_err());
|
||||
assert!(ac.probe_raw(&f("#![allow(dead_code)] fn x() {}")).is_ok());
|
||||
assert!(ac
|
||||
.probe_raw(&f("#![deny(dead_code)] pub fn x() {}"))
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_cleanup() {
|
||||
let dir = support::out_dir().join("autocfg_test_probe_cleanup");
|
||||
std::fs::create_dir(&dir).unwrap();
|
||||
|
||||
let ac = AutoCfg::with_dir(&dir).unwrap();
|
||||
assert!(ac.probe_type("i32"));
|
||||
|
||||
// NB: this is not `remove_dir_all`, so it will only work if the directory
|
||||
// is empty -- i.e. the probe should have removed any output files.
|
||||
std::fs::remove_dir(&dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editions() {
|
||||
let mut ac = autocfg_for_test();
|
||||
assert!(ac.edition().is_none());
|
||||
assert!(ac.probe_raw("").is_ok());
|
||||
|
||||
for (edition, minor) in vec![(2015, 27), (2018, 31), (2021, 56), (2024, 85)] {
|
||||
let edition = edition.to_string();
|
||||
ac.set_edition(Some(edition.clone()));
|
||||
assert_eq!(ac.edition(), Some(&*edition));
|
||||
assert_min(&ac, 1, minor, ac.probe_raw("").is_ok());
|
||||
}
|
||||
|
||||
ac.set_edition(Some("invalid".into()));
|
||||
assert_eq!(ac.edition(), Some("invalid"));
|
||||
assert!(ac.probe_raw("").is_err());
|
||||
|
||||
ac.set_edition(None);
|
||||
assert!(ac.edition().is_none());
|
||||
assert!(ac.probe_raw("").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edition_keyword_try() {
|
||||
let mut ac = autocfg_for_test();
|
||||
|
||||
if ac.probe_rustc_version(1, 27) {
|
||||
ac.set_edition(Some(2015.to_string()));
|
||||
}
|
||||
assert!(ac.probe_expression("{ let try = 0; try }"));
|
||||
|
||||
if ac.probe_rustc_version(1, 31) {
|
||||
ac.set_edition(Some(2018.to_string()));
|
||||
assert!(!ac.probe_expression("{ let try = 0; try }"));
|
||||
assert!(ac.probe_expression("{ let r#try = 0; r#try }"));
|
||||
}
|
||||
}
|
||||
83
third_party/crates/autocfg-1.5.1/tests/wrappers.rs
vendored
Normal file
83
third_party/crates/autocfg-1.5.1/tests/wrappers.rs
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
extern crate autocfg;
|
||||
|
||||
use std::env;
|
||||
use std::io;
|
||||
|
||||
mod support;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<_> = env::args().skip(1).collect();
|
||||
if args.is_empty() {
|
||||
// With no arguments, this must be a (harness-free) test run.
|
||||
// (we're using system binaries as wrappers, so ignore other platforms)
|
||||
if cfg!(unix) {
|
||||
test_wrappers();
|
||||
}
|
||||
} else {
|
||||
// Otherwise we're acting like a no-op rustc wrapper, ignoring almost everything.
|
||||
for arg in args {
|
||||
match &*arg {
|
||||
// Add our own version so we can check that the wrapper is used for that.
|
||||
"--version" => println!("release: 12345.6789.0"),
|
||||
|
||||
// Read all input so the writer doesn't get EPIPE when we exit.
|
||||
"-" => {
|
||||
let stdin = io::stdin();
|
||||
let _ = io::copy(&mut stdin.lock(), &mut io::sink());
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Tests that autocfg uses the RUSTC_WRAPPER and/or RUSTC_WORKSPACE_WRAPPER
|
||||
/// environment variables when running rustc.
|
||||
fn test_wrappers() {
|
||||
fn set(name: &str, value: Option<bool>) {
|
||||
match value {
|
||||
Some(true) => env::set_var(name, "/usr/bin/env"),
|
||||
Some(false) => env::set_var(name, "/bin/false"),
|
||||
None => env::remove_var(name),
|
||||
}
|
||||
}
|
||||
|
||||
let out = support::out_dir();
|
||||
|
||||
// This is used as a heuristic to detect rust-lang/cargo#9601.
|
||||
env::set_var("CARGO_ENCODED_RUSTFLAGS", "");
|
||||
|
||||
// No wrapper, a good pass-through wrapper, and a bad wrapper.
|
||||
let variants = [None, Some(true), Some(false)];
|
||||
|
||||
for &workspace in &variants {
|
||||
for &rustc in &variants {
|
||||
set("RUSTC_WRAPPER", rustc);
|
||||
set("RUSTC_WORKSPACE_WRAPPER", workspace);
|
||||
|
||||
let ac = autocfg::AutoCfg::with_dir(out.as_ref()).unwrap();
|
||||
if rustc == Some(false) || workspace == Some(false) {
|
||||
// Everything should fail with bad wrappers.
|
||||
assert!(!ac.probe_type("usize"));
|
||||
} else {
|
||||
// Try known good and bad types for the wrapped rustc.
|
||||
assert!(ac.probe_type("usize"));
|
||||
assert!(!ac.probe_type("mesize"));
|
||||
}
|
||||
// Either way, we should have found the inner rustc version.
|
||||
assert!(ac.probe_rustc_version(1, 0));
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, make sure that `RUSTC_WRAPPER` is applied outermost
|
||||
// by using something (ourself) that doesn't pass through at all.
|
||||
let wrap_ignored = env::current_exe().unwrap();
|
||||
env::set_var("RUSTC_WRAPPER", &wrap_ignored);
|
||||
env::set_var("RUSTC_WORKSPACE_WRAPPER", "/bin/false");
|
||||
let ac = autocfg::AutoCfg::with_dir(out.as_ref()).unwrap();
|
||||
assert!(ac.probe_type("mesize")); // anything goes!
|
||||
|
||||
// Make sure we also got the version from that wrapper.
|
||||
assert!(ac.probe_rustc_version(12345, 6789));
|
||||
}
|
||||
Reference in New Issue
Block a user