-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmain_test.go
More file actions
78 lines (69 loc) · 1.85 KB
/
Copy pathmain_test.go
File metadata and controls
78 lines (69 loc) · 1.85 KB
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
package main_test
import (
"context"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"github.com/s4wave/goscript/compiler"
"github.com/sirupsen/logrus"
)
func TestBuildRunExampleSimple(t *testing.T) {
// Set up paths
projectDir, err := filepath.Abs(".")
if err != nil {
t.Fatalf("failed to determine project directory: %v", err)
}
outputDir := filepath.Join(projectDir, "output")
if err := os.RemoveAll(outputDir); err != nil {
t.Fatalf("failed to remove output directory: %v", err)
}
t.Cleanup(func() {
if err := os.RemoveAll(outputDir); err != nil {
t.Logf("failed to clean output directory: %v", err)
}
})
// Initialize the compiler
logger := logrus.New()
logger.SetLevel(logrus.DebugLevel)
le := logrus.NewEntry(logger)
conf := &compiler.Config{
OutputPath: outputDir,
}
if err := conf.Validate(); err != nil {
t.Fatalf("invalid compiler config: %v", err)
}
comp, err := compiler.NewCompiler(conf, le, nil)
if err != nil {
t.Fatalf("failed to create compiler: %v", err)
}
if _, err = comp.CompilePackages(context.Background(), "."); err != nil {
t.Fatalf("failed to compile example: %v", err)
}
if _, statErr := os.Stat(filepath.Join(outputDir, "@goscript", "example", "main.gs.ts")); statErr != nil {
t.Fatalf("generated main output missing: %v", statErr)
}
cmd := exec.Command("bun", "run", "./main.ts")
cmd.Dir = projectDir
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("failed to run generated example: %v\n%s", err, output)
}
out := string(output)
for _, want := range []string{
"GoScript feature tour",
"struct: ada 12 go typescript",
"interface: ada",
"set: true false 3",
"filter: 2 2 4",
"min: 3 4 go",
"channel: 3 1 3",
"select: buffered",
"cleanup: simple",
} {
if !strings.Contains(out, want) {
t.Fatalf("missing %q in example output:\n%s", want, out)
}
}
}