diff options
| author | Jakob Unterwurzacher | 2026-11-20 22:44:17 +0100 |
|---|---|---|
| committer | Jakob Unterwurzacher | 2026-11-20 22:53:36 +0100 |
| commit | 7190404b14597fa0afffff1313b192c2b83e04cb (patch) | |
| tree | 39de57f39719af9ce863a4b5dc38183f16bf628e /tests/test_helpers/helpers.go | |
| parent | 173e5056ef8beaa461c5a6665b75e1d97503c5ac (diff) | |
test.bash: collect coverage from unit and integration tests
Most of the test suite runs the gocryptfs binary, so "go test -cover"
alone misses most of the coverage. test.bash now builds a separate
coverage-instrumented binary into ./coverage (./gocryptfs stays a normal
build, so "make install" does not pick it up) and points the tests at it
via $GOCRYPTFS_TEST_BINARY.
"go test -cover" overwrites $GOCOVERDIR with a temporary directory and
ignores the data of other executables in it, so the directory is passed
as $GOCRYPTFS_COVERAGE_DATA and test_helpers sets $GOCOVERDIR from it.
Only our packages that go into the gocryptfs binary are instrumented, so
the reported percentage is relative to that code.
The merged result is written to coverage/coverage.out and
coverage/coverage.html.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/test_helpers/helpers.go')
| -rw-r--r-- | tests/test_helpers/helpers.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go index fd2ea9c..53187ac 100644 --- a/tests/test_helpers/helpers.go +++ b/tests/test_helpers/helpers.go @@ -22,8 +22,16 @@ import ( // $TMPDIR/gocryptfs-test-parent . var testParentDir = "" -// GocryptfsBinary is the assumed path to the gocryptfs build. -const GocryptfsBinary = "../../gocryptfs" +// GocryptfsBinary is the path to the gocryptfs build under test. +// test.bash sets $GOCRYPTFS_TEST_BINARY to a coverage-instrumented build. +var GocryptfsBinary = gocryptfsBinary() + +func gocryptfsBinary() string { + if b := os.Getenv("GOCRYPTFS_TEST_BINARY"); b != "" { + return b + } + return "../../gocryptfs" +} // UnmountScript is the fusermount/umount compatibility wrapper script const UnmountScript = "../../tests/fuse-unmount.bash" @@ -42,6 +50,12 @@ var DefaultPlainDir string var DefaultCipherDir string func init() { + // "go test -cover" overwrites $GOCOVERDIR with a temporary directory, so + // let's overwrite it back. Then the gocryptfs processes, that we start, + // write coverage info to ./coverage/data like the unit tests do. + if d := os.Getenv("GOCRYPTFS_COVERAGE_DATA"); d != "" { + os.Setenv("GOCOVERDIR", d) + } doInit() } |
