Skip to content

Commit 5147cac

Browse files
authored
ensure tests compile with --no-default-features (#338)
note that the tests cannot actually be _run_ under `#![no_std]` because the test runner doesn't support it, but now they at least type check fixes #336
1 parent 14678b1 commit 5147cac

File tree

6 files changed

+41
-9
lines changed

6 files changed

+41
-9
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
- run: cargo test ${{ matrix.RUST.FLAGS }}
9797
if: "${{ !matrix.RUST.SKIP_TESTS }}"
9898

99-
- run: cargo check ${{ matrix.RUST.FLAGS }}
99+
- run: cargo check --tests ${{ matrix.RUST.FLAGS }}
100100

101101
coverage:
102102
runs-on: ubuntu-latest

src/bit_string.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ impl OwnedBitString {
6565
#[cfg(test)]
6666
mod tests {
6767
use crate::{BitString, OwnedBitString};
68+
use alloc::vec;
6869

6970
#[test]
7071
fn test_bitstring_new() {

src/object_identifier.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ impl fmt::Display for ObjectIdentifier {
114114
#[cfg(test)]
115115
mod tests {
116116
use super::MAX_OID_LENGTH;
117+
use crate::alloc::string::ToString;
117118
use crate::{ObjectIdentifier, ParseError, ParseErrorKind};
118119

119120
#[test]

src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ mod tests {
350350
};
351351
#[cfg(feature = "const-generics")]
352352
use crate::{Explicit, Implicit};
353-
use alloc::vec;
353+
use alloc::{format, vec};
354354
use chrono::{TimeZone, Utc};
355355
use core::fmt;
356356

src/types.rs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,9 +1469,13 @@ mod tests {
14691469
};
14701470
#[cfg(feature = "const-generics")]
14711471
use crate::{Explicit, Implicit};
1472+
use alloc::vec;
1473+
use alloc::vec::Vec;
14721474
use chrono::{TimeZone, Utc};
1475+
#[cfg(feature = "std")]
1476+
use core::hash::{Hash, Hasher};
1477+
#[cfg(feature = "std")]
14731478
use std::collections::hash_map::DefaultHasher;
1474-
use std::hash::{Hash, Hasher};
14751479

14761480
#[test]
14771481
fn test_printable_string_new() {
@@ -1582,47 +1586,72 @@ mod tests {
15821586
assert!(!seq2.is_empty());
15831587
}
15841588

1589+
#[cfg(feature = "std")]
15851590
fn hash<T: Hash>(v: &T) -> u64 {
15861591
let mut h = DefaultHasher::new();
15871592
v.hash(&mut h);
15881593
h.finish()
15891594
}
15901595

15911596
#[test]
1592-
fn test_set_of_eq_hash() {
1597+
fn test_set_of_eq() {
15931598
let s1 = SetOf::<bool>::new(b"");
15941599
let s2 = SetOf::<bool>::new(b"");
15951600
let s3 = SetOf::<bool>::new(b"\x01\x01\x00");
15961601
let s4 = SetOf::<bool>::new(b"\x01\x01\xff");
15971602

15981603
assert!(s1 == s2);
1599-
assert_eq!(hash(&s1), hash(&s2));
16001604

16011605
assert!(s2 != s3);
1602-
assert_ne!(hash(&s2), hash(&s3));
16031606

16041607
assert!(s3 == s3);
16051608

16061609
assert!(s3 != s4);
1610+
}
1611+
1612+
#[cfg(feature = "std")]
1613+
#[test]
1614+
fn test_set_of_hash() {
1615+
let s1 = SetOf::<bool>::new(b"");
1616+
let s2 = SetOf::<bool>::new(b"");
1617+
let s3 = SetOf::<bool>::new(b"\x01\x01\x00");
1618+
let s4 = SetOf::<bool>::new(b"\x01\x01\xff");
1619+
1620+
assert_eq!(hash(&s1), hash(&s2));
1621+
1622+
assert_ne!(hash(&s2), hash(&s3));
1623+
16071624
assert_ne!(hash(&s3), hash(&s4));
16081625
}
16091626

16101627
#[test]
1611-
fn test_sequence_of_eq_hash() {
1628+
fn test_sequence_of_eq() {
16121629
let s1 = SequenceOf::<bool>::new(b"").unwrap();
16131630
let s2 = SequenceOf::<bool>::new(b"").unwrap();
16141631
let s3 = SequenceOf::<bool>::new(b"\x01\x01\x00").unwrap();
16151632
let s4 = SequenceOf::<bool>::new(b"\x01\x01\xff").unwrap();
16161633

16171634
assert!(s1 == s2);
1618-
assert_eq!(hash(&s1), hash(&s2));
16191635

16201636
assert!(s2 != s3);
1621-
assert_ne!(hash(&s2), hash(&s3));
16221637

16231638
assert!(s3 == s3);
16241639

16251640
assert!(s3 != s4);
1641+
}
1642+
1643+
#[cfg(feature = "std")]
1644+
#[test]
1645+
fn test_sequence_of_hash() {
1646+
let s1 = SequenceOf::<bool>::new(b"").unwrap();
1647+
let s2 = SequenceOf::<bool>::new(b"").unwrap();
1648+
let s3 = SequenceOf::<bool>::new(b"\x01\x01\x00").unwrap();
1649+
let s4 = SequenceOf::<bool>::new(b"\x01\x01\xff").unwrap();
1650+
1651+
assert_eq!(hash(&s1), hash(&s2));
1652+
1653+
assert_ne!(hash(&s2), hash(&s3));
1654+
16261655
assert_ne!(hash(&s3), hash(&s4));
16271656
}
16281657

src/writer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ mod tests {
214214
};
215215
#[cfg(feature = "const-generics")]
216216
use crate::{Explicit, Implicit};
217+
use alloc::vec::Vec;
217218

218219
fn assert_writes<T>(data: &[(T, &[u8])])
219220
where

0 commit comments

Comments
 (0)