Skip to content

Commit 1c850ce

Browse files
committed
ci: Run most tests with miri
This PR additionally reduces the size of some heavy tests to reduce their running time. We use nextest as our runner because it runs tests in parallel. However, since nextest does not currenlty run doc tests, we also run those separately.
1 parent 9f5256f commit 1c850ce

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

.github/workflows/ci.yml

+15
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ jobs:
5454
- uses: dtolnay/rust-toolchain@stable
5555
- run: cargo test --all-features
5656

57+
miri:
58+
runs-on: ubuntu-latest
59+
env:
60+
CARGO_TERM_COLOR: always
61+
steps:
62+
- uses: actions/checkout@v4
63+
- uses: dtolnay/rust-toolchain@master
64+
with:
65+
toolchain: nightly
66+
components: miri
67+
- uses: taiki-e/install-action@nextest
68+
- run: |
69+
cargo miri nextest run --all-features
70+
cargo miri test --doc
71+
5772
check-format:
5873
name: check format
5974
runs-on: ubuntu-latest

tests/quick.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
//! and adaptors.
33
//!
44
//! In particular we test the tedious size_hint and exact size correctness.
5+
//!
6+
//! **NOTE:** Due to performance limitations, these tests are not run with miri!
7+
//! They cannot be relied upon to discover soundness issues.
58
9+
#![cfg(not(miri))]
610
#![allow(deprecated, unstable_name_collisions)]
711

812
use itertools::free::{

tests/specializations.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
//! Test specializations of methods with default impls match the behavior of the
2+
//! default impls.
3+
//!
4+
//! **NOTE:** Due to performance limitations, these tests are not run with miri!
5+
//! They cannot be relied upon to discover soundness issues.
6+
7+
#![cfg(not(miri))]
18
#![allow(unstable_name_collisions)]
29

310
use itertools::Itertools;

tests/test_std.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ fn sorted_by() {
491491
it::assert_equal(v, vec![4, 3, 2, 1, 0]);
492492
}
493493

494+
#[cfg(not(miri))]
494495
qc::quickcheck! {
495496
fn k_smallest_range(n: i64, m: u16, k: u16) -> () {
496497
// u16 is used to constrain k and m to 0..2¹⁶,
@@ -598,7 +599,9 @@ macro_rules! generic_test {
598599
};
599600
}
600601

602+
#[cfg(not(miri))]
601603
generic_test!(k_smallest_sort, u8, u16, u32, u64, i8, i16, i32, i64);
604+
#[cfg(not(miri))]
602605
generic_test!(k_smallest_by_sort, u8, u16, u32, u64, i8, i16, i32, i64);
603606

604607
#[test]
@@ -1055,8 +1058,8 @@ fn binomial(n: usize, k: usize) -> usize {
10551058

10561059
#[test]
10571060
fn combinations_range_count() {
1058-
for n in 0..=10 {
1059-
for k in 0..=10 {
1061+
for n in 0..=7 {
1062+
for k in 0..=7 {
10601063
let len = binomial(n, k);
10611064
let mut it = (0..n).combinations(k);
10621065
assert_eq!(len, it.clone().count());
@@ -1077,7 +1080,7 @@ fn combinations_range_count() {
10771080

10781081
#[test]
10791082
fn combinations_inexact_size_hints() {
1080-
for k in 0..=10 {
1083+
for k in 0..=7 {
10811084
let mut numbers = (0..18).filter(|i| i % 2 == 0); // 9 elements
10821085
let mut it = numbers.clone().combinations(k);
10831086
let real_n = numbers.clone().count();
@@ -1129,8 +1132,8 @@ fn permutations_zero() {
11291132

11301133
#[test]
11311134
fn permutations_range_count() {
1132-
for n in 0..=7 {
1133-
for k in 0..=7 {
1135+
for n in 0..=4 {
1136+
for k in 0..=4 {
11341137
let len = if k <= n { (n - k + 1..=n).product() } else { 0 };
11351138
let mut it = (0..n).permutations(k);
11361139
assert_eq!(len, it.clone().count());
@@ -1162,6 +1165,7 @@ fn permutations_overflowed_size_hints() {
11621165
}
11631166

11641167
#[test]
1168+
#[cfg(not(miri))]
11651169
fn combinations_with_replacement() {
11661170
// Pool smaller than n
11671171
it::assert_equal((0..1).combinations_with_replacement(2), vec![vec![0, 0]]);
@@ -1190,8 +1194,8 @@ fn combinations_with_replacement() {
11901194

11911195
#[test]
11921196
fn combinations_with_replacement_range_count() {
1193-
for n in 0..=7 {
1194-
for k in 0..=7 {
1197+
for n in 0..=4 {
1198+
for k in 0..=4 {
11951199
let len = binomial(usize::saturating_sub(n + k, 1), k);
11961200
let mut it = (0..n).combinations_with_replacement(k);
11971201
assert_eq!(len, it.clone().count());
@@ -1236,7 +1240,7 @@ fn powerset() {
12361240
assert_eq!((0..8).powerset().count(), 1 << 8);
12371241
assert_eq!((0..16).powerset().count(), 1 << 16);
12381242

1239-
for n in 0..=10 {
1243+
for n in 0..=4 {
12401244
let mut it = (0..n).powerset();
12411245
let len = 2_usize.pow(n);
12421246
assert_eq!(len, it.clone().count());

0 commit comments

Comments
 (0)