Skip to content

Commit

Permalink
Merge branch 'kcl-lang:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
d4v1d03 authored May 28, 2024
2 parents 94096ce + 9215818 commit 7529b30
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,8 @@ func (c *KpmClient) AddDepToPkg(kclPkg *pkg.KclPkg, d *pkg.Dependency) error {

// If the dependency is from the local path, do nothing.
if d.IsFromLocal() {
kclPkg.ModFile.Dependencies.Deps[d.Name] = *d
kclPkg.Dependencies.Deps[d.Name] = *d
return nil
}

Expand Down
40 changes: 40 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1500,3 +1500,43 @@ func testRunWithOciDownloader(t *testing.T) {
strings.Contains(buf.String(), "downloading 'zong-zhe/helloworld:0.0.3' from 'ghcr.io/zong-zhe/helloworld:0.0.3'")
assert.Equal(t, res.GetRawYamlResult(), "The_first_kcl_program: Hello World!")
}

func TestAddLocalPath(t *testing.T) {

kpmCli, err := NewKpmClient()
assert.Equal(t, err, nil)

path := getTestDir("test_add_local_path")
err = copy.Copy(filepath.Join(path, "kcl.mod.bak"), filepath.Join(path, "kcl.mod"))
assert.Equal(t, err, nil)

kclPkg, err := kpmCli.LoadPkgFromPath(path)
assert.Equal(t, err, nil)

opts := opt.AddOptions{
LocalPath: path,
RegistryOpts: opt.RegistryOptions{
Local: &opt.LocalOptions{
Path: filepath.Join(path, "dep"),
},
},
}
_, err = kpmCli.AddDepWithOpts(kclPkg, &opts)
assert.Equal(t, err, nil)

modFile, err := kpmCli.LoadModFile(path)
assert.Equal(t, err, nil)
assert.Equal(t, len(modFile.Deps), 1)
assert.Equal(t, modFile.Deps["dep"].Name, "dep")
assert.Equal(t, modFile.Deps["dep"].LocalFullPath, filepath.Join(path, "dep"))

kclPkg1, err := kpmCli.LoadPkgFromPath(path)
assert.Equal(t, err, nil)
assert.Equal(t, kclPkg1.Dependencies.Deps["dep"].Name, "dep")
assert.Equal(t, kclPkg1.Dependencies.Deps["dep"].FullName, "dep_0.0.1")
assert.Equal(t, kclPkg1.Dependencies.Deps["dep"].Version, "0.0.1")
defer func() {
_ = os.Remove(filepath.Join(path, "kcl.mod.lock"))
_ = os.Remove(filepath.Join(path, "kcl.mod"))
}()
}
5 changes: 5 additions & 0 deletions pkg/client/test_data/test_add_local_path/dep/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "dep"
edition = "v0.9.0"
version = "0.0.1"

Empty file.
1 change: 1 addition & 0 deletions pkg/client/test_data/test_add_local_path/dep/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World!'
5 changes: 5 additions & 0 deletions pkg/client/test_data/test_add_local_path/kcl.mod.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "test_add_local_path"
edition = "v0.9.0"
version = "0.0.1"

Empty file.
1 change: 1 addition & 0 deletions pkg/client/test_data/test_add_local_path/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World!'

0 comments on commit 7529b30

Please sign in to comment.