Skip to content

Commit 886ef2e

Browse files
authoredJul 22, 2024··
Add --var-values flag to regal test command (#930)
Fixes #876 Signed-off-by: Anders Eknert <anders@styra.com>
1 parent 8382e1c commit 886ef2e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed
 

‎cmd/test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type testCommandParams struct {
4949
runRegex string
5050
count int
5151
skipExitZero bool
52+
varValues bool
5253
}
5354

5455
func newTestCommandParams() *testCommandParams {
@@ -167,7 +168,8 @@ func opaTest(args []string) int {
167168
WithEnablePrintStatements(!testParams.benchmark).
168169
WithSchemas(compile.RegalSchemaSet()).
169170
WithUseTypeCheckAnnotations(true).
170-
WithModuleLoader(moduleLoader(regalBundle))
171+
WithModuleLoader(moduleLoader(regalBundle)).
172+
WithRewriteTestRules(testParams.varValues)
171173

172174
if testParams.threshold > 0 && !testParams.coverage {
173175
testParams.coverage = true
@@ -192,6 +194,7 @@ func opaTest(args []string) int {
192194
SetCompiler(compiler).
193195
SetStore(store).
194196
CapturePrintOutput(true).
197+
EnableTracing(testParams.verbose || testParams.varValues).
195198
SetCoverageQueryTracer(coverTracer).
196199
SetRuntime(Runtime()).
197200
SetModules(modules).
@@ -256,6 +259,8 @@ func testReporter(cov *cover.Cover, modules map[string]*ast.Module) tester.Repor
256259
BenchmarkResults: testParams.benchmark,
257260
BenchMarkShowAllocations: testParams.benchMem,
258261
BenchMarkGoBenchFormat: goBench,
262+
FailureLine: testParams.varValues,
263+
LocalVars: testParams.varValues,
259264
}
260265
}
261266
} else {
@@ -358,6 +363,8 @@ func init() {
358363
"benchmark the unit tests")
359364
testCommand.Flags().StringVarP(&testParams.runRegex, "run", "r", "",
360365
"run only test cases matching the regular expression.")
366+
testCommand.Flags().BoolVar(&testParams.varValues,
367+
"var-values", false, "show local variable values in test output")
361368

362369
addPprofFlag(testCommand.Flags())
363370
addBundleModeFlag(testCommand.Flags(), &testParams.bundleMode, false)

0 commit comments

Comments
 (0)
Please sign in to comment.