Skip to content

Commit

Permalink
test: don't require alloc for no_std test (#146)
Browse files Browse the repository at this point in the history
Also run the no_std tests on CI.
  • Loading branch information
vmx authored Oct 17, 2023
1 parent 86c7912 commit 7f97c48
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ jobs:
run: cargo clippy --all-targets --all-features -- -D warnings
shell: bash

- name: Test --no-default-features
run: cargo test --no-default-features
shell: bash

- name: Test
run: cargo test --all-features
shell: bash
Expand Down
7 changes: 3 additions & 4 deletions tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;

#[cfg(feature = "std")]
mod std_tests {
use std::collections::HashMap;
Expand Down Expand Up @@ -215,14 +215,13 @@ mod std_tests {

#[cfg(all(test, not(feature = "std")))]
mod no_std_tests {
use alloc::vec;
use cid::Cid;

#[test]
fn validate_cid_unwrap_panics() {
// This should not panic, but should return an error.
// bad_cid created during fuzz testing
let bad_cid = vec![255, 255, 255, 255, 0, 6, 85, 0];
assert_eq!(Cid::read_bytes(&bad_cid[..]).is_ok(), false);
let bad_cid = [255, 255, 255, 255, 0, 6, 85, 0];
assert!(Cid::read_bytes(&bad_cid[..]).is_err());
}
}

0 comments on commit 7f97c48

Please sign in to comment.