Skip to content

Commit

Permalink
refactor: strict setting files config running
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <xpf6677@163.com>
  • Loading branch information
Peefy committed May 24, 2024
1 parent e160f6c commit 3c4438c
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 49 deletions.
31 changes: 0 additions & 31 deletions kclvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"sort"
"strconv"
"strings"
"sync"
"testing"

assert2 "github.com/stretchr/testify/assert"
Expand All @@ -37,36 +36,6 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}

func TestRunFiles(t *testing.T) {
_, err := kcl.RunFiles([]string{"./testdata/app0/kcl.yaml"})
if err != nil {
t.Fatal(err)
}
_, err = kcl.RunFiles([]string{"./testdata/app0/kcl.yaml"})
if err != nil {
t.Fatal(err)
}

chErr := make(chan error, 3)

var wg sync.WaitGroup
for i := 0; i < cap(chErr); i++ {
wg.Add(1)
go func() {
defer wg.Done()
_, e := kcl.RunFiles([]string{"./testdata/app0/kcl.yaml"})
chErr <- e
}()
}
wg.Wait()

for i := 0; i < cap(chErr); i++ {
if e := <-chErr; e != nil {
t.Fatal(e)
}
}
}

func TestStreamResult(t *testing.T) {
file, err := filepath.Abs("./testdata/stream/one_stream.k")
if err != nil {
Expand Down
6 changes: 0 additions & 6 deletions pkg/kcl/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ func TestKCLResultInt(t *testing.T) {
tAssert(t, *m == 1)
}

func TestRun_kcl_yaml(t *testing.T) {
const s = "../../testdata/app0/kcl.yaml"
_, err := RunFiles([]string{s})
tAssert(t, err == nil, err)
}

func TestRun(t *testing.T) {
const k_code = `
name = "kcl"
Expand Down
11 changes: 1 addition & 10 deletions pkg/kcl/opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,7 @@ func (p *Option) GetLogger() io.Writer {
func ParseArgs(pathList []string, opts ...Option) (Option, error) {
var tmpOptList []Option
for _, s := range pathList {
switch {
case strings.HasSuffix(s, ".k"):
tmpOptList = append(tmpOptList, WithKFilenames(s))
case strings.HasSuffix(s, ".yaml") || strings.HasSuffix(s, ".yml"):
tmpOptList = append(tmpOptList, WithSettings(s))
case isDir(s):
tmpOptList = append(tmpOptList, WithWorkDir(s))
default:
tmpOptList = append(tmpOptList, WithKFilenames(s))
}
tmpOptList = append(tmpOptList, WithKFilenames(s))
}

args := NewOption().Merge(opts...).Merge(tmpOptList...)
Expand Down
3 changes: 1 addition & 2 deletions pkg/settings/utils_settings_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ func LoadFile(filename string, src interface{}) (f *SettingsFile, err error) {

func (settings *SettingsFile) To_ExecProgram_Args() *gpyrpc.ExecProgram_Args {
args := &gpyrpc.ExecProgram_Args{
WorkDir: filepath.Dir(settings.Filename),

KFilenameList: []string{},
KCodeList: []string{},

Expand All @@ -106,6 +104,7 @@ func (settings *SettingsFile) To_ExecProgram_Args() *gpyrpc.ExecProgram_Args {
SortKeys: settings.Config.SortKeys,
ShowHidden: settings.Config.ShowHidden,
IncludeSchemaTypePath: settings.Config.IncludeSchemaTypePath,
PathSelector: settings.Config.PathSelector,
}
if settings.Config.Debug {
args.Debug = 1
Expand Down

0 comments on commit 3c4438c

Please sign in to comment.