Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit 029d665

Browse files
committed
Merge #147: Improve feature coverage in CI test suite
5dc3fd4 Add TODO about features to test once we bump MSRV (Tobin Harding) 41807c0 Add feature documentation to manifest (Tobin Harding) f368608 Enable running tests without an allocator (Tobin Harding) f6603c2 Run tests without std enabled (Tobin Harding) 20e4c39 Remove duplicate test (Tobin Harding) Pull request description: Improve feature testing by adding all the features to the test matrix and enabling testing with `--no-default-features`. ACKs for top commit: apoelstra: ACK 5dc3fd4 Tree-SHA512: 2d1f389e27ed8d3cdbf3aed81d48d22652b94f571beffba0ce7f879768f6bdea935e754f920c53e1f28e4085ddc2c6e4f441a977b974e2efaa89832e6f597229
2 parents b8d135b + 5dc3fd4 commit 029d665

File tree

11 files changed

+100
-86
lines changed

11 files changed

+100
-86
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ serde-std = ["serde/std"]
2525
unstable = [] # for benchmarking
2626

2727
[dependencies]
28+
# Only enable this if you explicitly do not want to use "std", otherwise enable "serde-std".
2829
serde = { version = "1.0", default-features = false, optional = true }
30+
# Can only be used with "std" enabled.
2931
schemars = { version = "<=0.8.3", optional = true }
32+
# Only enable this if you explicitly do not want to use an allocator, otherwise enable "alloc".
3033
core2 = { version = "0.3.0", optional = true, default_features = false }
3134

3235
[dev-dependencies]

contrib/test.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/sh -ex
22

3+
# TODO: Add core2 here once we bump MSRV past 1.29
34
FEATURES="serde serde-std std"
45

56
if [ "$DO_ALLOC_TESTS" = true ]; then
@@ -28,21 +29,22 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then
2829

2930
# All features
3031
cargo build --all --no-default-features --features="$FEATURES"
31-
cargo test --all --features="$FEATURES"
32+
cargo test --all --no-default-features --features="$FEATURES"
3233
# Single features
3334
for feature in ${FEATURES}
3435
do
3536
cargo build --all --no-default-features --features="$feature"
36-
cargo test --all --features="$feature"
37+
cargo test --all --no-default-features --features="$feature"
3738
# All combos of two features
3839
for featuretwo in ${FEATURES}; do
3940
cargo build --all --no-default-features --features="$feature $featuretwo"
40-
cargo test --all --features="$feature $featuretwo"
41+
cargo test --all --no-default-features --features="$feature $featuretwo"
4142
done
4243
done
4344

4445
# Other combos
45-
cargo test --all --features="serde-std"
46+
# TODO: Add this test once we bump MSRV past 1.29
47+
# cargo test --all --no-default-features --features="std,schemars"
4648
fi
4749

4850
if [ "$DO_SCHEMARS_TESTS" = true ]; then
@@ -69,11 +71,11 @@ if [ "$DO_ASAN" = true ]; then
6971
CC='clang -fsanitize=address -fno-omit-frame-pointer' \
7072
RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes' \
7173
ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' \
72-
cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
74+
cargo test --lib --all --no-default-features --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
7375
cargo clean
7476
CC='clang -fsanitize=memory -fno-omit-frame-pointer' \
7577
RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes' \
76-
cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
78+
cargo test --lib --all --no-default-features --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
7779
fi
7880

7981
# Bench

