-
Notifications
You must be signed in to change notification settings - Fork 3
/
ircts.go
137 lines (116 loc) · 3.32 KB
/
ircts.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright (c) 2019 Daniel Oaks <[email protected]>
// Copyright (c) 2019 Shivaram Lingamneni
// released under the MIT license
package main
import (
"fmt"
"log"
"strings"
"github.com/goshuirc/irc-go/ircmsg"
"github.com/ircdocs/ircts/lib/tests"
"github.com/docopt/docopt-go"
"github.com/ircdocs/ircts/lib"
"github.com/ircdocs/ircts/lib/conn"
"github.com/ircdocs/ircts/lib/utils"
)
func main() {
usage := `ircts.
ircts is an IRC Test Suite, designed to test software's compatibility with
accepted standards and common behaviour. To run it, simply setup the config
file to point it towards the server, and go!
Usage:
ircts run [--config <file>] [--verbose]
ircts -h | --help
ircts --version
Options:
--config <file> Configuration file [default: ircts.yaml].
-v --verbose Show more detail while running tests.
-h --help Show this screen.
--version Show version.`
arguments, _ := docopt.ParseArgs(usage, nil, lib.SemVer)
if arguments["run"].(bool) {
// load config
config, err := utils.LoadConfig(arguments["--config"].(string))
if err != nil {
log.Fatalln("Failed to load config:", err.Error())
}
// create connection list
connectionPool := conn.NewConnectionPool()
rm := tests.NewRunManager()
rm.Pool = connectionPool
rm.Config = config
// mark all tests as N/A (not yet run)
for _, TG := range tests.AllTests {
for _, Test := range TG.Tests {
name := fmt.Sprintf("%s-%s", TG.Name, Test.Name)
rm.Results.Set(name, tests.NotApplicable, "Test cancelled and not run", "")
}
}
// get supported caps
c, err := rm.Pool.NewConnection(config.Server)
if err != nil {
log.Fatalln("Failed to connect to server for initial caps:", err.Error())
}
supportedCaps := make(map[string]bool)
capValues := make(map[string]string)
c.SendLine("CAP LS 302")
for err == nil {
line, err := c.GetLine()
if err != nil {
break
}
msg, err := ircmsg.ParseLine(line)
if err != nil {
break
}
if msg.Command == "CAP" {
if 2 < len(msg.Params) && strings.ToUpper(msg.Params[1]) == "LS" {
if msg.Params[2] == "*" {
for _, fullVal := range strings.Fields(msg.Params[3]) {
splitVal := strings.SplitN(fullVal, "=", 2)
name := splitVal[0]
var value string
if 1 < len(splitVal) {
value = splitVal[1]
}
supportedCaps[name] = true
capValues[name] = value
}
} else {
for _, fullVal := range strings.Fields(msg.Params[2]) {
splitVal := strings.SplitN(fullVal, "=", 2)
name := splitVal[0]
var value string
if 1 < len(splitVal) {
value = splitVal[1]
}
supportedCaps[name] = true
capValues[name] = value
}
c.SendLine("QUIT")
}
}
}
}
// eventually we'll just return it nicely instead
rm.Pool.DestroyConnection(c)
// start running tests!
for _, TG := range tests.AllTests {
fmt.Println("")
fmt.Println("Testing", TG.Name)
for _, Test := range TG.Tests {
fmt.Println("-", Test.Name)
name := fmt.Sprintf("%s-%s", TG.Name, Test.Name)
Test.Handler(name, rm)
}
}
// print basic results
fmt.Println("\n= Results =")
for _, TG := range tests.AllTests {
for _, Test := range TG.Tests {
name := fmt.Sprintf("%s-%s", TG.Name, Test.Name)
rm.Results.Print(name)
}
}
}
}