Skip to content

Commit 0c653bc

Browse files
committed
Remove unstable feature
Currently it is not possible to run the test suite with `cargo test --all-features`, this is because we use a feature called `unstable` to enable the unstable `test` crate that is used for benchmarking. There is another way to conditionally enable the test crate and guard the benchmark code. We can use a custom configuration option `bench` and then set it using `RUSTFLAGS='--cfg=bench`.
1 parent fd9ef55 commit 0c653bc

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ no-std = ["hashbrown", "bitcoin/no-std"]
1717
compiler = []
1818
trace = []
1919

20-
unstable = []
2120
serde = ["actual-serde", "bitcoin/serde"]
2221
rand = ["bitcoin/rand"]
2322

contrib/test.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ cargo update -p serde_derive --precise 1.0.142
1010
cargo --version
1111
rustc --version
1212

13-
# Work out if we are using a nightly toolchain.
13+
# Cache the toolchain we are using.
14+
NIGHTLY=false
15+
if cargo --version | grep nightly; then
16+
NIGHTLY=true
17+
fi
1418
MSRV=false
1519
if cargo --version | grep "1\.41\.0"; then
1620
MSRV=true
1721
fi
1822

23+
# Do pinning based on toolchain.
1924
if cargo --version | grep "1\.47\.0"; then
2025
cargo update -p once_cell --precise 1.13.1
2126
fi
22-
2327
# form_urlencoded 1.1.0 breaks MSRV.
2428
if [ "$MSRV" = true ]; then
2529
cargo update -p url --precise 2.2.2
@@ -88,10 +92,18 @@ then
8892
done
8993
fi
9094

91-
# Bench if told to (this only works with the nightly toolchain)
95+
# Bench if told to, only works with non-stable toolchain (nightly, beta).
9296
if [ "$DO_BENCH" = true ]
9397
then
94-
cargo bench --features="unstable compiler"
98+
if [ "$NIGHTLY" = false ]; then
99+
if [ -n "$RUSTUP_TOOLCHAIN" ]; then
100+
echo "RUSTUP_TOOLCHAIN is set to a non-nightly toolchain but DO_BENCH requires a nightly toolchain"
101+
else
102+
echo "DO_BENCH requires a nightly toolchain"
103+
fi
104+
exit 1
105+
fi
106+
RUSTFLAGS='--cfg=bench' cargo bench
95107
fi
96108

97109
# Build the docs if told to (this only works with the nightly toolchain)

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
//!
8080
8181
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
82-
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
82+
// Experimental features we need.
83+
#![cfg_attr(bench, feature(test))]
8384
// Coding conventions
8485
#![deny(unsafe_code)]
8586
#![deny(non_upper_case_globals)]
@@ -109,7 +110,8 @@ extern crate core;
109110

110111
#[cfg(feature = "serde")]
111112
pub use actual_serde as serde;
112-
#[cfg(all(test, feature = "unstable"))]
113+
114+
#[cfg(bench)]
113115
extern crate test;
114116

115117
#[macro_use]

src/policy/compiler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ mod tests {
16131613
}
16141614
}
16151615

1616-
#[cfg(all(test, feature = "unstable"))]
1616+
#[cfg(bench)]
16171617
mod benches {
16181618
use std::str::FromStr;
16191619

src/policy/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ mod tests {
553553
}
554554
}
555555

556-
#[cfg(all(test, feature = "compiler", feature = "unstable"))]
556+
#[cfg(bench)]
557557
mod benches {
558558
use core::str::FromStr;
559559

0 commit comments

Comments
 (0)