From 4dec0966b0ffa27ddb053ad56183c0cd85f44612 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Tue, 8 Dec 2020 10:44:16 +0000 Subject: [PATCH 1/8] GitHub Actions: add GitHub pages deployment --- .github/workflows/gh-pages.yml | 29 +++++++++++++++++++++++++++++ .github/workflows/test.yml | 25 +++++++++++++++++++++++++ .travis.yml | 23 ----------------------- 3 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/gh-pages.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml new file mode 100644 index 00000000000..ad9b0943d4f --- /dev/null +++ b/.github/workflows/gh-pages.yml @@ -0,0 +1,29 @@ +name: gh-pages + +on: + push: + branches: + - master + +jobs: + deploy: + name: GH-pages documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + - name: doc (rand) + env: + RUSTDOCFLAGS: --cfg doc_cfg + # --all builds all crates, but with default features for other crates (okay in this case) + run: cargo doc --all --features nightly,serde1,getrandom,small_rng + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./target/doc diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000000..b1b51c22d89 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,25 @@ +name: Tests + +on: + push: + branches: [ master, '0.[0-9]+' ] + pull_request: + branches: [ master, '0.[0-9]+' ] + +jobs: + check-doc: + name: Check doc + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + run: cargo install cargo-deadlinks + - name: doc (rand) + env: RUSTDOCFLAGS: --cfg doc_cfg + # --all builds all crates, but with default features for other crates (okay in this case) + run: cargo deadlinks --ignore-fragments -- --all --features nightly,serde1,getrandom,small_rng diff --git a/.travis.yml b/.travis.yml index 35d755e3527..82093929ca7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,29 +25,6 @@ matrix: - rust: beta name: "Linux, beta" - - rust: nightly - os: linux - name: "Linux, nightly, docs" - env: NIGHTLY=1 - install: - - cargo --list | egrep "^\s*deadlinks$" -q || cargo install cargo-deadlinks - - cargo deadlinks -V - before_script: - - pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH - script: - - bash utils/ci/script.sh - # remove cached documentation, otherwise files from previous PRs can get included - - rm -rf target/doc - - cargo doc --no-deps --all --all-features - - cargo deadlinks --dir target/doc - deploy: - local_dir: target/doc - provider: pages - skip_cleanup: true - github_token: $GITHUB_TOKEN - on: - branch: master - # This target catches endianness issues - rust: stable sudo: required From 8caa86b666d7fae3c00be290f33771699e1d0a49 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Tue, 8 Dec 2020 11:56:08 +0000 Subject: [PATCH 2/8] Cargo.toml: remove [badges] sections According to the Cargo manifest, this section is not used and the README should be used for build status. --- Cargo.toml | 4 ---- rand_chacha/Cargo.toml | 4 ---- rand_core/Cargo.toml | 4 ---- rand_distr/Cargo.toml | 4 ---- rand_hc/Cargo.toml | 4 ---- rand_pcg/Cargo.toml | 4 ---- 6 files changed, 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9284f3084fd..b6e87bab282 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,10 +16,6 @@ autobenches = true edition = "2018" include = ["src/", "LICENSE-*", "README.md", "CHANGELOG.md", "COPYRIGHT"] -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - [features] # Meta-features: default = ["std", "std_rng"] diff --git a/rand_chacha/Cargo.toml b/rand_chacha/Cargo.toml index 2a17aa172bc..703cc86ac9b 100644 --- a/rand_chacha/Cargo.toml +++ b/rand_chacha/Cargo.toml @@ -14,10 +14,6 @@ keywords = ["random", "rng", "chacha"] categories = ["algorithms", "no-std"] edition = "2018" -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - [dependencies] rand_core = { path = "../rand_core", version = "0.5" } ppv-lite86 = { version = "0.2.8", default-features = false, features = ["simd"] } diff --git a/rand_core/Cargo.toml b/rand_core/Cargo.toml index 4b85940ff70..831562689dc 100644 --- a/rand_core/Cargo.toml +++ b/rand_core/Cargo.toml @@ -14,10 +14,6 @@ keywords = ["random", "rng"] categories = ["algorithms", "no-std"] edition = "2018" -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - [features] std = ["alloc", "getrandom", "getrandom/std"] # use std library; should be default but for above bug alloc = [] # enables Vec and Box support without std diff --git a/rand_distr/Cargo.toml b/rand_distr/Cargo.toml index fe40d179110..e6dc5462c24 100644 --- a/rand_distr/Cargo.toml +++ b/rand_distr/Cargo.toml @@ -15,10 +15,6 @@ categories = ["algorithms"] edition = "2018" include = ["src/", "LICENSE-*", "README.md", "CHANGELOG.md", "COPYRIGHT"] -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - [dependencies] rand = { path = "..", version = "0.7", default-features = false } num-traits = { version = "0.2", default-features = false, features = ["libm"] } diff --git a/rand_hc/Cargo.toml b/rand_hc/Cargo.toml index 84f53f80cdd..048f9aaa208 100644 --- a/rand_hc/Cargo.toml +++ b/rand_hc/Cargo.toml @@ -14,9 +14,5 @@ keywords = ["random", "rng", "hc128"] categories = ["algorithms", "no-std"] edition = "2018" -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - [dependencies] rand_core = { path = "../rand_core", version = "0.5" } diff --git a/rand_pcg/Cargo.toml b/rand_pcg/Cargo.toml index 9eb2eaf51e1..33e65c547dd 100644 --- a/rand_pcg/Cargo.toml +++ b/rand_pcg/Cargo.toml @@ -14,10 +14,6 @@ keywords = ["random", "rng", "pcg"] categories = ["algorithms", "no-std"] edition = "2018" -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - [features] serde1 = ["serde"] From 0f53b56870840168f79862651af67b3ac3899f04 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Tue, 8 Dec 2020 11:57:26 +0000 Subject: [PATCH 3/8] Update README files shields and doc --- README.md | 7 +++---- rand_chacha/README.md | 3 +-- rand_core/README.md | 3 +-- rand_distr/README.md | 3 +-- rand_hc/README.md | 3 +-- rand_pcg/README.md | 3 +-- 6 files changed, 8 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 6d1db896ddd..3ca09b008b7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # Rand -[![Build Status](https://travis-ci.org/rust-random/rand.svg?branch=master)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) +[![Test Status](https://github.com/rust-random/rand/workflows/Tests/badge.svg?event=push)](https://github.com/rust-random/rand/actions) [![Crate](https://img.shields.io/crates/v/rand.svg)](https://crates.io/crates/rand) [![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) [![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand) @@ -104,8 +103,8 @@ greater, and 0.4 and 0.3 (since approx. June 2017) require Rustc version 1.15 or greater. Subsets of the Rand code may work with older Rust versions, but this is not supported. -Travis CI always has a build with a pinned version of Rustc matching the oldest -supported Rust release. The current policy is that this can be updated in any +Continuous Integration (CI) will always test the oldest supported Rustc version +(the MSRV). The current policy is that this can be updated in any Rand release if required, but the change must be noted in the changelog. ## Crate Features diff --git a/rand_chacha/README.md b/rand_chacha/README.md index b1928fd9cc8..edd754d791e 100644 --- a/rand_chacha/README.md +++ b/rand_chacha/README.md @@ -1,7 +1,6 @@ # rand_chacha -[![Build Status](https://travis-ci.org/rust-random/rand.svg)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) +[![Test Status](https://github.com/rust-random/rand/workflows/Tests/badge.svg?event=push)](https://github.com/rust-random/rand/actions) [![Latest version](https://img.shields.io/crates/v/rand_chacha.svg)](https://crates.io/crates/rand_chacha) [![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) [![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_chacha) diff --git a/rand_core/README.md b/rand_core/README.md index 78c8083fc82..aaec728672c 100644 --- a/rand_core/README.md +++ b/rand_core/README.md @@ -1,7 +1,6 @@ # rand_core -[![Build Status](https://travis-ci.org/rust-random/rand.svg)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) +[![Test Status](https://github.com/rust-random/rand/workflows/Tests/badge.svg?event=push)](https://github.com/rust-random/rand/actions) [![Latest version](https://img.shields.io/crates/v/rand_core.svg)](https://crates.io/crates/rand_core) [![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) [![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_core) diff --git a/rand_distr/README.md b/rand_distr/README.md index 9a67e5b3f93..29b5fe0853e 100644 --- a/rand_distr/README.md +++ b/rand_distr/README.md @@ -1,7 +1,6 @@ # rand_distr -[![Build Status](https://travis-ci.org/rust-random/rand.svg?branch=master)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) +[![Test Status](https://github.com/rust-random/rand/workflows/Tests/badge.svg?event=push)](https://github.com/rust-random/rand/actions) [![Latest version](https://img.shields.io/crates/v/rand_distr.svg)](https://crates.io/crates/rand_distr) [[![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) [![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_distr) diff --git a/rand_hc/README.md b/rand_hc/README.md index 4d992fec0c5..87f1c8915c1 100644 --- a/rand_hc/README.md +++ b/rand_hc/README.md @@ -1,7 +1,6 @@ # rand_hc -[![Build Status](https://travis-ci.org/rust-random/rand.svg)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) +[![Test Status](https://github.com/rust-random/rand/workflows/Tests/badge.svg?event=push)](https://github.com/rust-random/rand/actions) [![Latest version](https://img.shields.io/crates/v/rand_hc.svg)](https://crates.io/crates/rand_hc) [[![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) [![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_hc) diff --git a/rand_pcg/README.md b/rand_pcg/README.md index 97204213c8d..736a789035c 100644 --- a/rand_pcg/README.md +++ b/rand_pcg/README.md @@ -1,7 +1,6 @@ # rand_pcg -[![Build Status](https://travis-ci.org/rust-random/rand.svg?branch=master)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) +[![Test Status](https://github.com/rust-random/rand/workflows/Tests/badge.svg?event=push)](https://github.com/rust-random/rand/actions) [![Latest version](https://img.shields.io/crates/v/rand_pcg.svg)](https://crates.io/crates/rand_pcg) [![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) [![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_pcg) From 9e7c010ddb6682274eb0e4f1d40d953aa63c07df Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Tue, 8 Dec 2020 12:50:16 +0000 Subject: [PATCH 4/8] Migrate tests to GH-Actions Incomplete: Linux 32-bit, Big-Endian, Web --- .github/workflows/test.yml | 109 +++++++++++++++++++++++++++++++++- .travis.yml | 92 ---------------------------- appveyor.yml | 48 --------------- utils/ci/install.sh | 49 --------------- utils/ci/install_cargo_web.sh | 15 ----- utils/ci/miri.sh | 18 ------ utils/ci/script.sh | 59 ------------------ 7 files changed, 107 insertions(+), 283 deletions(-) delete mode 100644 .travis.yml delete mode 100644 appveyor.yml delete mode 100644 utils/ci/install.sh delete mode 100755 utils/ci/install_cargo_web.sh delete mode 100644 utils/ci/miri.sh delete mode 100644 utils/ci/script.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b1b51c22d89..7f5bfc7d0fa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,8 +18,113 @@ jobs: profile: minimal toolchain: nightly override: true - run: cargo install cargo-deadlinks + - run: cargo install cargo-deadlinks - name: doc (rand) - env: RUSTDOCFLAGS: --cfg doc_cfg + env: + RUSTDOCFLAGS: --cfg doc_cfg # --all builds all crates, but with default features for other crates (okay in this case) run: cargo deadlinks --ignore-fragments -- --all --features nightly,serde1,getrandom,small_rng + + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + toolchain: [stable] + minimal: [false] + include: + - os: ubuntu-latest + toolchain: beta + - os: ubuntu-latest + toolchain: 1.36.0 + - os: ubuntu-latest + toolchain: nightly + - os: ubuntu-latest + toolchain: nightly + minimal: true + + steps: + - uses: actions/checkout@v2 + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.toolchain }} + override: true + - name: Maybe minimal + if: ${{ matrix.minimal }} + run: cargo generate-lockfile -Z minimal-versions + - name: Maybe nightly + if: ${{ matrix.toolchain == 'nightly' }} + run: | + cargo test --tests --features=nightly + cargo test --all-features + cargo test --benches --features=nightly + cargo test --manifest-path rand_distr/Cargo.toml --benches + - name: Test rand + run: | + cargo test --tests --no-default-features + cargo test --tests --no-default-features --features=alloc,getrandom,small_rng + # all stable features: + cargo test --features=serde1,log,small_rng + cargo test --examples + - name: Test rand_core + run: | + cargo test --manifest-path rand_core/Cargo.toml + cargo test --manifest-path rand_core/Cargo.toml --no-default-features + cargo test --manifest-path rand_core/Cargo.toml --no-default-features --features=alloc,getrandom + - name: Test rand_distr + run: cargo test --manifest-path rand_distr/Cargo.toml + - name: Test rand_pcg + run: cargo test --manifest-path rand_pcg/Cargo.toml --features=serde1 + - name: Test rand_chacha + run: cargo test --manifest-path rand_chacha/Cargo.toml + - name: Test rand_hc + run: cargo test --manifest-path rand_hc/Cargo.toml + + test-miri: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install toolchain + run: | + MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri) + rustup default "$MIRI_NIGHTLY" + rustup component add miri + - name: Test rand + run: | + cargo miri test --no-default-features + cargo miri test --features=log,small_rng + cargo miri test --manifest-path rand_core/Cargo.toml + cargo miri test --manifest-path rand_core/Cargo.toml --features=serde1 + cargo miri test --manifest-path rand_core/Cargo.toml --no-default-features + #cargo miri test --manifest-path rand_distr/Cargo.toml # no unsafe and lots of slow tests + cargo miri test --manifest-path rand_pcg/Cargo.toml --features=serde1 + cargo miri test --manifest-path rand_chacha/Cargo.toml --no-default-features + cargo miri test --manifest-path rand_hc/Cargo.toml + + test-no-std: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + target: thumbv6m-none-eabi + override: true + - name: Build top-level only + run: cargo build --target=thumbv6m-none-eabi --no-default-features + + test-ios: + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + target: aarch64-apple-ios + override: true + - name: Build top-level only + run: cargo build --target=aarch64-apple-ios diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 82093929ca7..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,92 +0,0 @@ -language: rust -sudo: false - -# Since most OS-specific code has moved to the getrandom crate, we require -# few target-specific tests here. - -matrix: - include: - - rust: 1.36.0 - name: "Linux, 1.36.0" - os: linux - - - rust: stable - name: "Linux, stable" - - - rust: stable - name: "OSX+iOS, stable" - os: osx - install: - - rustup target add aarch64-apple-ios - script: - - bash utils/ci/script.sh - - cargo build --target=aarch64-apple-ios - - - rust: beta - name: "Linux, beta" - - # This target catches endianness issues - - rust: stable - sudo: required - dist: trusty - services: docker - name: "Linux (MIPS, big-endian)" - env: TARGET=mips-unknown-linux-gnu - install: - - sh utils/ci/install.sh - - source ~/.cargo/env || true - - # This target checks we really can build no_std binaries - - rust: nightly - name: "no_std platform test" - install: - - rustup target add thumbv6m-none-eabi - script: - # Test the top-level crate with all features: - - cargo build --target=thumbv6m-none-eabi --no-default-features - - - rust: nightly - name: "Linux, nightly (32-bit test)" - env: TARGET=i686-unknown-linux-musl - install: - - rustup target add $TARGET - - - rust: nightly - os: linux - name: "Miri, nightly" - script: - - sh utils/ci/miri.sh - - - rust: nightly - os: linux - name: "Minimal dep versions" - script: - - cargo generate-lockfile -Z minimal-versions - - bash utils/ci/script.sh - -before_install: - - set -e - - rustup self update - -script: - - bash utils/ci/script.sh - -after_script: set +e - -# Cache: this seems to do more harm than good -#cache: - #cargo: true - #directories: - #- .local/share/cargo-web - -#before_cache: - ## Travis can't cache files that are not readable by "others" - #- chmod -R a+r $HOME/.cargo - -env: - global: - secure: "BdDntVHSompN+Qxz5Rz45VI4ZqhD72r6aPl166FADlnkIwS6N6FLWdqs51O7G5CpoMXEDvyYrjmRMZe/GYLIG9cmqmn/wUrWPO+PauGiIuG/D2dmfuUNvSTRcIe7UQLXrfP3yyfZPgqsH6pSnNEVopquQKy3KjzqepgriOJtbyY=" - -notifications: - email: - on_success: never diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index c7d35ef2b33..00000000000 --- a/appveyor.yml +++ /dev/null @@ -1,48 +0,0 @@ -environment: - - # At the time this was added AppVeyor was having troubles with checking - # revocation of SSL certificates of sites like static.rust-lang.org and what - # we think is crates.io. The libcurl HTTP client by default checks for - # revocation on Windows and according to a mailing list [1] this can be - # disabled. - # - # The `CARGO_HTTP_CHECK_REVOKE` env var here tells cargo to disable SSL - # revocation checking on Windows in libcurl. Note, though, that rustup, which - # we're using to download Rust here, also uses libcurl as the default backend. - # Unlike Cargo, however, rustup doesn't have a mechanism to disable revocation - # checking. To get rustup working we set `RUSTUP_USE_HYPER` which forces it to - # use the Hyper instead of libcurl backend. Both Hyper and libcurl use - # schannel on Windows but it appears that Hyper configures it slightly - # differently such that revocation checking isn't turned on by default. - # - # [1]: https://curl.haxx.se/mail/lib-2016-03/0202.html - RUSTUP_USE_HYPER: 1 - CARGO_HTTP_CHECK_REVOKE: false - - matrix: - - TARGET: x86_64-pc-windows-msvc - - TARGET: i686-pc-windows-msvc -install: - - appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe - - rustup-init.exe -y --default-host %TARGET% --default-toolchain nightly - - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin - - rustc -V - - cargo -V - -build: false - -test_script: - - cargo test --tests --no-default-features - - cargo test --tests --no-default-features --features=alloc,getrandom - - cargo test --features simd_support - # all stable features: - - cargo test --features=serde1,log - - cargo test --benches --features=nightly - - cargo test --examples - - cargo test --manifest-path rand_core/Cargo.toml - - cargo test --manifest-path rand_core/Cargo.toml --no-default-features - - cargo test --manifest-path rand_core/Cargo.toml --no-default-features --features=alloc - - cargo test --manifest-path rand_distr/Cargo.toml - - cargo test --manifest-path rand_pcg/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_chacha/Cargo.toml - - cargo test --manifest-path rand_hc/Cargo.toml diff --git a/utils/ci/install.sh b/utils/ci/install.sh deleted file mode 100644 index 8e636e18175..00000000000 --- a/utils/ci/install.sh +++ /dev/null @@ -1,49 +0,0 @@ -# From https://github.com/japaric/trust - -set -ex - -main() { - local target= - if [ $TRAVIS_OS_NAME = linux ]; then - target=x86_64-unknown-linux-musl - sort=sort - else - target=x86_64-apple-darwin - sort=gsort # for `sort --sort-version`, from brew's coreutils. - fi - - # Builds for iOS are done on OSX, but require the specific target to be - # installed. - case $TARGET in - aarch64-apple-ios) - rustup target install aarch64-apple-ios - ;; - armv7-apple-ios) - rustup target install armv7-apple-ios - ;; - armv7s-apple-ios) - rustup target install armv7s-apple-ios - ;; - i386-apple-ios) - rustup target install i386-apple-ios - ;; - x86_64-apple-ios) - rustup target install x86_64-apple-ios - ;; - esac - - # This fetches latest stable release - local tag=$(git ls-remote --tags --refs --exit-code https://github.com/japaric/cross \ - | cut -d/ -f3 \ - | grep -E '^v[0.1.0-9.]+$' \ - | $sort --version-sort \ - | tail -n1) - curl -LSfs https://japaric.github.io/trust/install.sh | \ - sh -s -- \ - --force \ - --git japaric/cross \ - --tag $tag \ - --target $target -} - -main diff --git a/utils/ci/install_cargo_web.sh b/utils/ci/install_cargo_web.sh deleted file mode 100755 index b35f0691984..00000000000 --- a/utils/ci/install_cargo_web.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -euo pipefail -IFS=$'\n\t' - -CARGO_WEB_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/koute/cargo-web/releases/latest) -CARGO_WEB_VERSION=$(echo $CARGO_WEB_RELEASE | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/') -CARGO_WEB_URL="https://github.com/koute/cargo-web/releases/download/$CARGO_WEB_VERSION/cargo-web-x86_64-unknown-linux-gnu.gz" - -echo "Downloading cargo-web from: $CARGO_WEB_URL" -curl -L $CARGO_WEB_URL | gzip -d > cargo-web -chmod +x cargo-web - -mkdir -p ~/.cargo/bin -mv cargo-web ~/.cargo/bin diff --git a/utils/ci/miri.sh b/utils/ci/miri.sh deleted file mode 100644 index 7e06091ff32..00000000000 --- a/utils/ci/miri.sh +++ /dev/null @@ -1,18 +0,0 @@ -set -ex - -MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri) -echo "Installing latest nightly with Miri: $MIRI_NIGHTLY" -rustup default "$MIRI_NIGHTLY" - -rustup component add miri -cargo miri setup - -cargo miri test --no-default-features -cargo miri test --features=log -cargo miri test --manifest-path rand_core/Cargo.toml -cargo miri test --manifest-path rand_core/Cargo.toml --features=serde1 -cargo miri test --manifest-path rand_core/Cargo.toml --no-default-features -#cargo miri test --manifest-path rand_distr/Cargo.toml # no unsafe and lots of slow tests -cargo miri test --manifest-path rand_pcg/Cargo.toml --features=serde1 -cargo miri test --manifest-path rand_chacha/Cargo.toml --no-default-features -cargo miri test --manifest-path rand_hc/Cargo.toml diff --git a/utils/ci/script.sh b/utils/ci/script.sh deleted file mode 100644 index caef0767ca9..00000000000 --- a/utils/ci/script.sh +++ /dev/null @@ -1,59 +0,0 @@ -# Derived from https://github.com/japaric/trust - -set -ex - -# ----- Options ----- - -# TARGET enables cross-building -if [ -z $TARGET ]; then - CARGO=cargo -elif [ "$TARGET" = "i686-unknown-linux-musl" ]; then - CARGO=cargo - TARGET="--target $TARGET" -else - CARGO=cross - TARGET="--target $TARGET" -fi - -# ALLOC defaults on; is disabled for rustc < 1.36 -if [ -z $ALLOC ]; then - ALLOC=1 -fi - -# NIGHTLY defaults off - - -# ----- Script ----- - -main() { - if [ "0$NIGHTLY" -ge 1 ]; then - $CARGO test $TARGET --all-features - $CARGO test $TARGET --benches --features=nightly - $CARGO test $TARGET --manifest-path rand_distr/Cargo.toml --benches - else - # all stable features: - $CARGO test $TARGET --features=serde1,log,small_rng - fi - - if [ "$ALLOC" -ge 1 ]; then - $CARGO test $TARGET --tests --no-default-features --features=alloc,getrandom,small_rng - $CARGO test $TARGET --manifest-path rand_core/Cargo.toml --no-default-features --features=alloc - fi - - $CARGO test $TARGET --tests --no-default-features - $CARGO test $TARGET --examples - - $CARGO test $TARGET --manifest-path rand_core/Cargo.toml - $CARGO test $TARGET --manifest-path rand_core/Cargo.toml --no-default-features - $CARGO test $TARGET --manifest-path rand_core/Cargo.toml --no-default-features --features=getrandom - - $CARGO test $TARGET --manifest-path rand_distr/Cargo.toml - $CARGO test $TARGET --manifest-path rand_pcg/Cargo.toml --features=serde1 - $CARGO test $TARGET --manifest-path rand_chacha/Cargo.toml - $CARGO test $TARGET --manifest-path rand_hc/Cargo.toml -} - -# we don't run the "test phase" when doing deploys -if [ -z $TRAVIS_TAG ]; then - main -fi From 545f076ccf602bc50f2c7863d65c3cb01874374e Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Thu, 10 Dec 2020 12:04:07 +0000 Subject: [PATCH 5/8] CI: add explicit target selections --- .github/workflows/test.yml | 61 ++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7f5bfc7d0fa..5a7496eb2ca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,57 +30,72 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - toolchain: [stable] - minimal: [false] include: - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + toolchain: stable + - os: macos-latest + target: x86_64-apple-darwin + toolchain: stable + # TODO: also aarch64 / M1 + - os: windows-latest + target: x86_64-pc-windows-gnu + toolchain: stable + - os: windows-latest + target: x86_64-pc-windows-msvc toolchain: beta + # Test both windows-gnu and windows-msvc; use beta rust on one - os: ubuntu-latest - toolchain: 1.36.0 + target: x86_64-unknown-linux-gnu + toolchain: 1.36.0 # MSRV - os: ubuntu-latest + deps: sudo apt install gcc-multilib + target: i686-unknown-linux-gnu toolchain: nightly - os: ubuntu-latest + target: x86_64-unknown-linux-gnu toolchain: nightly - minimal: true + variant: minimal steps: - uses: actions/checkout@v2 - name: Install toolchain uses: actions-rs/toolchain@v1 with: - toolchain: ${{ matrix.toolchain }} - override: true + target: ${{ matrix.target }} + toolchain: ${{ matrix.toolchain }} + override: true + - run: ${{ matrix.deps }} - name: Maybe minimal - if: ${{ matrix.minimal }} + if: ${{ matrix.variant == 'minimal' }} run: cargo generate-lockfile -Z minimal-versions - name: Maybe nightly if: ${{ matrix.toolchain == 'nightly' }} run: | - cargo test --tests --features=nightly - cargo test --all-features - cargo test --benches --features=nightly - cargo test --manifest-path rand_distr/Cargo.toml --benches + cargo test --target ${{ matrix.target }} --tests --features=nightly + cargo test --target ${{ matrix.target }} --all-features + cargo test --target ${{ matrix.target }} --benches --features=nightly + cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --benches - name: Test rand run: | - cargo test --tests --no-default-features - cargo test --tests --no-default-features --features=alloc,getrandom,small_rng + cargo test --target ${{ matrix.target }} --tests --no-default-features + cargo test --target ${{ matrix.target }} --tests --no-default-features --features=alloc,getrandom,small_rng # all stable features: - cargo test --features=serde1,log,small_rng - cargo test --examples + cargo test --target ${{ matrix.target }} --features=serde1,log,small_rng + cargo test --target ${{ matrix.target }} --examples - name: Test rand_core run: | - cargo test --manifest-path rand_core/Cargo.toml - cargo test --manifest-path rand_core/Cargo.toml --no-default-features - cargo test --manifest-path rand_core/Cargo.toml --no-default-features --features=alloc,getrandom + cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml + cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml --no-default-features + cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml --no-default-features --features=alloc,getrandom - name: Test rand_distr - run: cargo test --manifest-path rand_distr/Cargo.toml + run: cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml - name: Test rand_pcg - run: cargo test --manifest-path rand_pcg/Cargo.toml --features=serde1 + run: cargo test --target ${{ matrix.target }} --manifest-path rand_pcg/Cargo.toml --features=serde1 - name: Test rand_chacha - run: cargo test --manifest-path rand_chacha/Cargo.toml + run: cargo test --target ${{ matrix.target }} --manifest-path rand_chacha/Cargo.toml - name: Test rand_hc - run: cargo test --manifest-path rand_hc/Cargo.toml + run: cargo test --target ${{ matrix.target }} --manifest-path rand_hc/Cargo.toml test-miri: runs-on: ubuntu-latest From 33a78deb964b796e2219d70a89084c42ae540dc4 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Sun, 13 Dec 2020 09:55:58 +0000 Subject: [PATCH 6/8] Add cross test (inspired by ndarray CI) --- .github/workflows/test.yml | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5a7496eb2ca..686cea4baaf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -62,6 +62,7 @@ jobs: - name: Install toolchain uses: actions-rs/toolchain@v1 with: + profile: minimal target: ${{ matrix.target }} toolchain: ${{ matrix.toolchain }} override: true @@ -97,6 +98,43 @@ jobs: - name: Test rand_hc run: cargo test --target ${{ matrix.target }} --manifest-path rand_hc/Cargo.toml + test-cross: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + target: mips-unknown-linux-gnu + toolchain: stable + + steps: + - uses: actions/checkout@v2 + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + target: ${{ matrix.target }} + toolchain: ${{ matrix.toolchain }} + override: true + - name: Cache cargo plugins + uses: actions/cache@v1 + with: + path: ~/.cargo/bin/ + key: ${{ runner.os }}-cargo-plugins + - name: Install cross + run: cargo install cross || true + - name: Test + run: | + # all stable features: + cross test --no-fail-fast --target ${{ matrix.target }} --features=serde1,log,small_rng + cross test --no-fail-fast --target ${{ matrix.target }} --examples + cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml + cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml + cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_pcg/Cargo.toml --features=serde1 + cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_chacha/Cargo.toml + cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_hc/Cargo.toml + test-miri: runs-on: ubuntu-latest steps: @@ -125,6 +163,7 @@ jobs: - name: Install toolchain uses: actions-rs/toolchain@v1 with: + profile: minimal toolchain: nightly target: thumbv6m-none-eabi override: true @@ -138,6 +177,7 @@ jobs: - name: Install toolchain uses: actions-rs/toolchain@v1 with: + profile: minimal toolchain: nightly target: aarch64-apple-ios override: true From 354468ed6a07ddbf0d74cddca3d3805c9a99c6d7 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Sun, 13 Dec 2020 14:16:18 +0000 Subject: [PATCH 7/8] Use approximate assertions in value stability and increase some tolerences slightly --- rand_distr/src/cauchy.rs | 2 +- rand_distr/src/normal.rs | 3 +- rand_distr/src/pareto.rs | 16 +++++------ rand_distr/tests/value_stability.rs | 44 +++++++++++++++++++++++++---- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/rand_distr/src/cauchy.rs b/rand_distr/src/cauchy.rs index ffe86d00a9b..1fadf0c6f61 100644 --- a/rand_distr/src/cauchy.rs +++ b/rand_distr/src/cauchy.rs @@ -160,7 +160,7 @@ mod test { let expected = [15.023088, -5.446413, 3.7092876, 3.112482]; for (a, b) in buf.iter().zip(expected.iter()) { let (a, b) = (*a, *b); - assert!((a - b).abs() < 1e-6, "expected: {} = {}", a, b); + assert!((a - b).abs() < 1e-5, "expected: {} = {}", a, b); } } } diff --git a/rand_distr/src/normal.rs b/rand_distr/src/normal.rs index ae82799147a..4ab0fbd1901 100644 --- a/rand_distr/src/normal.rs +++ b/rand_distr/src/normal.rs @@ -345,7 +345,8 @@ mod tests { assert_almost_eq!(lnorm.norm.std_dev, 1.0, 2e-16); let lnorm = LogNormal::from_mean_cv(e.powf(1.5), (e - 1.0).sqrt()).unwrap(); - assert_eq!((lnorm.norm.mean, lnorm.norm.std_dev), (1.0, 1.0)); + assert!((lnorm.norm.mean - 1.0).abs() < 1e-15); + assert_eq!(lnorm.norm.std_dev, 1.0); } #[test] fn test_log_normal_invalid_sd() { diff --git a/rand_distr/src/pareto.rs b/rand_distr/src/pareto.rs index 217899ed9a7..0c62383b1cb 100644 --- a/rand_distr/src/pareto.rs +++ b/rand_distr/src/pareto.rs @@ -87,6 +87,7 @@ where F: Float, OpenClosed01: Distribution #[cfg(test)] mod tests { use super::*; + use core::fmt::{Debug, Display}; #[test] #[should_panic] @@ -108,21 +109,20 @@ mod tests { #[test] fn value_stability() { - fn test_samples>( - distr: D, zero: F, expected: &[F], + fn test_samples>( + distr: D, thresh: F, expected: &[F], ) { let mut rng = crate::test::rng(213); - let mut buf = [zero; 4]; - for x in &mut buf { - *x = rng.sample(&distr); + for v in expected { + let x = rng.sample(&distr); + assert!((x - *v).abs() < thresh, "not approx eq: {}, {}", x, *v); } - assert_eq!(buf, expected); } - test_samples(Pareto::new(1.0, 1.0).unwrap(), 0f32, &[ + test_samples(Pareto::new(1f32, 1.0).unwrap(), 1e-6, &[ 1.0423688, 2.1235929, 4.132709, 1.4679428, ]); - test_samples(Pareto::new(2.0, 0.5).unwrap(), 0f64, &[ + test_samples(Pareto::new(2.0, 0.5).unwrap(), 1e-14, &[ 9.019295276219136, 4.3097126018270595, 6.837815045397157, diff --git a/rand_distr/tests/value_stability.rs b/rand_distr/tests/value_stability.rs index 986b9963283..aafb95552d5 100644 --- a/rand_distr/tests/value_stability.rs +++ b/rand_distr/tests/value_stability.rs @@ -6,7 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::{fmt::Debug, cmp::PartialEq}; +use core::fmt::Debug; use rand::Rng; use rand_distr::*; @@ -17,12 +17,45 @@ fn get_rng(seed: u64) -> impl rand::Rng { rand_pcg::Pcg32::new(seed, INC) } -fn test_samples>( +/// We only assert approximate equality since some platforms do not perform +/// identically (i686-unknown-linux-gnu and most notably x86_64-pc-windows-gnu). +trait ApproxEq { + fn is_approx_eq(&self, rhs: &Self) -> bool; +} + +impl ApproxEq for f32 { + fn is_approx_eq(&self, rhs: &Self) -> bool { + (self - rhs).abs() < 1e-6 + } +} +impl ApproxEq for f64 { + fn is_approx_eq(&self, rhs: &Self) -> bool { + (self - rhs).abs() < 1e-14 + } +} +impl ApproxEq for u64 { + fn is_approx_eq(&self, rhs: &Self) -> bool { + self == rhs + } +} +impl ApproxEq for [T; 2] { + fn is_approx_eq(&self, rhs: &Self) -> bool { + self[0].is_approx_eq(&rhs[0]) && self[1].is_approx_eq(&rhs[1]) + } +} +impl ApproxEq for [T; 3] { + fn is_approx_eq(&self, rhs: &Self) -> bool { + self[0].is_approx_eq(&rhs[0]) && self[1].is_approx_eq(&rhs[1]) && self[2].is_approx_eq(&rhs[2]) + } +} + +fn test_samples>( seed: u64, distr: D, expected: &[F], ) { let mut rng = get_rng(seed); - for &val in expected { - assert_eq!(val, rng.sample(&distr)); + for val in expected { + let x = rng.sample(&distr); + assert!(x.is_approx_eq(&val), "not approx eq: {:?}, {:?}", x, val); } } @@ -334,11 +367,12 @@ fn cauchy_stability() { // Unfortunately this test is not fully portable due to reliance on the // system's implementation of tanf (see doc on Cauchy struct). + // We use a lower threshold of 1e-5 here. let distr = Cauchy::new(10f32, 7.0).unwrap(); let mut rng = get_rng(353); let expected = [15.023088, -5.446413, 3.7092876, 3.112482]; for &a in expected.iter() { let b = rng.sample(&distr); - assert!((a - b).abs() < 1e-6, "expected: {} = {}", a, b); + assert!((a - b).abs() < 1e-5, "not approx eq: {:?}, {:?}", a, b); } } From 33b8f37231f4b54cb4f1e50ae3a74483abc01dad Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Mon, 14 Dec 2020 13:44:46 +0000 Subject: [PATCH 8/8] Address review: use assert_almost_eq macro --- README.md | 2 +- rand_distr/src/cauchy.rs | 3 +-- rand_distr/src/normal.rs | 2 +- rand_distr/src/pareto.rs | 6 +++--- rand_distr/tests/value_stability.rs | 30 ++++++++++++++++------------- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 3ca09b008b7..214d9ed41e0 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ greater, and 0.4 and 0.3 (since approx. June 2017) require Rustc version 1.15 or greater. Subsets of the Rand code may work with older Rust versions, but this is not supported. -Continuous Integration (CI) will always test the oldest supported Rustc version +Continuous Integration (CI) will always test the minimum supported Rustc version (the MSRV). The current policy is that this can be updated in any Rand release if required, but the change must be noted in the changelog. diff --git a/rand_distr/src/cauchy.rs b/rand_distr/src/cauchy.rs index 1fadf0c6f61..952b7f29dc9 100644 --- a/rand_distr/src/cauchy.rs +++ b/rand_distr/src/cauchy.rs @@ -159,8 +159,7 @@ mod test { gen_samples(10f32, 7.0, &mut buf); let expected = [15.023088, -5.446413, 3.7092876, 3.112482]; for (a, b) in buf.iter().zip(expected.iter()) { - let (a, b) = (*a, *b); - assert!((a - b).abs() < 1e-5, "expected: {} = {}", a, b); + assert_almost_eq!(*a, *b, 1e-5); } } } diff --git a/rand_distr/src/normal.rs b/rand_distr/src/normal.rs index 4ab0fbd1901..8c3c8f8fd2f 100644 --- a/rand_distr/src/normal.rs +++ b/rand_distr/src/normal.rs @@ -345,7 +345,7 @@ mod tests { assert_almost_eq!(lnorm.norm.std_dev, 1.0, 2e-16); let lnorm = LogNormal::from_mean_cv(e.powf(1.5), (e - 1.0).sqrt()).unwrap(); - assert!((lnorm.norm.mean - 1.0).abs() < 1e-15); + assert_almost_eq!(lnorm.norm.mean, 1.0, 1e-15); assert_eq!(lnorm.norm.std_dev, 1.0); } #[test] diff --git a/rand_distr/src/pareto.rs b/rand_distr/src/pareto.rs index 0c62383b1cb..3250c86ffe9 100644 --- a/rand_distr/src/pareto.rs +++ b/rand_distr/src/pareto.rs @@ -87,7 +87,7 @@ where F: Float, OpenClosed01: Distribution #[cfg(test)] mod tests { use super::*; - use core::fmt::{Debug, Display}; + use core::fmt::{Debug, Display, LowerExp}; #[test] #[should_panic] @@ -109,13 +109,13 @@ mod tests { #[test] fn value_stability() { - fn test_samples>( + fn test_samples>( distr: D, thresh: F, expected: &[F], ) { let mut rng = crate::test::rng(213); for v in expected { let x = rng.sample(&distr); - assert!((x - *v).abs() < thresh, "not approx eq: {}, {}", x, *v); + assert_almost_eq!(x, *v, thresh); } } diff --git a/rand_distr/tests/value_stability.rs b/rand_distr/tests/value_stability.rs index aafb95552d5..65c49644a41 100644 --- a/rand_distr/tests/value_stability.rs +++ b/rand_distr/tests/value_stability.rs @@ -6,6 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use average::assert_almost_eq; use core::fmt::Debug; use rand::Rng; use rand_distr::*; @@ -20,32 +21,35 @@ fn get_rng(seed: u64) -> impl rand::Rng { /// We only assert approximate equality since some platforms do not perform /// identically (i686-unknown-linux-gnu and most notably x86_64-pc-windows-gnu). trait ApproxEq { - fn is_approx_eq(&self, rhs: &Self) -> bool; + fn assert_almost_eq(&self, rhs: &Self); } impl ApproxEq for f32 { - fn is_approx_eq(&self, rhs: &Self) -> bool { - (self - rhs).abs() < 1e-6 + fn assert_almost_eq(&self, rhs: &Self) { + assert_almost_eq!(self, rhs, 1e-6); } } impl ApproxEq for f64 { - fn is_approx_eq(&self, rhs: &Self) -> bool { - (self - rhs).abs() < 1e-14 + fn assert_almost_eq(&self, rhs: &Self) { + assert_almost_eq!(self, rhs, 1e-14); } } impl ApproxEq for u64 { - fn is_approx_eq(&self, rhs: &Self) -> bool { - self == rhs + fn assert_almost_eq(&self, rhs: &Self) { + assert_eq!(self, rhs); } } impl ApproxEq for [T; 2] { - fn is_approx_eq(&self, rhs: &Self) -> bool { - self[0].is_approx_eq(&rhs[0]) && self[1].is_approx_eq(&rhs[1]) + fn assert_almost_eq(&self, rhs: &Self) { + self[0].assert_almost_eq(&rhs[0]); + self[1].assert_almost_eq(&rhs[1]); } } impl ApproxEq for [T; 3] { - fn is_approx_eq(&self, rhs: &Self) -> bool { - self[0].is_approx_eq(&rhs[0]) && self[1].is_approx_eq(&rhs[1]) && self[2].is_approx_eq(&rhs[2]) + fn assert_almost_eq(&self, rhs: &Self) { + self[0].assert_almost_eq(&rhs[0]); + self[1].assert_almost_eq(&rhs[1]); + self[2].assert_almost_eq(&rhs[2]); } } @@ -55,7 +59,7 @@ fn test_samples>( let mut rng = get_rng(seed); for val in expected { let x = rng.sample(&distr); - assert!(x.is_approx_eq(&val), "not approx eq: {:?}, {:?}", x, val); + x.assert_almost_eq(val); } } @@ -373,6 +377,6 @@ fn cauchy_stability() { let expected = [15.023088, -5.446413, 3.7092876, 3.112482]; for &a in expected.iter() { let b = rng.sample(&distr); - assert!((a - b).abs() < 1e-5, "not approx eq: {:?}, {:?}", a, b); + assert_almost_eq!(a, b, 1e-5); } }