-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
113 lines (99 loc) · 2.41 KB
/
main.go
File metadata and controls
113 lines (99 loc) · 2.41 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
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
package main
import (
"fmt"
"os"
"strings"
)
// TestCase represents a single test case
type TestCase struct {
Name string
Input string
Expected string
Description string
}
// TestResult represents the result of running a test
type TestResult struct {
TestCase TestCase
Passed bool
Output string
Error string
}
func parseTestFile(content string) (TestCase, error) {
lines := strings.Split(content, "\n")
if len(lines) < 4 {
return TestCase{}, fmt.Errorf("invalid test file format")
}
// Format:
// name: Test Name
// description: Test Description
// input: |
// test input
// expected: |
// expected output
var testCase TestCase
var currentSection string
var currentContent strings.Builder
for _, line := range lines {
if strings.HasPrefix(line, "name: ") {
testCase.Name = strings.TrimPrefix(line, "name: ")
} else if strings.HasPrefix(line, "description: ") {
testCase.Description = strings.TrimPrefix(line, "description: ")
} else if strings.HasPrefix(line, "input: |") {
currentSection = "input"
currentContent.Reset()
} else if strings.HasPrefix(line, "expected: |") {
currentSection = "expected"
currentContent.Reset()
} else if currentSection != "" {
if line == "" && currentContent.Len() == 0 {
continue
}
currentContent.WriteString(line)
currentContent.WriteString("\n")
}
}
testCase.Input = strings.TrimSpace(currentContent.String())
return testCase, nil
}
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: gndtest <test-file>")
os.Exit(1)
}
testFile := os.Args[1]
// Read test file
content, err := os.ReadFile(testFile)
if err != nil {
fmt.Printf("Error reading test file: %v\n", err)
os.Exit(1)
}
// Parse test case
testCase, err := parseTestFile(string(content))
if err != nil {
fmt.Printf("Error parsing test case: %v\n", err)
os.Exit(1)
}
// Run test
result := runTest(testCase)
// Print result
if result.Passed {
fmt.Printf("✓ Test '%s' passed\n", testCase.Name)
} else {
fmt.Printf("✗ Test '%s' failed\n", testCase.Name)
if result.Error != "" {
fmt.Printf("Error: %s\n", result.Error)
}
if result.Output != "" {
fmt.Printf("Output: %s\n", result.Output)
}
os.Exit(1)
}
}
func runTest(testCase TestCase) TestResult {
// TODO: Implement actual test execution using gnd
// For now, just return a placeholder result
return TestResult{
TestCase: testCase,
Passed: true,
}
}