Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add a test case for kcl issue 1788 #572

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions pkg/client/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}})
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World!'
Loading