Repository: alex/rust-asn1 (language: rust)

Issue:
Running the test with `--no-default-features` fails - Tests aren't feature gated.
Currently running the tests with `--no-default-features` fails:

```
$ cargo test --no-default-features
    Updating crates.io index
   Compiling autocfg v1.1.0
   Compiling libc v0.2.136
   Compiling num-traits v0.2.15
   Compiling num-integer v0.1.45
   Compiling chrono v0.4.22
   Compiling asn1 v0.12.2 (/tmp/rust-asn1)
error[E0433]: failed to resolve: use of undeclared crate or module `std`
    --> src/types.rs:1473:9
     |
1473 |     use std::collections::hash_map::DefaultHasher;
     |         ^^^ use of undeclared crate or module `std`

error[E0433]: failed to resolve: use of undeclared crate or module `std`
    --> src/types.rs:1474:9
     |
1474 |     use std::hash::{Hash, Hasher};
     |         ^^^ use of undeclared crate or module `std`

error: cannot find macro `vec` in this scope
    --> src/types.rs:1561:46
     |
1561 |         assert_eq!(seq2.collect::<Vec<_>>(), vec![2, 3]);
     |                                              ^^^
     |
     = note: consider importing one of these items:
             alloc::vec
             crate::types::vec

error: cannot find macro `vec` in this scope
    --> src/types.rs:1560:46
     |
1560 |         assert_eq!(seq1.collect::<Vec<_>>(), vec![2, 3]);
     |                                              ^^^
     |
     = note: consider importing one of these items:
             alloc::vec
             crate::types::vec

error: cannot find macro `format` in this scope
   --> src/parser.rs:465:25
    |
465 |             assert_eq!(&format!("{}", e), expected);
    |                         ^^^^^^
    |
    = note: consider importing this macro:
            alloc::format

error: cannot find macro `format` in this scope
   --> src/parser.rs:411:25
    |
411 |             assert_eq!(&format!("{:?}", e), expected);
    |                         ^^^^^^
    |
    = note: consider importing this macro:
            alloc::format

error: cannot find macro `vec` in this scope
  --> src/bit_string.rs:86:37
   |
86 |         assert!(OwnedBitString::new(vec![0xfe], 1).is_some());
   |                                     ^^^
   |
   = note: consider importing this macro:
           alloc::vec

error: cannot find macro `vec` in this scope
  --> src/bit_string.rs:85:37
   |
85 |         assert!(OwnedBitString::new(vec![0xff], 0).is_some());
   |                                     ^^^
   |
   = note: consider importing this macro:
           alloc::vec

error: cannot find macro `vec` in this scope
  --> src/bit_string.rs:83:40
   |
83 |         assert_eq!(OwnedBitString::new(vec![0xff], 1), None);
   |                                        ^^^
   |
   = note: consider importing this macro:
           alloc::vec

error: cannot find macro `vec` in this scope
  --> src/bit_string.rs:82:40
   |
82 |         assert_eq!(OwnedBitString::new(vec![], 2), None);
   |                                        ^^^
   |
   = note: consider importing this macro:
           alloc::vec

error: cannot find macro `vec` in this scope
  --> src/bit_string.rs:81:40
   |
81 |         assert_eq!(OwnedBitString::new(vec![b'a', b'b', b'c'], 8), None);
   |                                        ^^^
   |
   = note: consider importing this macro:
           alloc::vec

error[E0412]: cannot find type `Vec` in this scope
    --> src/types.rs:1560:35
     |
1560 |         assert_eq!(seq1.collect::<Vec<_>>(), vec![2, 3]);
     |                                   ^^^ not found in this scope
     |
help: consider importing one of these items
     |
1465 |     use alloc::vec::Vec;
     |
1465 |     use crate::types::vec::Vec;
     |

error[E0412]: cannot find type `Vec` in this scope
    --> src/types.rs:1561:35
     |
1561 |         assert_eq!(seq2.collect::<Vec<_>>(), vec![2, 3]);
     |                                   ^^^ not found in this scope
     |
help: consider importing one of these items
     |
1465 |     use alloc::vec::Vec;
     |
1465 |     use crate::types::vec::Vec;
     |

error[E0412]: cannot find type `Vec` in this scope
   --> src/writer.rs:537:46
    |
537 |         assert_writes::<SequenceOfWriter<u8, Vec<u8>>>(&[
    |                                              ^^^ not found in this scope
    |
help: consider importing one of these items
    |
203 |     use alloc::vec::Vec;
    |
203 |     use crate::writer::Vec;
    |

Some errors have detailed explanations: E0412, E0433.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `asn1` due to 14 previous errors
warning: build failed, waiting for other jobs to finish...
```


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 0b25d45..c5c2929 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -96,7 +96,7 @@ jobs:
       - run: cargo test ${{ matrix.RUST.FLAGS }}
         if: "${{ !matrix.RUST.SKIP_TESTS }}"
 
-      - run: cargo check ${{ matrix.RUST.FLAGS }}
+      - run: cargo check --tests ${{ matrix.RUST.FLAGS }}
 
   coverage:
     runs-on: ubuntu-latest
