forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool_lint_test.go
77 lines (74 loc) · 3.07 KB
/
tool_lint_test.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
package main
import (
"strings"
"testing"
)
func TestLintApp(t *testing.T) {
tc := []testMainCase{
{
args: []string{"tool", "lint"},
errShouldBe: "flag: help requested",
},
{
args: []string{"tool", "lint", "../../tests/integ/run_main/"},
stderrShouldContain: "./../../tests/integ/run_main: gno.mod file not found in current or any parent directory (code=1)",
errShouldBe: "exit code: 1",
},
{
args: []string{"tool", "lint", "../../tests/integ/undefined_variable_test/undefined_variables_test.gno"},
stderrShouldContain: "undefined_variables_test.gno:6:28: name toto not declared (code=2)",
errShouldBe: "exit code: 1",
},
{
args: []string{"tool", "lint", "../../tests/integ/package_not_declared/main.gno"},
stderrShouldContain: "main.gno:4:2: name fmt not declared (code=2)",
errShouldBe: "exit code: 1",
},
{
args: []string{"tool", "lint", "../../tests/integ/several-lint-errors/main.gno"},
stderrShouldContain: "../../tests/integ/several-lint-errors/main.gno:5:5: expected ';', found example (code=3)\n../../tests/integ/several-lint-errors/main.gno:6",
errShouldBe: "exit code: 1",
},
{
args: []string{"tool", "lint", "../../tests/integ/several-files-multiple-errors/main.gno"},
stderrShouldContain: func() string {
lines := []string{
"../../tests/integ/several-files-multiple-errors/file2.gno:3:5: expected 'IDENT', found '{' (code=3)",
"../../tests/integ/several-files-multiple-errors/file2.gno:5:1: expected type, found '}' (code=3)",
"../../tests/integ/several-files-multiple-errors/main.gno:5:5: expected ';', found example (code=3)",
"../../tests/integ/several-files-multiple-errors/main.gno:6:2: expected '}', found 'EOF' (code=3)",
}
return strings.Join(lines, "\n") + "\n"
}(),
errShouldBe: "exit code: 1",
},
{
args: []string{"tool", "lint", "../../tests/integ/minimalist_gnomod/"},
// TODO: raise an error because there is a gno.mod, but no .gno files
},
{
args: []string{"tool", "lint", "../../tests/integ/invalid_module_name/"},
// TODO: raise an error because gno.mod is invalid
},
{
args: []string{"tool", "lint", "../../tests/integ/invalid_gno_file/"},
stderrShouldContain: "../../tests/integ/invalid_gno_file/invalid.gno:1:1: expected 'package', found packag (code=2)",
errShouldBe: "exit code: 1",
},
{
args: []string{"tool", "lint", "../../tests/integ/typecheck_missing_return/"},
stderrShouldContain: "../../tests/integ/typecheck_missing_return/main.gno:5:1: missing return (code=4)",
errShouldBe: "exit code: 1",
},
{
args: []string{"tool", "lint", "../../tests/integ/init/"},
// stderr / stdout should be empty; the init function and statements
// should not be executed
},
// TODO: 'gno mod' is valid?
// TODO: are dependencies valid?
// TODO: is gno source using unsafe/discouraged features?
// TODO: check for imports of native libs from non _test.gno files
}
testMainCaseRun(t, tc)
}