forked from vdobler/ht
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
78 lines (70 loc) · 1.83 KB
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2014 Volker Dobler. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"flag"
"fmt"
"github.com/vdobler/ht/ht"
"github.com/vdobler/ht/internal/json5"
)
var cmdList = &Command{
RunSuites: runList,
Usage: "list [flags] <suite>...",
Description: "list tests in suits",
Flag: flag.NewFlagSet("run", flag.ContinueOnError),
Help: `
List loads the given suites, unrolls the tests, prepares
the tests and prints the list of tests.
`,
}
var (
checkFlag bool
fullFlag bool
)
func init() {
cmdList.Flag.BoolVar(&checkFlag, "check", false,
"including checks inlisting")
cmdList.Flag.BoolVar(&fullFlag, "full", false,
"print complete tests")
}
func runList(cmd *Command, suites []*ht.Suite) {
// TODO: provide templated output
for sNo, suite := range suites {
stitle := fmt.Sprintf("Suite %d: %s", sNo+1, suite.Name)
fmt.Printf("%s\n", ht.Underline(stitle, "-", ""))
for tNo, test := range suite.Setup {
id := fmt.Sprintf("%d.u%d", sNo+1, tNo+1)
displayTest(id, test)
}
for tNo, test := range suite.Tests {
id := fmt.Sprintf("%d.%d", sNo+1, tNo+1)
displayTest(id, test)
}
for tNo, test := range suite.Teardown {
id := fmt.Sprintf("%d.d%d", sNo+1, tNo+1)
displayTest(id, test)
}
}
}
func displayTest(id string, test *ht.Test) {
fmt.Printf("%-6s %s\n", id, test.Name)
if fullFlag {
buf, err := json5.MarshalIndent(test, " ", " ")
if err != nil {
buf = []byte(err.Error())
}
fmt.Println(" ", string(buf))
fmt.Println()
} else if checkFlag {
for _, check := range test.Checks {
name := ht.NameOf(check)
buf, err := json5.Marshal(check)
if err != nil {
buf = []byte(err.Error())
}
fmt.Printf(" %-14s %s\n", name, buf)
}
fmt.Println()
}
}