Debian Codegraph @

.cargo/vendor/zerocopy/tests/trybuild.rs

raw
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 // Many of our UI tests require the "derive" feature to function properly. In
10 // particular:
11 // - Some tests directly include `zerocopy-derive/tests/include.rs`, which
12 // derives traits on the `AU16` type.
13 // - The file `invalid-impls.rs` directly includes `src/util/macros.rs` in order
14 // to test the `impl_or_verify!` macro which is defined in that file.
15 // Specifically, it tests the verification portion of that macro, which is
16 // enabled when `cfg(any(feature = "derive", test))`. While `--cfg test` is of
17 // course passed to the code in the file you're reading right now, `trybuild`
18 // does not pass `--cfg test` when it invokes Cargo. As a result, this
19 // `trybuild` test only tests the correct behavior when the "derive" feature
20 // is enabled.
21 #![cfg(feature = "derive")]
22
23 use testutil::{set_rustflags_w_warnings, ToolchainVersion};
24
25 #[test]
26 #[cfg_attr(miri, ignore)]
27 fn ui() {
28 let version = ToolchainVersion::extract_from_pwd().unwrap();
29 // See the doc comment on this method for an explanation of what this does
30 // and why we store source files in different directories.
31 let source_files_dirname = version.get_ui_source_files_dirname_and_maybe_print_warning();
32
33 // Set `-Wwarnings` in the `RUSTFLAGS` environment variable to ensure that
34 // `.stderr` files reflect what the typical user would encounter.
35 set_rustflags_w_warnings();
36
37 let t = trybuild::TestCases::new();
38 t.compile_fail(format!("tests/{}/*.rs", source_files_dirname));
39 }
40
41 #[test]
42 #[cfg_attr(miri, ignore)]
43 fn ui_invalid_impls() {
44 let version = ToolchainVersion::extract_from_pwd().unwrap();
45 // See the doc comment on this method for an explanation of what this does
46 // and why we store source files in different directories.
47 let source_files_dirname = version.get_ui_source_files_dirname_and_maybe_print_warning();
48
49 // Set `-Wwarnings` in the `RUSTFLAGS` environment variable to ensure that
50 // `.stderr` files reflect what the typical user would encounter.
51 set_rustflags_w_warnings();
52
53 let t = trybuild::TestCases::new();
54 t.compile_fail(format!("tests/{}/invalid-impls/*.rs", source_files_dirname));
55 }