Skip to content
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

chore(tests): don't panic on diff output #660

Closed
wants to merge 1 commit into from

Conversation

albttx
Copy link
Member

@albttx albttx commented Mar 28, 2023

Description

We don't need panic here, diff output is much more clear like that

@albttx albttx requested a review from a team as a code owner March 28, 2023 13:49
@albttx albttx self-assigned this Mar 28, 2023
Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't necessarily think of this as an improvement for the following reason:

  1. It prints the error without panicking only for the given situation (e.g. Output differs) - although all other branches still fail with the panic error and in an unfriendly way.
  2. There is a difference between panicking and os.Exit(1), and that is on whether the other goroutines execute (assuming the panicking one is appropriately recovered). This means that when panicking, for instance executing make test.gno, the other file tests are still executing1, while if we os.Exit, the program finishes execution and no other tests run2.

I think a better approach would be that of rewriting this function to return errors instead of panicking, if we want a quick solution. I think this one can be done in this PR. However there is a further improvement I think we could do to the gnodev test command - I've written it up on #665 as I think it goes a bit beyond the scope of this PR.

Footnotes

  1. image

  2. image

@thehowl
Copy link
Member

thehowl commented Jun 12, 2023

Any thoughts on this @albttx ?

@albttx
Copy link
Member Author

albttx commented Jun 12, 2023

Hello,

The code has been updated to:

						if resWanted == "" {
							panic(fmt.Sprintf("fail on %s: got unexpected output: %s", path, res))
						} else {
							diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
								A:        difflib.SplitLines(resWanted),
								B:        difflib.SplitLines(res),
								FromFile: "Expected",
								FromDate: "",
								ToFile:   "Actual",
								ToDate:   "",
								Context:  1,
							})
							panic(fmt.Sprintf("fail on %s: diff:\n%s\n", path, diff))
						}

which is better, but i agree with you, returning an error and have a cleaning "stop" would be a better solution

@thehowl
Copy link
Member

thehowl commented Aug 24, 2023

@albttx did you forget to push?

@albttx albttx closed this Aug 24, 2023
@albttx
Copy link
Member Author

albttx commented Aug 24, 2023

@thehowl sorry, it's been fixed with one of Thomas PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants