Skip to content

Commit

Permalink
Add --var-values flag to regal test command (#930)
Browse files Browse the repository at this point in the history
Fixes #876

Signed-off-by: Anders Eknert <anders@styra.com>
  • Loading branch information
anderseknert authored Jul 22, 2024
1 parent 8382e1c commit 886ef2e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type testCommandParams struct {
runRegex string
count int
skipExitZero bool
varValues bool
}

func newTestCommandParams() *testCommandParams {
Expand Down Expand Up @@ -167,7 +168,8 @@ func opaTest(args []string) int {
WithEnablePrintStatements(!testParams.benchmark).
WithSchemas(compile.RegalSchemaSet()).
WithUseTypeCheckAnnotations(true).
WithModuleLoader(moduleLoader(regalBundle))
WithModuleLoader(moduleLoader(regalBundle)).
WithRewriteTestRules(testParams.varValues)

if testParams.threshold > 0 && !testParams.coverage {
testParams.coverage = true
Expand All @@ -192,6 +194,7 @@ func opaTest(args []string) int {
SetCompiler(compiler).
SetStore(store).
CapturePrintOutput(true).
EnableTracing(testParams.verbose || testParams.varValues).
SetCoverageQueryTracer(coverTracer).
SetRuntime(Runtime()).
SetModules(modules).
Expand Down Expand Up @@ -256,6 +259,8 @@ func testReporter(cov *cover.Cover, modules map[string]*ast.Module) tester.Repor
BenchmarkResults: testParams.benchmark,
BenchMarkShowAllocations: testParams.benchMem,
BenchMarkGoBenchFormat: goBench,
FailureLine: testParams.varValues,
LocalVars: testParams.varValues,
}
}
} else {
Expand Down Expand Up @@ -358,6 +363,8 @@ func init() {
"benchmark the unit tests")
testCommand.Flags().StringVarP(&testParams.runRegex, "run", "r", "",
"run only test cases matching the regular expression.")
testCommand.Flags().BoolVar(&testParams.varValues,
"var-values", false, "show local variable values in test output")

addPprofFlag(testCommand.Flags())
addBundleModeFlag(testCommand.Flags(), &testParams.bundleMode, false)
Expand Down

0 comments on commit 886ef2e

Please sign in to comment.