Skip to content

Commit

Permalink
cmd/screentest,internal/screentest: add ints function, release notes …
Browse files Browse the repository at this point in the history
…tests

This CL is preparation for converting release notes to Markdown.
We want to use the screentest tool to help us minimize changes.

- internal/screentest: add a template function to generate a sequence
  of integers

- cmd/screentest/testdata: add relnotes.txt, which has a test for
  every release note.

Change-Id: Ibeb2419637bc73d93b88d4c378f5396967d3d70f
Reviewed-on: https://go-review.googlesource.com/c/website/+/539496
TryBot-Result: Gopher Robot <[email protected]>
Run-TryBot: Jonathan Amsterdam <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
  • Loading branch information
jba committed Nov 10, 2023
1 parent b8642e1 commit 91adbee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions cmd/screentest/testdata/relnotes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
windowsize 1536x960
compare https://go.dev http://localhost:6060/go.dev


test rl0
pathname /doc/go1
capture fullscreen

{{range ints 1 22}}
test rl{{.}}
pathname /doc/go1.{{.}}
capture fullscreen
{{end}}
11 changes: 10 additions & 1 deletion internal/screentest/screentest.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,16 @@ func (t *testcase) String() string {

// readTests parses the testcases from a text file.
func readTests(file string, vars map[string]string) ([]*testcase, error) {
tmpl, err := template.ParseFiles(file)
tmpl := template.New(filepath.Base(file)).Funcs(template.FuncMap{
"ints": func(start, end int) []int {
var out []int
for i := start; i < end; i++ {
out = append(out, i)
}
return out
},
})
_, err := tmpl.ParseFiles(file)
if err != nil {
return nil, fmt.Errorf("template.ParseFiles(%q): %w", file, err)
}
Expand Down

0 comments on commit 91adbee

Please sign in to comment.