Added os:exec builtin (#2)
All checks were successful
Build / build (push) Successful in 2m39s

Co-authored-by: Leon Mika <lmika@lmika.com>
Reviewed-on: #2
This commit is contained in:
lmika 2025-10-24 06:09:45 +00:00
parent 7c76e61b08
commit dd516feed4
2 changed files with 79 additions and 4 deletions

View file

@ -2,8 +2,10 @@ package builtins_test
import (
"context"
"github.com/stretchr/testify/assert"
"testing"
"time"
"github.com/stretchr/testify/assert"
"ucl.lmika.dev/ucl"
"ucl.lmika.dev/ucl/builtins"
)
@ -34,3 +36,25 @@ func TestOS_Env(t *testing.T) {
})
}
}
func TestOS_Exec(t *testing.T) {
tests := []struct {
descr string
eval string
want any
}{
{descr: "run command 1", eval: `os:exec "echo" "hello, world"`, want: "hello, world\n"},
{descr: "run command 1", eval: `os:exec "date" "+%Y%m%d"`, want: time.Now().Format("20060102") + "\n"},
}
for _, tt := range tests {
t.Run(tt.descr, func(t *testing.T) {
inst := ucl.New(
ucl.WithModule(builtins.OS()),
)
res, err := inst.EvalString(context.Background(), tt.eval)
assert.NoError(t, err)
assert.Equal(t, tt.want, res)
})
}
}