mirror of
https://github.com/dragonheim/gagent.git
synced 2025-05-24 04:16:47 -07:00
feat: added some more test harness.
This commit is contained in:
parent
7f9a5777bd
commit
bdeaf2ec92
8 changed files with 513 additions and 59 deletions
|
@ -12,16 +12,15 @@ import (
|
|||
|
||||
var fname = flag.String("f", "", "file name")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
func RunPicol(fname string) error {
|
||||
interp := picol.NewInterpreter()
|
||||
interp.RegisterCoreCommands()
|
||||
|
||||
buf, err := ioutil.ReadFile(*fname)
|
||||
buf, err := ioutil.ReadFile(fname)
|
||||
if err == nil {
|
||||
result, err := interp.Eval(string(buf))
|
||||
if err != nil {
|
||||
fmt.Println("ERRROR", result, err)
|
||||
return fmt.Errorf("Error: %s, Result: %s", err, result)
|
||||
}
|
||||
} else {
|
||||
for {
|
||||
|
@ -30,8 +29,17 @@ func main() {
|
|||
clibuf, _ := scanner.ReadString('\n')
|
||||
result, err := interp.Eval(clibuf[:len(clibuf)-1])
|
||||
if len(result) != 0 {
|
||||
fmt.Println("ERRROR", result, err)
|
||||
return fmt.Errorf("Error: %s, Result: %s", err, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
err := RunPicol(*fname)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
|
31
pkg/picol/picol_unused/main_test.go_unused
Normal file
31
pkg/picol/picol_unused/main_test.go_unused
Normal file
|
@ -0,0 +1,31 @@
|
|||
package main_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
picol "github.com/dragonheim/gagent/pkg/picol/picol_unused"
|
||||
)
|
||||
|
||||
func Test_RunPicol(t *testing.T) {
|
||||
// Create a temporary test file
|
||||
content := []byte("set a 5\nset b 7\n+ $a $b\n")
|
||||
tmpfile, err := ioutil.TempFile("", "picol_test")
|
||||
if err != nil {
|
||||
t.Fatalf("Error creating temporary test file: %v", err)
|
||||
}
|
||||
defer os.Remove(tmpfile.Name()) // clean up
|
||||
|
||||
if _, err := tmpfile.Write(content); err != nil {
|
||||
t.Fatalf("Error writing content to temporary test file: %v", err)
|
||||
}
|
||||
if err := tmpfile.Close(); err != nil {
|
||||
t.Fatalf("Error closing temporary test file: %v", err)
|
||||
}
|
||||
|
||||
err = picol.RunPicol(tmpfile.Name())
|
||||
if err != nil {
|
||||
t.Errorf("Error during RunPicol: %v", err)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue