-
Notifications
You must be signed in to change notification settings - Fork 15
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
Print all failed test in a test suite which is an arr.ai tuple. #631
base: master
Are you sure you want to change the base?
Changes from all commits
77cd8ef
05628d5
bbdd36f
cea3f75
fd90cab
fe55ff7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,10 @@ func (e *TupleExpr) String() string { //nolint:dupl | |
|
||
// Eval returns the subject | ||
func (e *TupleExpr) Eval(ctx context.Context, local Scope) (Value, error) { | ||
if cmd, isStr := ctx.Value(CmdIdentifier{Name: "test"}).(string); isStr && cmd == "test" { | ||
return e.evalTests(ctx, local) | ||
} | ||
|
||
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. This shouldn't be required. 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.
This is current definition of |
||
tuple := EmptyTuple | ||
var err error | ||
for _, attr := range e.attrs { | ||
|
@@ -151,3 +155,22 @@ func (e *TupleExpr) Eval(ctx context.Context, local Scope) (Value, error) { | |
// TODO: Construct new tuple directly | ||
return tuple.(*GenericTuple).Canonical(), nil | ||
} | ||
|
||
func (e *TupleExpr) evalTests(ctx context.Context, local Scope) (Value, error) { | ||
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. As above, this should be in 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. Current code can't support this approach. The code 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. So my thinking is:
To do this, we first evaluate the file and get the data structure and walk through all of the nodes. For each leaf node, add an I'm going to make a key assumption here because it simplifies things a lot and will be largely true in practice. Assume that the data structure containing the test output is statically defined (i.e. a literal, not generated by some other code). Each branch is either a set, array, dict or tuple, and each leaf is some other kind of expression. So to get the failed comparison, parse the test file and walk the AST in search of the lowest tuple or sequence attribute found in the failed path. If there are multiple (e.g. Once you have the leaf node (unevaluated at this point), search inside that for a comparison operator (something that returns true: Evaluate that modified AST and walk it, compiling the report from the leaf tuples. Fin. I expect that I'm glossing over the complexity of "find the comparison", but it's conceptually possible. You might argue "wow that's hard; this PR is an improvement, shouldn't we just merge it and do the more complete solution as a follow-up?" Maybe. I'm wary because a) it's mixing test code with implementation which is a code smell for both test and implementation code, and b) it's not in the same direction as the solution described above; we would ultimately plan to delete this test code, so why commit it in the first place and add an extra complexity and maintenance burden? |
||
tuple := EmptyTuple | ||
var err error | ||
var errs Errors | ||
for _, attr := range e.attrs { | ||
tuple, err = attr.Apply(ctx, local, tuple) | ||
if err != nil { | ||
errs.errors = append(errs.errors, WrapContextErr(err, e, local)) | ||
tuple = EmptyTuple | ||
} | ||
} | ||
if len(errs.errors) > 0 { | ||
return nil, errs | ||
} | ||
|
||
// TODO: Construct new tuple directly | ||
return tuple.(*GenericTuple).Canonical(), nil | ||
} |
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.
This should live in
internal/test/
, since it should only be used in the case of testing.In general, test-related code should not be mixed in with implementation code.