- Inject bonfire.Output from stdin/stdout/stderr with stdlib widgets and x/term - Degrade spinner, progress, table and prompts without a TTY or color - Reject plugin command names that are not namespace:verb
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"go/parser"
|
|
"go/token"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.golem15.com/golem15/summercms/bonfire"
|
|
)
|
|
|
|
func TestToolCommandNames(t *testing.T) {
|
|
var names []string
|
|
for _, c := range toolCommands() {
|
|
names = append(names, c.Name)
|
|
}
|
|
for _, want := range []string{"build", "make:plugin", "plugin:add"} {
|
|
if !slices.Contains(names, want) {
|
|
t.Fatalf("missing %s in %v", want, names)
|
|
}
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
root, err := bonfire.NewRoot("summer", toolCommands(), &buf)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
root.SetArgs([]string{"make:plugin", "--help"})
|
|
if err := root.Execute(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(buf.String(), "vendor.plugin") {
|
|
t.Fatalf("make:plugin help missing argument text:\n%s", buf.String())
|
|
}
|
|
}
|
|
|
|
func TestToolDoesNotImportExamplePlugins(t *testing.T) {
|
|
roots := []string{".", filepath.Join("..", "..", "internal", "build")}
|
|
fset := token.NewFileSet()
|
|
for _, root := range roots {
|
|
entries, err := os.ReadDir(root)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, entry := range entries {
|
|
name := entry.Name()
|
|
if entry.IsDir() || !strings.HasSuffix(name, ".go") {
|
|
continue
|
|
}
|
|
file, err := parser.ParseFile(fset, filepath.Join(root, name), nil, parser.ImportsOnly)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, spec := range file.Imports {
|
|
path, err := strconv.Unquote(spec.Path.Value)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if strings.Contains(path, "examples/hello") {
|
|
t.Fatalf("%s imports %s", name, path)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|