diff --git a/src/bit_string.rs b/src/bit_string.rs
index e3f60c1..fbac572 100644
--- a/src/bit_string.rs
+++ b/src/bit_string.rs
@@ -65,6 +65,7 @@ impl OwnedBitString {
 #[cfg(test)]
 mod tests {
     use crate::{BitString, OwnedBitString};
+    use alloc::vec;
 
     #[test]
     fn test_bitstring_new() {
diff --git a/src/object_identifier.rs b/src/object_identifier.rs
index b9726ed..f5ea90f 100644
--- a/src/object_identifier.rs
+++ b/src/object_identifier.rs
@@ -114,6 +114,7 @@ impl fmt::Display for ObjectIdentifier {
 #[cfg(test)]
 mod tests {
     use super::MAX_OID_LENGTH;
+    use crate::alloc::string::ToString;
     use crate::{ObjectIdentifier, ParseError, ParseErrorKind};
 
     #[test]
diff --git a/src/parser.rs b/src/parser.rs
index df7980e..005677c 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -350,7 +350,7 @@ mod tests {
     };
     #[cfg(feature = "const-generics")]
     use crate::{Explicit, Implicit};
-    use alloc::vec;
+    use alloc::{format, vec};
     use chrono::{TimeZone, Utc};
     use core::fmt;
 
diff --git a/src/types.rs b/src/types.rs
index 0ebe160..0427dd8 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -1469,9 +1469,13 @@ mod tests {
     };
     #[cfg(feature = "const-generics")]
     use crate::{Explicit, Implicit};
+    use alloc::vec;
+    use alloc::vec::Vec;
     use chrono::{TimeZone, Utc};
+    #[cfg(feature = "std")]
+    use core::hash::{Hash, Hasher};
+    #[cfg(feature = "std")]
     use std::collections::hash_map::DefaultHasher;
-    use std::hash::{Hash, Hasher};
 
     #[test]
     fn test_printable_string_new() {
@@ -1582,6 +1586,7 @@ mod tests {
         assert!(!seq2.is_empty());
     }
 
+    #[cfg(feature = "std")]
     fn hash<T: Hash>(v: &T) -> u64 {
         let mut h = DefaultHasher::new();
         v.hash(&mut h);
@@ -1589,40 +1594,64 @@ mod tests {
     }
 
     #[test]
-    fn test_set_of_eq_hash() {
+    fn test_set_of_eq() {
         let s1 = SetOf::<bool>::new(b"");
         let s2 = SetOf::<bool>::new(b"");
         let s3 = SetOf::<bool>::new(b"\x01\x01\x00");
         let s4 = SetOf::<bool>::new(b"\x01\x01\xff");
 
         assert!(s1 == s2);
-        assert_eq!(hash(&s1), hash(&s2));
 
         assert!(s2 != s3);
-        assert_ne!(hash(&s2), hash(&s3));
 
         assert!(s3 == s3);
 
         assert!(s3 != s4);
+    }
+
+    #[cfg(feature = "std")]
+    #[test]
+    fn test_set_of_hash() {
+        let s1 = SetOf::<bool>::new(b"");
+        let s2 = SetOf::<bool>::new(b"");
+        let s3 = SetOf::<bool>::new(b"\x01\x01\x00");
+        let s4 = SetOf::<bool>::new(b"\x01\x01\xff");
+
+        assert_eq!(hash(&s1), hash(&s2));
+
+        assert_ne!(hash(&s2), hash(&s3));
+
         assert_ne!(hash(&s3), hash(&s4));
     }
 
     #[test]
-    fn test_sequence_of_eq_hash() {
+    fn test_sequence_of_eq() {
         let s1 = SequenceOf::<bool>::new(b"").unwrap();
         let s2 = SequenceOf::<bool>::new(b"").unwrap();
         let s3 = SequenceOf::<bool>::new(b"\x01\x01\x00").unwrap();
         let s4 = SequenceOf::<bool>::new(b"\x01\x01\xff").unwrap();
 
         assert!(s1 == s2);
-        assert_eq!(hash(&s1), hash(&s2));
 
         assert!(s2 != s3);
-        assert_ne!(hash(&s2), hash(&s3));
 
         assert!(s3 == s3);
 
         assert!(s3 != s4);
+    }
+
+    #[cfg(feature = "std")]
+    #[test]
+    fn test_sequence_of_hash() {
+        let s1 = SequenceOf::<bool>::new(b"").unwrap();
+        let s2 = SequenceOf::<bool>::new(b"").unwrap();
+        let s3 = SequenceOf::<bool>::new(b"\x01\x01\x00").unwrap();
+        let s4 = SequenceOf::<bool>::new(b"\x01\x01\xff").unwrap();
+
+        assert_eq!(hash(&s1), hash(&s2));
+
+        assert_ne!(hash(&s2), hash(&s3));
+
         assert_ne!(hash(&s3), hash(&s4));
     }
 
diff --git a/src/writer.rs b/src/writer.rs
index 5d19292..cd7d260 100644
--- a/src/writer.rs
+++ b/src/writer.rs
@@ -214,6 +214,7 @@ mod tests {
     };
     #[cfg(feature = "const-generics")]
     use crate::{Explicit, Implicit};
+    use alloc::vec::Vec;
 
     fn assert_writes<T>(data: &[(T, &[u8])])
     where


Test patch: