Skip to content

Commit 17223e3

Browse files
committed
Range tests demo
1 parent 138a373 commit 17223e3

4 files changed

Lines changed: 96 additions & 0 deletions

File tree

.github/workflows/mull.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Mutation Testing
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
permissions:
10+
security-events: write
11+
12+
jobs:
13+
mutation-testing:
14+
runs-on: ubuntu-latest
15+
container:
16+
image: ubuntu:26.04
17+
steps:
18+
- name: Install prerequisites
19+
run: apt-get update && apt-get install -y curl ca-certificates git clang-22
20+
21+
- uses: actions/checkout@v4
22+
23+
- name: Install mull from nightly
24+
run: |
25+
curl -1sLf 'https://dl.cloudsmith.io/public/mull-project/mull-nightly/setup.deb.sh' | bash
26+
apt-get install -y mull-22
27+
28+
- name: Build range_tests
29+
run: |
30+
clang-22 \
31+
-fpass-plugin=/usr/lib/mull-ir-frontend-22 \
32+
-g -grecord-command-line \
33+
main.c -o range_tests
34+
35+
- name: Run mull
36+
run: |
37+
mull-runner-22 \
38+
--reporters GitHubAnnotations \
39+
--reporters SARIF \
40+
--report-name mull-report \
41+
--allow-surviving \
42+
range_tests
43+
44+
- name: Upload SARIF to Code Scanning
45+
uses: github/codeql-action/upload-sarif@v3
46+
with:
47+
sarif_file: mull-report.sarif

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# mull-demo
2+
3+
A minimal demo of [Mull](https://mull-project.com) mutation testing, based on the [Quick Primer](https://mull-project.com/getting-started/primer/).
4+
5+
## What this project does
6+
7+
`main.c` implements a (buggy) `in_range` function that checks whether a value falls within a closed interval `[min, max]`, along with three assertions that serve as its test suite:
8+
9+
```c
10+
int in_range(int value, int min, int max) {
11+
return value >= min && value < max;
12+
}
13+
```
14+
15+
The tests cover below-min, mid-range, and above-max cases — achieving 100% line coverage. Despite this, Mull reveals that two mutations survive:
16+
17+
- `>=` changed to `>` (the boundary at `min` is not tested)
18+
- `<` changed to `<=` (the boundary at `max` is not tested)
19+
20+
This demonstrates a core limitation of coverage-based testing: coverage does not guarantee that the tests actually validate the semantics of the code.
21+
22+
## Running locally
23+
24+
Install mull (see [installation docs](https://mull-project.com/getting-started/installation/)), then:
25+
26+
```bash
27+
clang-22 \
28+
-fpass-plugin=/usr/lib/mull-ir-frontend-22 \
29+
-g -grecord-command-line \
30+
main.c -o range_tests
31+
32+
mull-runner-22 range_tests
33+
```

main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <assert.h>
2+
3+
// Returns 1 if value is in the closed interval [min, max], 0 otherwise
4+
int in_range(int value, int min, int max) {
5+
return value >= min && value < max;
6+
}
7+
8+
int main(void) {
9+
assert(in_range(5, 1, 10) == 1); // mid-range: both conditions true
10+
assert(in_range(0, 1, 10) == 0); // below min: first condition false
11+
assert(in_range(15, 1, 10) == 0); // above max: second condition false
12+
return 0;
13+
}

mull.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mutators:
2+
- cxx_boundary
3+
- cxx_comparison

0 commit comments

Comments
 (0)