Skip to content

Commit f2c25f3

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 be27637 commit f2c25f3

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
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
base64 = ["bitcoin/base64"]

contrib/test.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ FEATURES="compiler serde rand base64"
77
cargo --version
88
rustc --version
99

10+
# Cache the toolchain we are using.
11+
NIGHTLY=false
12+
if cargo --version | grep nightly; then
13+
NIGHTLY=true
14+
fi
15+
1016
# Format if told to
1117
if [ "$DO_FMT" = true ]
1218
then
@@ -80,10 +86,18 @@ then
8086
done
8187
fi
8288

83-
# Bench if told to (this only works with the nightly toolchain)
89+
# Bench if told to, only works with non-stable toolchain (nightly, beta).
8490
if [ "$DO_BENCH" = true ]
8591
then
86-
cargo bench --features="unstable compiler"
92+
if [ "$NIGHTLY" = false ]; then
93+
if [ -n "$RUSTUP_TOOLCHAIN" ]; then
94+
echo "RUSTUP_TOOLCHAIN is set to a non-nightly toolchain but DO_BENCH requires a nightly toolchain"
95+
else
96+
echo "DO_BENCH requires a nightly toolchain"
97+
fi
98+
exit 1
99+
fi
100+
RUSTFLAGS='--cfg=bench' cargo bench
87101
fi
88102

89103
# 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
@@ -74,7 +74,8 @@
7474
//!
7575
7676
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
77-
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
77+
// Experimental features we need.
78+
#![cfg_attr(bench, feature(test))]
7879
// Coding conventions
7980
#![deny(unsafe_code)]
8081
#![deny(non_upper_case_globals)]
@@ -107,7 +108,8 @@ extern crate core;
107108

108109
#[cfg(feature = "serde")]
109110
pub use actual_serde as serde;
110-
#[cfg(all(test, feature = "unstable"))]
111+
112+
#[cfg(bench)]
111113
extern crate test;
112114

113115
#[macro_use]

src/policy/compiler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ mod tests {
16011601
}
16021602
}
16031603

1604-
#[cfg(all(test, feature = "unstable"))]
1604+
#[cfg(bench)]
16051605
mod benches {
16061606
use std::str::FromStr;
16071607

src/policy/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ mod tests {
541541
}
542542
}
543543

544-
#[cfg(all(test, feature = "compiler", feature = "unstable"))]
544+
#[cfg(bench)]
545545
mod benches {
546546
use core::str::FromStr;
547547

0 commit comments

Comments
 (0)