Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use check --all-targets for test in helper #352

Merged
merged 4 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/api-desc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

### Patch

- Fix clippy lint
- Make sure enum values don't skip any value, essentially mapping to `0..N`
- Use `*const void` instead of `*const u8` for opaque data
- Update dependencies
Expand Down
2 changes: 1 addition & 1 deletion crates/api-desc/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ mod tests {
fn name_new() {
#[track_caller]
fn test(expected: Option<&[u8; 6]>, name: &str) {
let expected = expected.map(|x| *x);
let expected = expected.copied();
let actual = Name::new(name).map(|x| x.0);
assert_eq!(actual, expected);
}
Expand Down
5 changes: 3 additions & 2 deletions crates/interpreter/tests/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ use wast::{parser, QuoteWat, Wast, WastArg, WastDirective, WastExecute, WastInvo

fn test(name: &str) {
let path = format!("../../third_party/WebAssembly/spec/test/core/{}.wast", name);
let content = std::fs::read_to_string(&path).unwrap();
let content = std::fs::read_to_string(path).unwrap();
let mut lexer = Lexer::new(&content);
lexer.allow_confusing_unicode(true);
let buffer = parser::ParseBuffer::new_with_lexer(lexer).unwrap();
let wast: Wast = parser::parse(&buffer).unwrap();
let layout = std::alloc::Layout::from_size_align(pool_size(name), MEMORY_ALIGN).unwrap();
let pool = unsafe { std::slice::from_raw_parts_mut(std::alloc::alloc(layout), layout.size()) };
let mut env = Env::new(pool);
env.instantiate("spectest", &*SPECTEST);
env.instantiate("spectest", &SPECTEST);
env.register_name("spectest", None);
assert!(env.inst.is_ok());
for directive in wast.directives {
Expand Down Expand Up @@ -173,6 +173,7 @@ lazy_static! {
static ref SPECTEST: Vec<u8> = spectest();
}

#[allow(clippy::vec_init_then_push)]
fn spectest() -> Vec<u8> {
let leb128 = |wasm: &mut Vec<u8>, mut x: usize| {
assert!(x <= u32::MAX as usize);
Expand Down
1 change: 1 addition & 0 deletions crates/store/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Patch

- Fix lints
- Fix lints
- Update dependencies

Expand Down
1 change: 1 addition & 0 deletions crates/store/fuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ fn read_bits_ok() {
assert_eq!(entropy.read_bits(2), 0b10);
}

#[allow(clippy::identity_op)]
#[test]
fn read_range_ok() {
let mut entropy = Entropy::new(&[0b00101011]);
Expand Down
10 changes: 4 additions & 6 deletions crates/store/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,12 @@ mod tests {
tmp_dir.into_path()
}

fn remove_tmp_dir(tmp_dir: PathBuf) {
fn remove_tmp_dir(tmp_dir: &Path) {
std::fs::remove_dir_all(tmp_dir).unwrap();
}

fn temp_storage(tmp_dir: &PathBuf) -> FileStorage {
let mut tmp_file = tmp_dir.clone();
tmp_file.push(FILE_NAME);
FileStorage::new(&tmp_file, OPTIONS).unwrap()
fn temp_storage(tmp_dir: &Path) -> FileStorage {
FileStorage::new(&tmp_dir.join(FILE_NAME), OPTIONS).unwrap()
}

#[test]
Expand All @@ -175,6 +173,6 @@ mod tests {
assert_eq!(file_storage.read_slice(index, 4).unwrap(), DATA_WORD);
assert_eq!(file_storage.read_slice(next_index, 4).unwrap(), BLANK_WORD);
}
remove_tmp_dir(tmp_dir);
remove_tmp_dir(&tmp_dir);
}
}
14 changes: 3 additions & 11 deletions crates/store/tests/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ fn interrupted_overflowing_compaction() {
.partial_apply(StoreOperation::Prepare { length: 1 }, StoreInterruption::pure(1))
{
Ok((None, d)) => driver = d.power_on().unwrap(),
_ => {
assert!(false);
return;
}
_ => panic!(),
}
}
}
Expand Down Expand Up @@ -103,15 +100,13 @@ fn full_compaction_with_max_prefix() {

// We fill the store with non-deleted entries making sure the last entry always overlaps the
// next page with m words for the first 3 pages.
let mut k = 0;
for _ in 0 .. c {
for k in 0 .. c {
let tail = get_tail(&driver);
if tail % q == q - 1 && tail < 4 * q {
driver.insert(k, &vec![0; max_value_len]).unwrap();
} else {
driver.insert(k, &[]).unwrap();
}
k += 1;
}
// We lost 1 word of lifetime because of compacting the first page.
check_lifetime(&driver, c + 1);
Expand All @@ -129,10 +124,7 @@ fn full_compaction_with_max_prefix() {
.partial_apply(StoreOperation::Clear { min_key: max_key }, StoreInterruption::pure(1))
{
Ok((None, d)) => driver = d.power_on().unwrap(),
_ => {
assert!(false);
return;
}
_ => panic!(),
}
}
check_lifetime(&mut driver, c + n - 1);
Expand Down
15 changes: 7 additions & 8 deletions scripts/test-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ ensure_submodule() {
}

test_helper() {
_test_desc_raw | grep -v -e '^$' -e '^#' -e 'cargo \(check\|test\)' \
_test_desc | grep -v -e '^$' -e '^#' -e 'cargo \(check\|test\)' \
&& e 'Invalid description (invalid commands are listed above).'
_test_desc '\(check\|test\)' check
_test_desc test test
_test_desc | _test_check | grep 'cargo check' | sh -ex
_test_desc | grep 'cargo test' | sh -ex
x cargo fmt -- --check
_test_desc '\(check\|test\)' clippy ' -- --deny=warnings'
_test_desc | _test_check | _test_clippy | grep 'cargo clippy' | sh -ex
if [ -e src/lib.rs -a "$(package_publish)" = true ]; then
features=$(package_doc_features | tr -d '[]" ')
[ -n "$features" ] && features="--features=$features"
Expand All @@ -54,10 +54,9 @@ test_helper() {
exit
}

_test_desc_raw() {
_test_desc() {
sed '0,/^test_helper$/d;:a;/\\$/{N;s/\\\n//;ta};s/ \+/ /g' "$SELF"
}

_test_desc() {
_test_desc_raw | sed -n "s/cargo $1/cargo $2/p" | sed "s/\$/$3/" | sh -ex
}
_test_check() { sed 's/cargo test/cargo check --all-targets/'; }
_test_clippy() { sed 's/cargo check/cargo clippy/;s/$/ -- --deny=warnings/'; }