Skip to content

Commit 38ee4e9

Browse files
committed
Fix parts of test suite not running
It disabled too much stuff through the use of a non-existent cfg(feature="stable"). That now exists as feature="rustc_is_stable", same with rustc_is_nightly. Then, allows test_case_registration to become a default feature. Essentially guards its use in cfg() with &= rustc_is_nightly, so stable users do not have to --no-default-features. Each test suite has instructions for running it at the top now.
1 parent 52ebeb2 commit 38ee4e9

File tree

6 files changed

+55
-24
lines changed

6 files changed

+55
-24
lines changed

src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,25 @@ pub mod __internal {
137137
pub use crate::runner::{
138138
check_test_runner, register, RegistrationNode, RegularShouldPanic, RegularTestDesc,
139139
};
140-
#[cfg(not(feature = "test_case_registration"))]
140+
// i.e. no TCR, use ctor instead
141+
#[cfg(not(all(feature = "rustc_is_nightly", feature = "test_case_registration")))]
141142
pub use datatest_derive::{data_ctor_internal, files_ctor_internal};
142-
#[cfg(feature = "test_case_registration")]
143+
// i.e. use TCR
144+
#[cfg(all(feature = "rustc_is_nightly", feature = "test_case_registration"))]
143145
pub use datatest_derive::{data_test_case_internal, files_test_case_internal};
144146
}
145147

146148
pub use crate::runner::runner;
147149

148-
#[cfg(not(feature = "test_case_registration"))]
150+
// i.e. no TCR, use ctor instead
151+
#[cfg(not(all(feature = "rustc_is_nightly", feature = "test_case_registration")))]
149152
pub use datatest_derive::{
150153
data_ctor_registration as data, files_ctor_registration as files,
151154
test_ctor_registration as test,
152155
};
153156

154-
#[cfg(feature = "test_case_registration")]
157+
// i.e. use TCR
158+
#[cfg(all(feature = "rustc_is_nightly", feature = "test_case_registration"))]
155159
pub use datatest_derive::{
156160
data_test_case_registration as data, files_test_case_registration as files,
157161
};

tests/datatest.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1-
#![cfg(feature = "nightly")]
1+
//! cargo +nightly test # test_case_registration enabled
2+
//! cargo +nightly test --no-default-features # no test_case_registration, uses ctor
3+
4+
// self-testing config only:
5+
#![cfg(all(feature = "rustc_is_nightly"))]
6+
27
#![feature(custom_test_frameworks)]
38
#![test_runner(datatest::runner)]
49

510
// We want to share tests between "nightly" and "stable" suites. These have to be two different
611
// suites as we set `harness = false` for the "stable" one.
712
include!("tests/mod.rs");
13+
14+
// Regular tests still work
15+
16+
#[test]
17+
fn regular_test() {
18+
println!("regular tests also work!");
19+
}
20+
21+
#[test]
22+
fn regular_test_result() -> Result<(), Box<dyn std::error::Error>> {
23+
println!("regular tests also work!");
24+
Ok(())
25+
}

tests/datatest_stable.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
1-
// We want to share tests between "nightly" and "stable" suites. These have to be two different
2-
// suites as we set `harness = false` for the "stable" one.
3-
include!("tests/mod.rs");
1+
//! cargo +stable test --features subvert_stable_guarantees
42
3+
// This test suite is configured with `harness = false` in Cargo.toml.
4+
// So we need to make sure it has a main function when testing nightly
5+
#[cfg(not(feature = "rustc_is_stable"))]
6+
fn main() {}
7+
// And uses the datatest harness when testing stable
8+
#[cfg(feature = "rustc_is_stable")]
59
datatest::harness!();
610

7-
// Regular test have to use `datatest` variant of `#[test]` to work.
8-
use datatest::test;
11+
#[cfg(feature = "rustc_is_stable")]
12+
mod stable {
13+
// Regular test have to use `datatest` variant of `#[test]` to work.
14+
use datatest::test;
915

10-
#[test]
11-
fn regular_test() {
12-
println!("regular tests also work!");
13-
}
16+
// We want to share tests between "rustc_is_nightly" and "rustc_is_stable" suites. These have to be two different
17+
// suites as we set `harness = false` for the "stable" one.
18+
include!("tests/mod.rs");
19+
20+
#[test]
21+
fn regular_test() {
22+
println!("regular tests also work!");
23+
}
1424

15-
#[test]
16-
fn regular_test_result() -> Result<(), Box<dyn std::error::Error>> {
17-
println!("regular tests also work!");
18-
Ok(())
25+
#[test]
26+
fn regular_test_result() -> Result<(), Box<dyn std::error::Error>> {
27+
println!("regular tests also work!");
28+
Ok(())
29+
}
1930
}

tests/datatest_stable_unsafe.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
//! Run with: `cargo +stable test --features unsafe_test_runner --test datatest_stable_unsafe`
1+
//! cargo +stable test --features subvert_stable_guarantees,unsafe_test_runner
22
3-
#[cfg(feature = "unsafe_test_runner")]
3+
#![cfg(feature = "rustc_is_stable")]
4+
#![cfg(feature = "unsafe_test_runner")]
45

56
// We want to share tests between "nightly" and "stable" suites. These have to be two different
67
// suites as we set `harness = false` for the "stable" one.

tests/tests/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#[cfg(feature = "stable")]
2-
use datatest::test;
3-
41
use serde::Deserialize;
52
use std::fmt;
63
use std::path::Path;

tests/unicode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg(feature = "nightly")]
1+
#![cfg(feature = "rustc_is_nightly")]
22
#![feature(non_ascii_idents)]
33
#![feature(custom_test_frameworks)]
44
#![test_runner(datatest::runner)]

0 commit comments

Comments
 (0)