From e68efadabc2e415ac738f68e4b1319a30d0b0248 Mon Sep 17 00:00:00 2001 From: zongz Date: Thu, 19 Dec 2024 20:21:49 +0800 Subject: [PATCH] fix: add a test case for kcl issue 1788 Signed-off-by: zongz --- pkg/client/issues_test.go | 35 +++++++++++++++++++ .../kcl-lang/kcl/issues/1788/README.md | 9 +++++ .../kcl-lang/kcl/issues/1788/mod/main.k | 1 + 3 files changed, 45 insertions(+) create mode 100644 pkg/client/test_data/issues/github.com/kcl-lang/kcl/issues/1788/README.md create mode 100644 pkg/client/test_data/issues/github.com/kcl-lang/kcl/issues/1788/mod/main.k diff --git a/pkg/client/issues_test.go b/pkg/client/issues_test.go index 19dba65f..946e7085 100644 --- a/pkg/client/issues_test.go +++ b/pkg/client/issues_test.go @@ -554,3 +554,38 @@ func TestKclIssue1768(t *testing.T) { } RunTestWithGlobalLockAndKpmCli(t, []TestSuite{{Name: "test_push_with_tag", TestFunc: test_push_with_tag}}) } + +func TestKclIssue1788(t *testing.T) { + testPath := "github.com/kcl-lang/kcl/issues/1788" + + test_run_only_file_not_generate_mod := func(t *testing.T, kpmcli *KpmClient) { + rootPath := getTestDir("issues") + kfilePath := filepath.Join(rootPath, testPath, "mod", "main.k") + var buf bytes.Buffer + kpmcli.SetLogWriter(&buf) + + res, err := kpmcli.Run( + WithRunSource( + &downloader.Source{ + Local: &downloader.Local{ + Path: kfilePath, + }, + }, + ), + ) + + if err != nil { + t.Fatal(err) + } + + modFilePath := filepath.Join(testPath, "kcl.mod") + modLockFilePath := filepath.Join(testPath, "kcl.mod.lock") + + assert.Equal(t, res.GetRawYamlResult(), "The_first_kcl_program: Hello World!") + assert.Equal(t, buf.String(), "") + assert.Equal(t, utils.DirExists(modFilePath), false) + assert.Equal(t, utils.DirExists(modLockFilePath), false) + } + + RunTestWithGlobalLockAndKpmCli(t, []TestSuite{{Name: "test_run_only_file_not_generate_mod", TestFunc: test_run_only_file_not_generate_mod}}) +} diff --git a/pkg/client/test_data/issues/github.com/kcl-lang/kcl/issues/1788/README.md b/pkg/client/test_data/issues/github.com/kcl-lang/kcl/issues/1788/README.md new file mode 100644 index 00000000..4d31390d --- /dev/null +++ b/pkg/client/test_data/issues/github.com/kcl-lang/kcl/issues/1788/README.md @@ -0,0 +1,9 @@ +## Bug Report + +https://github.com/kcl-lang/kcl/issues/1788 + +When I run the kcl run path/to/files command from a directory that does not contain a root path, kcl.mod and kcl.mod.lock files are generated in the directory specified on the command line path to run. However, I did not intend for the specified path to become a root path and it can be unclear why it is being treated as one. Why does the kcl.mod file get created automatically? Is there any way to change this default behavior so that I don't have files auto generated in places I don't expect and that will affect the results of running kcl code? + +### What is your KCL components version? (Required) + +kcl version: 0.11.0-alpha.1 diff --git a/pkg/client/test_data/issues/github.com/kcl-lang/kcl/issues/1788/mod/main.k b/pkg/client/test_data/issues/github.com/kcl-lang/kcl/issues/1788/mod/main.k new file mode 100644 index 00000000..fa7048e6 --- /dev/null +++ b/pkg/client/test_data/issues/github.com/kcl-lang/kcl/issues/1788/mod/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file