Skip to content

Commit 1a5729a

Browse files
authored
fix: add a test case for kcl issue 1788 (#572)
Signed-off-by: zongz <zongzhe1024@163.com>
1 parent 47dddb0 commit 1a5729a

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

pkg/client/issues_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,3 +554,38 @@ func TestKclIssue1768(t *testing.T) {
554554
}
555555
RunTestWithGlobalLockAndKpmCli(t, []TestSuite{{Name: "test_push_with_tag", TestFunc: test_push_with_tag}})
556556
}
557+
558+
func TestKclIssue1788(t *testing.T) {
559+
testPath := "github.com/kcl-lang/kcl/issues/1788"
560+
561+
test_run_only_file_not_generate_mod := func(t *testing.T, kpmcli *KpmClient) {
562+
rootPath := getTestDir("issues")
563+
kfilePath := filepath.Join(rootPath, testPath, "mod", "main.k")
564+
var buf bytes.Buffer
565+
kpmcli.SetLogWriter(&buf)
566+
567+
res, err := kpmcli.Run(
568+
WithRunSource(
569+
&downloader.Source{
570+
Local: &downloader.Local{
571+
Path: kfilePath,
572+
},
573+
},
574+
),
575+
)
576+
577+
if err != nil {
578+
t.Fatal(err)
579+
}
580+
581+
modFilePath := filepath.Join(testPath, "kcl.mod")
582+
modLockFilePath := filepath.Join(testPath, "kcl.mod.lock")
583+
584+
assert.Equal(t, res.GetRawYamlResult(), "The_first_kcl_program: Hello World!")
585+
assert.Equal(t, buf.String(), "")
586+
assert.Equal(t, utils.DirExists(modFilePath), false)
587+
assert.Equal(t, utils.DirExists(modLockFilePath), false)
588+
}
589+
590+
RunTestWithGlobalLockAndKpmCli(t, []TestSuite{{Name: "test_run_only_file_not_generate_mod", TestFunc: test_run_only_file_not_generate_mod}})
591+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Bug Report
2+
3+
https://github.com/kcl-lang/kcl/issues/1788
4+
5+
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?
6+
7+
### What is your KCL components version? (Required)
8+
9+
kcl version: 0.11.0-alpha.1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The_first_kcl_program = 'Hello World!'

0 commit comments

Comments
 (0)