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

ast.CommentGroup.Text() shouldn't be used to read expected test's outputs #627

Closed
tbruyelle opened this issue Mar 21, 2023 · 0 comments · Fixed by #628
Closed

ast.CommentGroup.Text() shouldn't be used to read expected test's outputs #627

tbruyelle opened this issue Mar 21, 2023 · 0 comments · Fixed by #628

Comments

@tbruyelle
Copy link
Contributor

Description

filetest can provide the expected output by using a comment prefixed with // Output:. It's useful to assert for instance Render functions :

package main

import (
	"gno.land/r/gnoland/faucet"
)

func main() {
	println(faucet.Render(""))
}

// Output:
// # Community Faucet.
//
// Status: active.
// Balance: 200000000ugnot.
// Total transfers:  (in 0 times).
//
// Package address: g17rgsdnfxzza0sdfsdma37sdwxagsz378833ca4
//
// Admin: g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5
//
//  Controllers:
//
//
//
// Per request limit: 350000000ugnot

When gnodev test executes this kind of test, it reads this comment and compare it with the test outputs. If it doesn't match, the test fails. The problem comes from how those comments are read, because it currently uses ast.CommentGroup.Text() method, which reduces multiple lines into one (see method comment).

So typically for the example above, it's not possible to

  • run gnodev test -update-golden-tests
  • run gnodev test
    without having a failure at the second run, because the 3 empty lines between Controllers and Per request limit are reduced to one before comparison.

Steps to reproduce

The example above doesn't exist yet in the codebase, it's part of a fix I wanted to provide for #621. Anyway it should be easy to reproduce by testing a Render that returns multiple empty lines.

tbruyelle added a commit to tbruyelle/gno that referenced this issue Mar 21, 2023
Fix gnolang#621

`Render` prints the controllers in a loop but relies on
`gControllersSize` rather than `gControllers.Size()` to determine the
number of controllers. The fix simply replaces `gControllersSize` by
`gControllers.Size()`.

Fix gnolang#627

filetest `Output:` directive doesn't work when the output contains
multiple consecutive empty lines, because the method used to collect
those comments truncate them (see issue and `ast.CommentGroup.Text()`).
The fix replaces this method by a custom one that doesn't truncate.
tbruyelle added a commit to tbruyelle/gno that referenced this issue Apr 3, 2023
Fix gnolang#621

`Render` prints the controllers in a loop but relies on
`gControllersSize` rather than `gControllers.Size()` to determine the
number of controllers. The fix simply replaces `gControllersSize` by
`gControllers.Size()`.

Fix gnolang#627

filetest `Output:` directive doesn't work when the output contains
multiple consecutive empty lines, because the method used to collect
those comments truncate them (see issue and `ast.CommentGroup.Text()`).
The fix replaces this method by a custom one that doesn't truncate.
@moul moul closed this as completed in #628 Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

1 participant