github cweill/gotests v1.7.4

latest release: v1.8.0
one day ago

What's New in v1.7.4

This release fixes two important bugs that improve test correctness and restore broken functionality.

Bug Fixes

🐛 Fixed wantErr Test Logic (PR #169)

When a test expects an error (tt.wantErr == true), gotests now correctly skips result validation instead of checking potentially undefined return values.

Before:

if (err != nil) != tt.wantErr {
    t.Errorf("Foo() error = %v, wantErr %v", err, tt.wantErr)
    continue
}
// Bug: Still checks results even when error is expected!
if got != tt.want {
    t.Errorf("Foo() = %v, want %v", got, tt.want)
}

After:

if (err != nil) != tt.wantErr {
    t.Errorf("Foo() error = %v, wantErr %v", err, tt.wantErr)
    continue
}
if tt.wantErr {
    return  // ← Fixed: Skip result checks when error expected
}
if got != tt.want {
    t.Errorf("Foo() = %v, want %v", got, tt.want)
}

This prevents false test failures and ensures tests behave correctly when expecting errors.

Thanks to @arifmahmudrana for identifying this issue!

🐛 Fixed -template_params Flag (Issue #149)

The -template_params flag was defined but never actually used due to a bug from PR #90. This flag now works correctly!

Usage:

# Pass template parameters as JSON string
$ gotests -template_params '{"key":"value"}' -all file.go

# Or use a file (takes precedence)
$ gotests -template_params_file params.json -all file.go

This is useful when calling gotests from other tools with custom templates.

Thanks to @butuzov for identifying this bug and @cweill for the fix suggestion!

Installation

go install github.com/cweill/gotests/gotests@v1.7.4

Full Changelog: v1.7.3...v1.7.4

Don't miss a new gotests release

NewReleases is sending notifications on new releases.