Repository navigation
cargo-mutants 27.1.0 (new): mutation testing for Rust (fv-lab) #1609
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| let { subsetOf, Attrs, BuildSpec, Local, Needs, OutputBin, Source, Test, .. } = import "minimal.ncl" in | ||
| let base = import "../base/build.ncl" in | ||
| let bash-bootstrap = import "../bash-bootstrap/build.ncl" in | ||
| let detbuild = import "../detbuild/build.ncl" in | ||
| let grep = import "../grep/build.ncl" in | ||
| let rust = import "../rust/build.ncl" in | ||
| let toolchain = import "../toolchain/build.ncl" in | ||
|
|
||
| let gcc = import "../gcc/build.ncl" in | ||
| let glibc = import "../glibc/build.ncl" in | ||
|
|
||
| let version = "27.1.0" in | ||
| { | ||
| name = "cargo-mutants", | ||
| # Mutation testing for Rust, built from source with the rust package. It drives | ||
| # whatever `cargo` is on PATH at run time (cargo build / cargo test on mutated | ||
| # copies of the tree) and ships no toolchain of its own, so rust is a test dep | ||
| # here, not a runtime dep: a session that uses it brings its own rust. | ||
| build_deps = [ | ||
| { file = "build.sh" } | Local, | ||
| { | ||
| # Mirror of https://github.com/sourcefrog/cargo-mutants/archive/refs/tags/v%{version}.tar.gz | ||
| url = "gs://minimal-staging-archives/sourcefrog/cargo-mutants/v%{version}.tar.gz", | ||
| sha256 = "e57d8c31a8edee7d9265949aef896768729c824626897938e98a5d162a82bda0", | ||
| extract = true, | ||
| strip_prefix = "cargo-mutants-%{version}", | ||
| } | Source, | ||
| base, | ||
| rust, | ||
| toolchain, | ||
| # Deterministic getrandom/getentropy for the offline build (see build.sh). | ||
| detbuild, | ||
| ], | ||
|
|
||
| runtime_deps = [ | ||
| glibc, | ||
| subsetOf gcc ["libgcc"], | ||
| ], | ||
|
|
||
| # cargo fetch (see build.sh) | ||
| needs = | ||
| { | ||
| dns = {}, | ||
| internet = {}, | ||
| } | Needs, | ||
|
|
||
| cmd = "./build.sh", | ||
| build_args = { include version }, | ||
|
|
||
| outputs = { | ||
| cargo-mutants = { glob = "usr/bin/cargo-mutants" } | OutputBin, | ||
| }, | ||
|
|
||
| tests = { | ||
| version_check = | ||
| { | ||
| class = 'Standalone, | ||
| test_deps = [bash-bootstrap, grep], | ||
| cmds = [ | ||
| ["/bin/bash", "-c", "cargo-mutants mutants --version | grep -qx 'cargo-mutants %{version}'"], | ||
| ], | ||
| } | Test, | ||
| # `cargo mutants --list` on a one-function crate: cargo finds the cargo-mutants | ||
| # subcommand on PATH, cargo-mutants runs `cargo metadata` and lists the mutants of | ||
| # `add`. Nothing is compiled, so no linker is needed. | ||
| list = | ||
| { | ||
| class = 'Standalone, | ||
| test_deps = [bash-bootstrap, grep, rust], | ||
| cmds = [ | ||
| [ | ||
| "/bin/bash", | ||
| "-c", | ||
| m%" | ||
| set -euo pipefail | ||
| export CARGO_HOME="$PWD/cargo-home" | ||
| mkdir -p tiny/src | ||
| cd tiny | ||
| printf '[package]\nname = "tiny"\nversion = "0.1.0"\nedition = "2021"\n' > Cargo.toml | ||
| printf 'pub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n' > src/lib.rs | ||
| out="$(cargo mutants --list --line-col=false)" | ||
| printf '%s\n' "$out" | ||
| grep -qx 'src/lib.rs: replace add -> i32 with 0' <<<"$out" | ||
| grep -qx 'src/lib.rs: replace + with - in add' <<<"$out" | ||
| "% | ||
| ], | ||
| ], | ||
| } | Test, | ||
| }, | ||
|
|
||
| attrs = | ||
| { | ||
| upstream_version = version, | ||
| license_spdx = "MIT", | ||
| source_provenance = { | ||
| category = 'GithubRepo, | ||
| owner = "sourcefrog", | ||
| repo = "cargo-mutants", | ||
| }, | ||
| } | Attrs, | ||
| } | BuildSpec | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| export CC=gcc | ||
| export LD=gcc | ||
| # Reproducibility: codegen-units=1 and v0 mangling (the default parallel codegen emits | ||
| # functions in a different order every build; legacy mangling hashes the session into | ||
| # symbol names; see codex, nushell, zola), plus both source and cargo-home paths | ||
| # remapped out of the binary. | ||
| export RUSTFLAGS="-C linker=gcc -C codegen-units=1 -C symbol-mangling-version=v0 --remap-path-prefix=$(pwd)=/builddir --remap-path-prefix=$HOME/.cargo=/cargo" | ||
| export CARGO_INCREMENTAL=0 | ||
|
|
||
| # All network access happens here, with real entropy: crates are fetched and checked | ||
| # against upstream's Cargo.lock before the shim below is loaded. cargo-mutants has no | ||
| # -sys crates and no build script that downloads anything (checked for 27.1.0). | ||
| cargo fetch --locked | ||
|
|
||
| # Deterministic build-time entropy (packages/detbuild) for the offline build only; | ||
| # `--frozen` refuses any network access. | ||
| LD_PRELOAD=/usr/lib/minimal/libdetbuild.so cargo build --frozen --release --bin cargo-mutants | ||
|
|
||
| install -Dm755 target/release/cargo-mutants "$OUTPUT_DIR/usr/bin/cargo-mutants" | ||
|
|
||
| # runtime_deps is glibc + libgcc (libgcc_s, for unwinding); fail closed if the binary | ||
| # ever NEEDs anything else. | ||
| needed=$(readelf -d "$OUTPUT_DIR/usr/bin/cargo-mutants" | sed -n 's/.*Shared library: \[\(.*\)\]/\1/p') | ||
| echo "$needed" | ||
| if grep -vxE 'libc\.so\.6|libm\.so\.6|libgcc_s\.so\.1|ld-linux-(x86-64|aarch64)\.so\.[12]' <<<"$needed"; then | ||
| echo "ERROR: cargo-mutants NEEDs a library outside glibc and libgcc_s (above)" >&2 | ||
| exit 1 | ||
| fi |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit ·
build_argsforwardsversion, butbuild.shdoes not readMINIMAL_ARG_VERSION. The source extracts into the cwd throughstrip_prefix, so the script needs no version. Remove the line, aspackages/zola/build.ncldoes.packages/cargo-nextest/build.nclhas the same unused forward, so this is a small pattern and not one instance.