| 1 |
// Copyright 2019 The Fuchsia Authors |
| 2 |
// |
| 3 |
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 |
| 4 |
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT |
| 5 |
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. |
| 6 |
// This file may not be copied, modified, or distributed except according to |
| 7 |
// those terms. |
| 8 |
|
| 9 |
#![allow(clippy::uninlined_format_args)] |
| 10 |
|
| 11 |
use std::env; |
| 12 |
|
| 13 |
use testutil::set_rustflags_w_warnings; |
| 14 |
|
| 15 |
fn test(subdir: &str) { |
| 16 |
let version = testutil::ToolchainVersion::extract_from_pwd().unwrap(); |
| 17 |
// See the doc comment on this method for an explanation of what this does |
| 18 |
// and why we store source files in different directories. |
| 19 |
let source_files_dirname = version.get_ui_source_files_dirname_and_maybe_print_warning(); |
| 20 |
|
| 21 |
// Set `-Wwarnings` in the `RUSTFLAGS` environment variable to ensure that |
| 22 |
// `.stderr` files reflect what the typical user would encounter. |
| 23 |
set_rustflags_w_warnings(); |
| 24 |
|
| 25 |
let t = trybuild::TestCases::new(); |
| 26 |
t.compile_fail(format!("tests/{}/{}/*.rs", source_files_dirname, subdir)); |
| 27 |
} |
| 28 |
|
| 29 |
#[test] |
| 30 |
#[cfg_attr(miri, ignore)] |
| 31 |
fn ui() { |
| 32 |
test(""); |
| 33 |
|
| 34 |
// This tests the behavior when `--cfg zerocopy_derive_union_into_bytes` is |
| 35 |
// not present, so remove it. If this logic is wrong, that's fine - it will |
| 36 |
// exhibit as a test failure that we can debug at that point. |
| 37 |
let rustflags = env::var("RUSTFLAGS").unwrap(); |
| 38 |
let new_rustflags = rustflags.replace("--cfg zerocopy_derive_union_into_bytes", ""); |
| 39 |
|
| 40 |
// SAFETY: None of our code is concurrently accessinv env vars. It's |
| 41 |
// possible that the test framework has spawned other threads that are |
| 42 |
// concurrently accessing env vars, but we can't do anything about that. |
| 43 |
#[allow(unused_unsafe)] // `set_var` is safe on our MSRV. |
| 44 |
unsafe { |
| 45 |
env::set_var("RUSTFLAGS", new_rustflags) |
| 46 |
}; |
| 47 |
|
| 48 |
test("union_into_bytes_cfg"); |
| 49 |
|
| 50 |
// Reset RUSTFLAGS in case we later add other tests which rely on its value. |
| 51 |
// This isn't strictly necessary, but it's easier to add this now when we're |
| 52 |
// thinking about the semantics of these env vars than to debug later when |
| 53 |
// we've forgotten about it. |
| 54 |
// |
| 55 |
// SAFETY: See previous safety comment. |
| 56 |
#[allow(unused_unsafe)] // `set_var` is safe on our MSRV. |
| 57 |
unsafe { |
| 58 |
env::set_var("RUSTFLAGS", rustflags) |
| 59 |
}; |
| 60 |
} |