Files
summercms/cmd/summer/main_test.go
Jakub Zych 270b7f1e87 feat(01-03): add summer dev watch rebuild loop
- Watch app sources with fsnotify, debounce, and one serialized build.App
- Restart the child only after a successful build and print rebuild latency
- Ignore generated app files and reap the child on cancellation
2026-09-16 13:59:43 +02:00

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", "dev"} {
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)
}
}
}
}
}