-
Notifications
You must be signed in to change notification settings - Fork 10
fix: remove hardcoded -short from coverage generation (#106) #194
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
Open
em-redhat
wants to merge
1
commit into
unbound-force:main
Choose a base branch
from
em-redhat:opsx/fix-hardcoded-short-flag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
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 |
|---|---|---|
|
|
@@ -1430,14 +1430,18 @@ func TestRunSelfCheck_InvalidFormat(t *testing.T) { | |
| } | ||
|
|
||
| func TestRunSelfCheck_TextFormat(t *testing.T) { | ||
| if os.Getenv("GAZE_COVERAGE_RUN") != "" { | ||
| t.Skip("skipping: GAZE_COVERAGE_RUN set (recursion guard)") | ||
| } | ||
| if testing.Short() { | ||
| t.Skip("skipping self-check in short mode") | ||
| } | ||
| var stdout, stderr bytes.Buffer | ||
| err := runSelfCheck(selfCheckParams{ | ||
| format: "text", | ||
| stdout: &stdout, | ||
| stderr: &stderr, | ||
| format: "text", | ||
| testShort: true, // match CLI default for self-check | ||
| stdout: &stdout, | ||
| stderr: &stderr, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("self-check text failed: %v", err) | ||
|
|
@@ -1448,14 +1452,18 @@ func TestRunSelfCheck_TextFormat(t *testing.T) { | |
| } | ||
|
|
||
| func TestRunSelfCheck_JSONFormat(t *testing.T) { | ||
| if os.Getenv("GAZE_COVERAGE_RUN") != "" { | ||
| t.Skip("skipping: GAZE_COVERAGE_RUN set (recursion guard)") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [CRITICAL] Same issue — add err := runSelfCheck(selfCheckParams{
format: "json",
testShort: true, // match CLI default for self-check
stdout: &stdout,
stderr: &stderr,
}) |
||
| } | ||
| if testing.Short() { | ||
| t.Skip("skipping self-check in short mode") | ||
| } | ||
| var stdout, stderr bytes.Buffer | ||
| err := runSelfCheck(selfCheckParams{ | ||
| format: "json", | ||
| stdout: &stdout, | ||
| stderr: &stderr, | ||
| format: "json", | ||
| testShort: true, // match CLI default for self-check | ||
| stdout: &stdout, | ||
| stderr: &stderr, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("self-check json failed: %v", err) | ||
|
|
@@ -2575,3 +2583,182 @@ func TestBuildAIMapperFunc_OllamaWithModel(t *testing.T) { | |
| t.Fatal("expected non-nil AIMapperFunc for ollama with model") | ||
| } | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // --test-short flag wiring tests (fix-hardcoded-short-flag Phase 2) | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| // TestCrapCmd_TestShortFlag verifies that the --test-short flag is | ||
| // recognized by the crap command and sets Short on the | ||
| // GoLineCoverageProvider. Uses cobra flag parsing to exercise the | ||
| // full newCrapCmd wiring. | ||
| func TestCrapCmd_TestShortFlag(t *testing.T) { | ||
| cmd := newCrapCmd() | ||
| // Verify the flag exists and has the expected default. | ||
| f := cmd.Flags().Lookup("test-short") | ||
| if f == nil { | ||
| t.Fatal("expected --test-short flag on crap command") | ||
| } | ||
| if f.DefValue != "false" { | ||
| t.Errorf("expected default value 'false', got %q", f.DefValue) | ||
| } | ||
| if f.Usage == "" { | ||
| t.Error("expected non-empty usage string for --test-short") | ||
| } | ||
| } | ||
|
|
||
| // TestRunCrap_TestShortThreadsToAnalyze verifies that when | ||
| // crapParams.opts.LineCoverageProvider is a *GoLineCoverageProvider | ||
| // with Short=true, the value reaches the analyzeFunc unchanged. | ||
| func TestRunCrap_TestShortThreadsToAnalyze(t *testing.T) { | ||
| var capturedOpts crap.Options | ||
| lineProv := goprovider.NewLineCoverageProvider(&bytes.Buffer{}) | ||
| lineProv.Short = true | ||
|
|
||
| opts := crap.DefaultOptions() | ||
| opts.LineCoverageProvider = lineProv | ||
|
|
||
| var stdout, stderr bytes.Buffer | ||
| err := runCrap(crapParams{ | ||
| patterns: []string{"./..."}, | ||
| format: "text", | ||
| opts: opts, | ||
| moduleDir: ".", | ||
| stdout: &stdout, | ||
| stderr: &stderr, | ||
| analyzeFunc: func(_ []string, _ string, o crap.Options) (*crap.Report, error) { | ||
| capturedOpts = o | ||
| return &crap.Report{ | ||
| Scores: []crap.Score{{Function: "Foo", Complexity: 1, LineCoverage: 100, CRAP: 1}}, | ||
| }, nil | ||
| }, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("runCrap returned error: %v", err) | ||
| } | ||
|
|
||
| prov, ok := capturedOpts.LineCoverageProvider.(*goprovider.GoLineCoverageProvider) | ||
| if !ok { | ||
| t.Fatalf("expected *GoLineCoverageProvider, got %T", capturedOpts.LineCoverageProvider) | ||
| } | ||
| if !prov.Short { | ||
| t.Error("expected GoLineCoverageProvider.Short=true to thread through to analyzeFunc") | ||
| } | ||
| } | ||
|
|
||
| // TestRunSelfCheck_TestShortThreadsToProvider verifies that when | ||
| // selfCheckParams.testShort is true, the GoLineCoverageProvider | ||
| // constructed in runSelfCheck has Short=true. Uses the runCrapFunc | ||
| // injection to capture the constructed crapParams. | ||
| func TestRunSelfCheck_TestShortThreadsToProvider(t *testing.T) { | ||
| var capturedOpts crap.Options | ||
| var stdout, stderr bytes.Buffer | ||
| err := runSelfCheck(selfCheckParams{ | ||
| format: "text", | ||
| testShort: true, | ||
| stdout: &stdout, | ||
| stderr: &stderr, | ||
| moduleRootFunc: func() (string, error) { | ||
| return "/fake/module/root", nil | ||
| }, | ||
| runCrapFunc: func(p crapParams) error { | ||
| capturedOpts = p.opts | ||
| return nil | ||
| }, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("runSelfCheck returned error: %v", err) | ||
| } | ||
|
|
||
| // The LineCoverageProvider should be a *GoLineCoverageProvider | ||
| // with Short=true. | ||
| prov, ok := capturedOpts.LineCoverageProvider.(*goprovider.GoLineCoverageProvider) | ||
| if !ok { | ||
| t.Fatalf("expected *GoLineCoverageProvider, got %T", capturedOpts.LineCoverageProvider) | ||
| } | ||
| if !prov.Short { | ||
| t.Error("expected GoLineCoverageProvider.Short=true when testShort=true") | ||
| } | ||
| } | ||
|
|
||
| // TestRunSelfCheck_TestShortFalseWhenExplicit verifies that when | ||
| // selfCheckParams.testShort is explicitly false, the | ||
| // GoLineCoverageProvider has Short=false. | ||
| func TestRunSelfCheck_TestShortFalseWhenExplicit(t *testing.T) { | ||
| var capturedOpts crap.Options | ||
| var stdout, stderr bytes.Buffer | ||
| err := runSelfCheck(selfCheckParams{ | ||
| format: "text", | ||
| // testShort not set — defaults to false | ||
| stdout: &stdout, | ||
| stderr: &stderr, | ||
| moduleRootFunc: func() (string, error) { | ||
| return "/fake/module/root", nil | ||
| }, | ||
| runCrapFunc: func(p crapParams) error { | ||
| capturedOpts = p.opts | ||
| return nil | ||
| }, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("runSelfCheck returned error: %v", err) | ||
| } | ||
|
|
||
| prov, ok := capturedOpts.LineCoverageProvider.(*goprovider.GoLineCoverageProvider) | ||
| if !ok { | ||
| t.Fatalf("expected *GoLineCoverageProvider, got %T", capturedOpts.LineCoverageProvider) | ||
| } | ||
| if prov.Short { | ||
| t.Error("expected GoLineCoverageProvider.Short=false when testShort not set") | ||
| } | ||
| } | ||
|
|
||
| // TestSelfCheckCmd_TestShortFlag verifies that the --test-short flag | ||
| // is recognized by the self-check command. | ||
| func TestSelfCheckCmd_TestShortFlag(t *testing.T) { | ||
| cmd := newSelfCheckCmd() | ||
| f := cmd.Flags().Lookup("test-short") | ||
| if f == nil { | ||
| t.Fatal("expected --test-short flag on self-check command") | ||
| } | ||
| if f.DefValue != "true" { | ||
| t.Errorf("expected default value 'true' for self-check, got %q", f.DefValue) | ||
| } | ||
| } | ||
|
|
||
| // TestRunReport_TestShortThreadsToRunnerOptions verifies that | ||
| // reportParams.testShort threads to RunnerOptions.TestShort when | ||
| // runReport calls the runner function. | ||
| func TestRunReport_TestShortThreadsToRunnerOptions(t *testing.T) { | ||
| var capturedTestShort bool | ||
| err := runReport(reportParams{ | ||
| patterns: []string{"./..."}, | ||
| format: "json", | ||
| testShort: true, | ||
| stdout: &bytes.Buffer{}, | ||
| stderr: &bytes.Buffer{}, | ||
| runnerFunc: func(opts aireport.RunnerOptions) error { | ||
| capturedTestShort = opts.TestShort | ||
| return nil | ||
| }, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("runReport returned error: %v", err) | ||
| } | ||
| if !capturedTestShort { | ||
| t.Error("expected RunnerOptions.TestShort=true when reportParams.testShort=true") | ||
| } | ||
| } | ||
|
|
||
| // TestReportCmd_TestShortFlag verifies that the --test-short flag | ||
| // is recognized by the report command. | ||
| func TestReportCmd_TestShortFlag(t *testing.T) { | ||
| cmd := newReportCmd() | ||
| f := cmd.Flags().Lookup("test-short") | ||
| if f == nil { | ||
| t.Fatal("expected --test-short flag on report command") | ||
| } | ||
| if f.DefValue != "false" { | ||
| t.Errorf("expected default value 'false', got %q", f.DefValue) | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
[CRITICAL] E2E test missing
testShort: true— causes 30-minute CI timeoutThe
GAZE_COVERAGE_RUNguard prevents recursion, but theselfCheckParamsbelow (line 1440) doesn't settestShort: true. SincetestShortdefaults tofalse(Go zero value), the internalgo test ./...runs ALL tests without-short, exceeding CI's 30-minute timeout.The CLI
self-checkcommand correctly defaults--test-shorttotrue(line 1571), but the E2E test bypasses the CLI and uses the struct zero value. AddtestShort: trueto match the CLI default:Same fix needed for
TestRunSelfCheck_JSONFormatat line 1461.Both E2E tests (Go 1.24 and 1.25) panic with
test timed out after 30m0sonTestRunSelfCheck_TextFormat. E2E passes onmainwhere-shortis still hardcoded.