src/hash160.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,20 @@ impl HashTrait for Hash {
104104

105105
#[cfg(test)]
106106
mod tests {
107-
use hash160;
108-
use hex::{FromHex, ToHex};
109-
use Hash;
110-
use HashEngine;
111-
112-
#[derive(Clone)]
113-
struct Test {
114-
input: Vec<u8>,
115-
output: Vec<u8>,
116-
output_str: &'static str,
117-
}
118-
119107
#[test]
108+
#[cfg(any(feature = "std", feature = "alloc"))]
120109
fn test() {
110+
use {hash160, Hash, HashEngine};
111+
use hex::{FromHex, ToHex};
112+
113+
#[derive(Clone)]
114+
#[cfg(any(feature = "std", feature = "alloc"))]
115+
struct Test {
116+
input: Vec<u8>,
117+
output: Vec<u8>,
118+
output_str: &'static str,
119+
}
120+
121121
let tests = vec![
122122
// Uncompressed pubkey obtained from Bitcoin key; data from validateaddress
123123
Test {
@@ -161,8 +161,8 @@ mod tests {
161161
#[cfg(feature = "serde")]
162162
#[test]
163163
fn ripemd_serde() {
164-
165164
use serde_test::{Configure, Token, assert_tokens};
165+
use {hash160, Hash};
166166

167167
static HASH_BYTES: [u8; 20] = [
168168
0x13, 0x20, 0x72, 0xdf,

src/hex.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ mod tests {
274274
use core::fmt;
275275

276276
#[test]
277+
#[cfg(any(feature = "std", feature = "alloc"))]
277278
fn hex_roundtrip() {
278279
let expected = "0123456789abcdef";
279280
let expected_up = "0123456789ABCDEF";
@@ -361,6 +362,7 @@ mod tests {
361362
}
362363

363364
#[test]
365+
#[cfg(any(feature = "std", feature = "alloc"))]
364366
fn hex_error() {
365367
let oddlen = "0123456789abcdef0";
366368
let badchar1 = "Z123456789abcdef";

src/hmac.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,18 @@ impl<'de, T: HashTrait + Deserialize<'de>> Deserialize<'de> for Hmac<T> {
239239

240240
#[cfg(test)]
241241
mod tests {
242-
use sha256;
243-
#[cfg(feature = "serde")] use sha512;
244-
use {Hash, HashEngine, Hmac, HmacEngine};
245-
246-
#[derive(Clone)]
247-
struct Test {
248-
key: Vec<u8>,
249-
input: Vec<u8>,
250-
output: Vec<u8>,
251-
}
252-
253242
#[test]
243+
#[cfg(any(feature = "std", feature = "alloc"))]
254244
fn test() {
245+
use {sha256, HashEngine, HmacEngine, Hash, Hmac};
246+
247+
#[derive(Clone)]
248+
struct Test {
249+
key: Vec<u8>,
250+
input: Vec<u8>,
251+
output: Vec<u8>,
252+
}
253+
255254
let tests = vec![
256255
// Test vectors copied from libsecp256k1
257256
// Sadly the RFC2104 test vectors all use MD5 as their underlying hash function,
@@ -369,6 +368,7 @@ mod tests {
369368
#[test]
370369
fn hmac_sha512_serde() {
371370
use serde_test::{Configure, Token, assert_tokens};
371+
use {sha512, Hash, Hmac};
372372

373373
static HASH_BYTES: [u8; 64] = [
374374
0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21,

src/ripemd160.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -459,20 +459,20 @@ impl HashEngine {
459459

460460
#[cfg(test)]
461461
mod tests {
462-
use ripemd160;
463-
use hex::{FromHex, ToHex};
464-
use Hash;
465-
use HashEngine;
466-
467-
#[derive(Clone)]
468-
struct Test {
469-
input: &'static str,
470-
output: Vec<u8>,
471-
output_str: &'static str,
472-
}
473-
474462
#[test]
463+
#[cfg(any(feature = "std", feature = "alloc"))]
475464
fn test() {
465+
use ripemd160;
466+
use {Hash, HashEngine};
467+
use hex::{FromHex, ToHex};
468+
469+
#[derive(Clone)]
470+
struct Test {
471+
input: &'static str,
472+
output: Vec<u8>,
473+
output_str: &'static str,
474+
}
475+
476476
let tests = vec![
477477
// Test messages from FIPS 180-1
478478
Test {
@@ -545,6 +545,7 @@ mod tests {
545545
#[test]
546546
fn ripemd_serde() {
547547
use serde_test::{Configure, Token, assert_tokens};
548+
use {ripemd160, Hash};
548549

549550
static HASH_BYTES: [u8; 20] = [
550551
0x13, 0x20, 0x72, 0xdf,

src/sha1.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,20 @@ impl HashEngine {
197197

198198
#[cfg(test)]
199199
mod tests {
200-
use sha1;
201-
use hex::{FromHex, ToHex};
202-
use Hash;
203-
use HashEngine;
204-
205-
#[derive(Clone)]
206-
struct Test {
207-
input: &'static str,
208-
output: Vec<u8>,
209-
output_str: &'static str,
210-
}
211-
212200
#[test]
201+
#[cfg(any(feature = "std", feature = "alloc"))]
213202
fn test() {
203+
use {sha1, Hash, HashEngine};
204+
use hex::{FromHex, ToHex};
205+
206+
#[derive(Clone)]
207+
struct Test {
208+
input: &'static str,
209+
output: Vec<u8>,
210+
output_str: &'static str,
211+
}
212+
213+
214214
let tests = vec![
215215
// Examples from wikipedia
216216
Test {
@@ -270,6 +270,7 @@ mod tests {
270270
#[test]
271271
fn sha1_serde() {
272272
use serde_test::{Configure, Token, assert_tokens};
273+
use {sha1, Hash};
273274

274275
static HASH_BYTES: [u8; 20] = [
275276
0x13, 0x20, 0x72, 0xdf,

src/sha256.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,18 +373,20 @@ impl HashEngine {
373373
#[cfg(test)]
374374
mod tests {
375375
use sha256;
376-
use hex::{FromHex, ToHex};
377376
use {Hash, HashEngine};
378377

379-
#[derive(Clone)]
380-
struct Test {
381-
input: &'static str,
382-
output: Vec<u8>,
383-
output_str: &'static str,
384-
}
385-
386378
#[test]
379+
#[cfg(any(feature = "std", feature = "alloc"))]
387380
fn test() {
381+
use hex::{FromHex, ToHex};
382+
383+
#[derive(Clone)]
384+
struct Test {
385+
input: &'static str,
386+
output: Vec<u8>,
387+
output_str: &'static str,
388+
}
389+
388390
let tests = vec![
389391
// Examples from wikipedia
390392
Test {

src/sha256d.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,19 @@ impl HashTrait for Hash {
100100

101101
#[cfg(test)]
102102
mod tests {
103-
use sha256d;
104-
use hex::{FromHex, ToHex};
105-
use Hash;
106-
use HashEngine;
107-
108-
#[derive(Clone)]
109-
struct Test {
110-
input: &'static str,
111-
output: Vec<u8>,
112-
output_str: &'static str,
113-
}
114-
115103
#[test]
104+
#[cfg(any(feature = "std", feature = "alloc"))]
116105
fn test() {
106+
use {sha256d, Hash, HashEngine};
107+
use hex::{FromHex, ToHex};
108+
109+
#[derive(Clone)]
110+
struct Test {
111+
input: &'static str,
112+
output: Vec<u8>,
113+
output_str: &'static str,
114+
}
115+
117116
let tests = vec![
118117
// Test vector copied out of rust-bitcoin
119118
Test {
@@ -150,6 +149,7 @@ mod tests {
150149
#[test]
151150
fn sha256_serde() {
152151
use serde_test::{Configure, Token, assert_tokens};
152+
use {sha256d, Hash};
153153

154154
static HASH_BYTES: [u8; 32] = [
155155
0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7,

src/sha256t.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ impl<'de, T: Tag> ::serde::Deserialize<'de> for Hash<T> {
246246
#[cfg(test)]
247247
mod tests {
248248
use ::{Hash, sha256, sha256t};
249+
#[cfg(any(feature = "std", feature = "alloc"))]
249250
use ::hex::ToHex;
250251

251252
const TEST_MIDSTATE: [u8; 32] = [
@@ -266,11 +267,13 @@ mod tests {
266267
}
267268

268269
/// A hash tagged with `$name`.
270+
#[cfg(any(feature = "std", feature = "alloc"))]
269271
pub type TestHash = sha256t::Hash<TestHashTag>;
270272

271273
sha256t_hash_newtype!(NewTypeHash, NewTypeTag, TEST_MIDSTATE, 64, doc="test hash", true);
272274

273275
#[test]
276+
#[cfg(any(feature = "std", feature = "alloc"))]
274277
fn test_sha256t() {
275278
assert_eq!(
276279
TestHash::hash(&[0]).to_hex(),

0 commit comments

Comments
 (0)