Skip to content

Commit 642d64a

Browse files
mmontinCopilot
andauthored
Replace cabal test override with cooked-test commands (#532)
Closes #402. ## Problem The `default` dev shell redefined `cabal` as an exported bash function in its `shellHook` to strip the verbose HPC `Writing: ….html` output of `cabal test` (coverage was enabled by default in `cabal.project`). That function was exported with `export -f`, so it was **not inherited under `direnv` with shells other than `bash`** (e.g. zsh), and the noisy output reappeared. ## Changes - **`cabal.project`**: remove the default coverage settings (the redundant `coverage` + deprecated `library-coverage` fields). Coverage is now opt-in, so plain `cabal test` output is clean. - **`flake.nix`**: replace the fragile `cabal` function override with two real scripts on `PATH` in the `default` shell (work regardless of shell/`direnv`): - `cooked-test` — runs the suite without coverage. - `cooked-test-coverage` — runs with `--enable-coverage` and filters the verbose `Writing: ….html` lines (preserving the real test exit status via `PIPESTATUS`). Both remove a stale `spec.tix` first to avoid HPC `.tix`/`.mix` hash mismatches (`-fignore-hpc-changes` lets GHC reuse instrumented objects across runs), and forward extra arguments to the `tasty` test binary (e.g. `cooked-test -p "Balancing"`). - Also removed a duplicate `pkgs.lmdb` entry in `LD_LIBRARY_PATH`. - **`CONTRIBUTING.md` / `CHANGELOG.md`**: documented the new commands and the default-coverage removal. ## Validation - Pre-commit `nixfmt` hook passes; `nix eval` of the `default` dev shell succeeds. - Verified `cooked-test` / `cooked-test-coverage` both run, including with a `-p` pattern, and that alternating between them no longer triggers the HPC `.tix` mismatch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0cc3518 commit 642d64a

4 files changed

Lines changed: 47 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515

1616
### Changed
1717

18+
- Test coverage analysis is no longer enabled by default in `cabal.project`,
19+
so `cabal test` output is no longer cluttered with `Writing: ….html` lines.
20+
The `nix develop .#default` dev shell provides two commands to run the test
21+
suite, `cooked-test` (without coverage) and `cooked-test-coverage` (with
22+
coverage), replacing the previous `cabal` function override that hid the
23+
coverage output but did not work under `direnv` with shells other than `bash`.
1824
- `doc/BALANCING.md` has been updated to match the current implementation:
1925
Polysemy effect signatures, the `ExtendedTxSkel` result of `balanceTxSkel`, the
2026
effectful `reachValue`/`computeFeeAndBalance` signatures and their actual

CONTRIBUTING.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,26 @@ Alternatively, one can work on _Cooked Validators_ without Nix, using only GHC
3535

3636
### Running tests
3737

38-
Unit tests are defined in `/cooked-validators/tests`. They can be run using:
38+
Unit tests are defined in `/cooked-validators/tests`. From within the
39+
`nix develop .#default` dev shell they can be run using:
3940

4041
```console
41-
$ cabal test all
42+
$ cooked-test
4243
...
4344
All 132 tests passed (3.18s)
4445
```
4546

47+
This runs the suite without coverage analysis, which keeps the output clean. To
48+
run the suite with coverage analysis instead, use `cooked-test-coverage`. Both
49+
commands forward extra arguments to `cabal`, so a single test group or case can
50+
be selected with a [Tasty] pattern, e.g. `cooked-test -p "Balancing"`.
51+
52+
Without the dev shell, the suite can still be run directly with:
53+
54+
```console
55+
$ cabal test all
56+
```
57+
4658
Our continuous integration checks them automatically.
4759

4860
## How to submit changes
@@ -177,3 +189,4 @@ coding conventions in the exact same way the CI does.
177189
[ormolu]: https://github.com/tweag/ormolu
178190
[haddock]: https://haskell-haddock.readthedocs.io/en/latest/
179191
[nixfmt]: https://github.com/serokell/nixfmt
192+
[tasty]: https://github.com/UnkindPartition/tasty

cabal.project

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ write-ghc-environment-files: never
2626
-- 'tasty' output.
2727
test-show-details: direct
2828

29-
-- We activate test coverage by default
30-
package cooked-validators
31-
coverage: True
32-
library-coverage: True
33-
3429
-- Removing optimization for these packages reduces their build time
3530
-- drastically and is not an issue for dev work
3631
package cardano-ledger-alonzo

flake.nix

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,29 @@
3434
}
3535
);
3636

37+
## Runs the test suite without coverage, for clean output. 'spec.tix' is
38+
## removed first to avoid stale HPC '.tix'/'.mix' mismatches (caused by
39+
## '-fignore-hpc-changes' in 'package.yaml'). Extra arguments are
40+
## forwarded to the 'tasty' test binary (e.g. '-p PATTERN').
41+
cooked-test = pkgs.writeShellScriptBin "cooked-test" ''
42+
rm -f spec.tix
43+
opts=(--test-option=--color=always)
44+
for arg in "$@"; do opts+=("--test-option=$arg"); done
45+
cabal test all "''${opts[@]}"
46+
'';
47+
48+
## Like 'cooked-test' but with coverage analysis (only checked
49+
## punctually). The verbose "Writing: ....html" coverage lines are
50+
## filtered out, and 'PIPESTATUS' preserves the test binary's exit status
51+
## through that pipe.
52+
cooked-test-coverage = pkgs.writeShellScriptBin "cooked-test-coverage" ''
53+
rm -f spec.tix
54+
opts=(--test-option=--color=always)
55+
for arg in "$@"; do opts+=("--test-option=$arg"); done
56+
cabal test all --enable-coverage "''${opts[@]}" | grep -vE --color=never "^Writing:.*html$"
57+
exit "''${PIPESTATUS[0]}"
58+
'';
59+
3760
pre-commit = pre-commit-hooks.lib.${system}.run {
3861
src = ./.;
3962
hooks = {
@@ -82,7 +105,6 @@
82105
pkgs.openldap # For freer-extras‽
83106
pkgs.libsodium
84107
pkgs.secp256k1
85-
pkgs.lmdb
86108
blst-portable
87109
];
88110

@@ -102,24 +124,14 @@
102124
pkgs.hlint
103125
pkgs.ormolu
104126
hpkgs.haskell-language-server
127+
cooked-test
128+
cooked-test-coverage
105129
];
106130

107131
inherit LD_LIBRARY_PATH;
108132
inherit LANG;
109133

110-
# In addition to the pre-commit hooks, this redefines a cabal
111-
# command that gets rid of annoying "Writing: .....*.html" output
112-
# when running cabal test.
113-
shellHook = pre-commit.shellHook + ''
114-
function cabal() {
115-
if [ "$1" != "test" ]; then
116-
command cabal "$@"
117-
else
118-
command cabal --test-option=--color=always "$@" | grep -vE --color=never "^Writing:.*html$"
119-
fi
120-
}
121-
export -f cabal
122-
'';
134+
shellHook = pre-commit.shellHook;
123135
};
124136
};
125137

0 commit comments

Comments
 (0)