Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update datatest to work on 1.40 #20

Merged
merged 4 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ members = [
# of all tests.
test_case_registration = []

# Allow this to build on compiler versions >1.39.0. Needed due to unstable API changes.
post_v139 = []

# Use very, very, very sketchy way of intercepting a test runner on a stable Rust. Without that feature, there are two
# options:
# 1. use `#![test_runner(datatest::runner)]` (nightly-only)
Expand Down
4 changes: 1 addition & 3 deletions datatest-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,7 @@ pub fn test_ctor_registration(
let should_panic = match info.should_panic {
ShouldPanic::No => quote!(::datatest::__internal::RegularShouldPanic::No),
ShouldPanic::Yes => quote!(::datatest::__internal::RegularShouldPanic::Yes),
ShouldPanic::YesWithMessage(v) => {
quote!(::datatest::__internal::RegularShouldPanic::YesWithMessage(#v))
}
ShouldPanic::YesWithMessage(v) => quote!(::datatest::__internal::RegularShouldPanic::YesWithMessage(#v)),
};
let registration = test_registration(Registration::Ctor, &desc_ident);
let output = quote! {
Expand Down
67 changes: 50 additions & 17 deletions src/runner.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::data::{DataTestDesc, DataTestFn};
use crate::files::{FilesTestDesc, FilesTestFn};
#[cfg(feature = "post_v139")]
use crate::rustc_test::TestType;
use crate::rustc_test::{Bencher, ShouldPanic, TestDesc, TestDescAndFn, TestFn, TestName};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, AtomicPtr, Ordering};
Expand Down Expand Up @@ -48,6 +50,37 @@ fn derive_test_name(root: &Path, path: &Path, test_name: &str) -> String {
test_name
}

#[cfg(feature = "post_v139")]
fn test_desc(
name: TestName,
ignore: bool,
should_panic: ShouldPanic,
allow_fail: bool,
) -> TestDesc {
TestDesc {
name,
ignore,
should_panic,
allow_fail,
test_type: TestType::Unknown,
}
}

#[cfg(not(feature = "post_v139"))]
fn test_desc(
name: TestName,
ignore: bool,
should_panic: ShouldPanic,
allow_fail: bool,
) -> TestDesc {
TestDesc {
name,
ignore,
should_panic,
allow_fail,
}
}

/// When compiling tests, Rust compiler collects all items marked with `#[test_case]` and passes
/// references to them to the test runner in a slice (like `&[&test_a, &test_b, &test_c]`). Since
/// we need a different descriptor for our data-driven tests than the standard one, we have two
Expand Down Expand Up @@ -168,13 +201,13 @@ fn render_files_test(desc: &FilesTestDesc, rendered: &mut Vec<TestDescAndFn>) {

// Generate a standard test descriptor
let desc = TestDescAndFn {
desc: TestDesc {
name: TestName::DynTestName(test_name),
desc: test_desc(
TestName::DynTestName(test_name),
ignore,
should_panic: ShouldPanic::No,
ShouldPanic::No,
// Cannot be used on stable: https://github.com/rust-lang/rust/issues/46488
allow_fail: false,
},
false,
),
testfn,
};

Expand Down Expand Up @@ -212,12 +245,12 @@ fn render_data_test(desc: &DataTestDesc, rendered: &mut Vec<TestDescAndFn>) {

// Generate a standard test descriptor
let desc = TestDescAndFn {
desc: TestDesc {
name: TestName::DynTestName(case_name),
ignore: desc.ignore,
should_panic: ShouldPanic::No,
allow_fail: false,
},
desc: test_desc(
TestName::DynTestName(case_name),
desc.ignore,
ShouldPanic::No,
false,
),
testfn,
};

Expand Down Expand Up @@ -370,13 +403,13 @@ fn render_test_descriptor(
}
DatatestTestDesc::RegularTest(desc) => {
rendered.push(TestDescAndFn {
desc: TestDesc {
name: TestName::StaticTestName(real_name(desc.name)),
ignore: desc.ignore,
desc: test_desc(
TestName::StaticTestName(real_name(desc.name)),
desc.ignore,
// FIXME: should support!
should_panic: desc.should_panic.into(),
allow_fail: false,
},
desc.should_panic.into(),
false,
),
testfn: TestFn::StaticTestFn(desc.testfn),
})
}
Expand Down