-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Show line of failure in opa test
#961
Comments
opa run
opa test
It's possible to see the location by using |
Hrmmm. The location info the in the JSON output will include the line number of the test rule that failed not the expression in the rule that failed. We could get the line number of the expression with tracing though. This could be done in conjunction with #856. |
Here's a rough sketch of how we could implement this. Implementation notes
Exampletest.rego:
Output with
Output with
|
I will take a stab at this one |
I have this working but writing a unit test for this feature is a bit tricky In tester/runner_test.go (date 1541440882000) I created a new test where I have to set both tracing and EnableFailureLine() to true. The reason being I need tracing to figure out the line that fails and at the same time if only tracing is enabled, I should not present the line. Moreover, Run() is called from both the CLI and also the testing harness, with different code paths and reporting. func TestRunner_EnableFailureLine(t *testing.T) {
Do you prefer another approach? BTW, what is the reason the second to last event has the line that fails? |
@repenno I think that the runner can just instantiate it's own buffer tracer when line failures are enabled. Per my comment above, line failures ( |
Fixes #961 Added new option to opa test command (-l) Verbose (-v) as precedence over (-l) Example run: opa test test.rego -l data.foo.test_a: FAIL (754ns) (test.rego:4) data.foo.test_b: FAIL (382ns) (test.rego:8) ------------------------------------------------------- FAIL: 2/2 Signed-off-by: repenno <rapenno@gmail.com>
I typically define more than one definition in a test suite:
While I see the test suite that fails, I'm not able to find the exact line without manually removing lines of the tests to see if it still passes (extremely annoying & time-intensive). The
opa test
result is something like this, for example:It would probably safe me around 10 minutes of dumb trial & error searching per test if I knew which line the failure occurred at.
The text was updated successfully, but these errors were encountered: