-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp_test.go.bkp
176 lines (144 loc) · 4.87 KB
/
help_test.go.bkp
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package main
import (
"fmt"
"github.com/Netflix/go-expect"
"github.com/cucumber/godog"
"io/ioutil"
"log"
"os"
"os/exec"
"regexp"
"strings"
"testing"
"time"
)
const (
timeout = 4 * time.Second
helpRaw = `invowk is a code execution & sharing engine exposed as an user-extensible CLI.
Why is it an 'execution engine'?
Because invowk helps you run code/scripts encapsulated as custom user-made
commands! Such commands can be written as/in:
- shell scripts (e.g.: bash, zsh, cmd, powershell)
- dynamic languages (e.g.: python, js/node.js, ruby)
- compiled languages (e.g.: java, go, rust, c/c++)
They can be run against the host machine or a Docker container, all in the
most seamless fashion.
Why is it a 'sharing engine'?
Because invowk helps you import/export custom user-made commands so that you
can easily run other people's code/automations/ideas and vice-versa!
We even have several curated custom commands that you can try out-of-the-box.
Why is it an 'user-extensible CLI'?
Because invowk is a kind of 'meta-CLI': it is designed so that its users can
extend it with custom commands that add the real value to the CLI and invowk
ecosystem! It also makes receiving (via flags or fancy interactive prompts)
and validating inputs a complete breeze.
Usage:
invowk [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
config A brief description of your command
help Help about any command
Flags:
--config string config file (default is $HOME/.config/invowk/invowk.toml)
-h, --help help for invowk
-t, --toggle Help message for toggle
`
)
type TestRunner struct {
console *expect.Console
cmd *exec.Cmd
}
func (t *TestRunner) anOpenTTY() error {
//c, err := expect.NewConsole(expect.WithStdout(os.Stdout))
//if err != nil {
// return err
//}
//
//t.console = c
return nil
}
func (t *TestRunner) iSuccessfullyRun(arg1 string) error {
cmd := exec.Command("./invowk", arg1)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Start()
if err != nil {
return err
}
t.cmd = cmd
return nil
}
func (t *TestRunner) theTUIOutputShouldContainTheContentFromWhichRendersTo(arg1 string, arg2 *godog.DocString) error {
content, err := ioutil.ReadFile("features/data/" + arg1)
if err != nil {
log.Fatal(err)
}
var expectedPattern = regexp.QuoteMeta(string(content))
expectedPattern = regexp.MustCompile("\n").ReplaceAllString(expectedPattern, " *\r*\n")
expectedRegexPattern := regexp.MustCompile("\r*\n*" + expectedPattern)
out, err := t.console.Expect(
expect.Regexp(expectedRegexPattern),
expect.WithTimeout(timeout))
if err != nil {
fmt.Println(out)
return err
}
return nil
}
func (t *TestRunner) theTerminalOutputShouldContain(arg1 *godog.DocString) error {
//result = strings.ReplaceAll(result, "\r", "")
//result = strings.ReplaceAll(result, " +\n+", "\n")
//result = regexp.MustCompile(" +\n").ReplaceAllString(result, "\n")
//result = regexp.MustCompile(" +\r").ReplaceAllString(result, "\n")
var expectedPattern = regexp.QuoteMeta(arg1.Content)
//expectedPattern = strings.ReplaceAll(arg1.Content, "\r", "")
//expectedPattern = regexp.MustCompile("\r").ReplaceAllString(expectedPattern, " *\r")
expectedPattern = regexp.MustCompile("\n").ReplaceAllString(expectedPattern, " *\r*\n")
expectedRegexPattern := regexp.MustCompile("\r*\n*" + expectedPattern)
out, err := t.console.Expect(
expect.Regexp(expectedRegexPattern),
expect.WithTimeout(timeout))
//arg1.Content = strings.ReplaceAll(arg1.Content, "\r", "")
arg1.Content = strings.ReplaceAll(arg1.Content, " +\n", "\n")
//arg1.Content = regexp.MustCompile(" +\n").ReplaceAllString(arg1.Content, "\n")
//arg1.Content = regexp.MustCompile(" +\r").ReplaceAllString(arg1.Content, "\n")
if err != nil {
fmt.Println(out)
return err
}
return nil
}
func InitializeScenario(ctx *godog.ScenarioContext) {
tr := TestRunner{}
if err := exec.Command("go", "build", ".").Run(); err != nil {
log.Fatal(err)
return
}
//defer func() {
// err := os.Remove("invowk")
// if err != nil {
// fmt.Println("Couldn't remove the compiled 'invowk' binary")
// }
//}()
ctx.Step(`^an open TTY$`, tr.anOpenTTY)
ctx.Step(`^I successfully run "([^"]*)"$`, tr.iSuccessfullyRun)
ctx.Step(`^the terminal output should contain:$`, tr.theTerminalOutputShouldContain)
ctx.Step(`^the TUI output should contain the content from "([^"]*)", which renders to:$`, tr.theTUIOutputShouldContainTheContentFromWhichRendersTo)
if tr.console != nil {
defer tr.console.Close()
}
}
func TestFeatures(t *testing.T) {
suite := godog.TestSuite{
ScenarioInitializer: InitializeScenario,
Options: &godog.Options{
Format: "pretty",
Paths: []string{"features"},
TestingT: t, // Testing instance that will run subtests.
},
}
if suite.Run() != 0 {
t.Fatal("non-zero status returned, failed to run feature tests")
}
}