Skip to content

Commit

Permalink
[trybuild] Only compile when feature = "derive" (#1291)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlf committed May 17, 2024
1 parent 18bccb0 commit deca4b8
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions tests/trybuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
// This file may not be copied, modified, or distributed except according to
// those terms.

// Many of our UI tests require the "derive" feature to function properly. In
// particular:
// - Some tests directly include `zerocopy-derive/tests/include.rs`, which
// derives traits on the `AU16` type.
// - The file `invalid-impls.rs` directly includes `src/macros.rs` in order to
// test the `impl_or_verify!` macro which is defined in that file.
// Specifically, it tests the verification portion of that macro, which is
// enabled when `cfg(any(feature = "derive", test))`. While `--cfg test` is of
// course passed to the code in the file you're reading right now, `trybuild`
// does not pass `--cfg test` when it invokes Cargo. As a result, this
// `trybuild` test only tests the correct behavior when the "derive" feature
// is enabled.
#![cfg(feature = "derive")]

use testutil::ToolchainVersion;

#[test]
Expand All @@ -20,19 +34,9 @@ fn ui() {
t.compile_fail(format!("tests/{}/*.rs", source_files_dirname));
}

// The file `invalid-impls.rs` directly includes `src/macros.rs` in order to
// test the `impl_or_verify!` macro which is defined in that file. Specifically,
// it tests the verification portion of that macro, which is enabled when
// `cfg(any(feature = "derive", test))`. While `--cfg test` is of course passed
// to the code in the file you're reading right now, `trybuild` does not pass
// `--cfg test` when it invokes Cargo. As a result, this `trybuild` test only
// tests the correct behavior when the "derive" feature is enabled.
#[cfg(feature = "derive")]
#[test]
#[cfg_attr(miri, ignore)]
fn ui_invalid_impls() {
assert!(cfg!(feature = "derive"), "ui tests cannot be run without the `derive` feature");

let version = ToolchainVersion::extract_from_pwd().unwrap();
// See the doc comment on this method for an explanation of what this does
// and why we store source files in different directories.
Expand Down

0 comments on commit deca4b8

Please sign in to comment.