diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index f0de55fc..ea51088b 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -19,6 +19,7 @@ import ( "kcl-lang.io/kpm/pkg/git" "kcl-lang.io/kpm/pkg/opt" pkg "kcl-lang.io/kpm/pkg/package" + "kcl-lang.io/kpm/pkg/reporter" "kcl-lang.io/kpm/pkg/runner" "kcl-lang.io/kpm/pkg/utils" ) @@ -158,7 +159,26 @@ func TestDependencyGraph(t *testing.T) { } func TestCyclicDependency(t *testing.T) { - + testDir := getTestDir("test_cyclic_dependency") + assert.Equal(t, utils.DirExists(filepath.Join(testDir, "aaa")), true) + assert.Equal(t, utils.DirExists(filepath.Join(testDir, "aaa/kcl.mod")), true) + assert.Equal(t, utils.DirExists(filepath.Join(testDir, "bbb")), true) + assert.Equal(t, utils.DirExists(filepath.Join(testDir, "bbb/kcl.mod")), true) + + pkg_path := filepath.Join(testDir, "aaa") + + kpmcli, err := NewKpmClient() + assert.Equal(t, err, nil) + kclPkg, err := kpmcli.LoadPkgFromPath(pkg_path) + assert.Equal(t, err, nil) + + err = os.Chdir(pkg_path) + assert.Equal(t, err, nil) + + _, _, err = kpmcli.InitGraphAndDownloadDeps(kclPkg) + assert.Equal(t, err, reporter.NewErrorEvent( + reporter.CircularDependencyExist, nil, "adding dependencies results in a cycle", + )) } func TestInitEmptyPkg(t *testing.T) { diff --git a/pkg/client/test_data/test_cyclic_dependency/aaa/kcl.mod b/pkg/client/test_data/test_cyclic_dependency/aaa/kcl.mod new file mode 100644 index 00000000..79bceba5 --- /dev/null +++ b/pkg/client/test_data/test_cyclic_dependency/aaa/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "aaa" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +bbb = { path = "../bbb" } diff --git a/pkg/client/test_data/test_cyclic_dependency/aaa/kcl.mod.lock b/pkg/client/test_data/test_cyclic_dependency/aaa/kcl.mod.lock new file mode 100644 index 00000000..9c249080 --- /dev/null +++ b/pkg/client/test_data/test_cyclic_dependency/aaa/kcl.mod.lock @@ -0,0 +1,6 @@ +[dependencies] + [dependencies.bbb] + name = "bbb" + full_name = "bbb_" + sum = "d5r1MvBb8BvbURsKSdE6mW6oA3w0Df4BKds8IU83/us=" + path = "../bbb" diff --git a/pkg/client/test_data/test_cyclic_dependency/aaa/main.k b/pkg/client/test_data/test_cyclic_dependency/aaa/main.k new file mode 100644 index 00000000..fa7048e6 --- /dev/null +++ b/pkg/client/test_data/test_cyclic_dependency/aaa/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file diff --git a/pkg/client/test_data/test_cyclic_dependency/bbb/kcl.mod b/pkg/client/test_data/test_cyclic_dependency/bbb/kcl.mod new file mode 100644 index 00000000..a70b8351 --- /dev/null +++ b/pkg/client/test_data/test_cyclic_dependency/bbb/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "bbb" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +aaa = { path = "../aaa" } diff --git a/pkg/client/test_data/test_cyclic_dependency/bbb/kcl.mod.lock b/pkg/client/test_data/test_cyclic_dependency/bbb/kcl.mod.lock new file mode 100644 index 00000000..e3672021 --- /dev/null +++ b/pkg/client/test_data/test_cyclic_dependency/bbb/kcl.mod.lock @@ -0,0 +1,8 @@ +[dependencies] + [dependencies.aaa] + name = "aaa" + full_name = "aaa_0.0.1" + version = "0.0.1" + sum = "hgAM5wYFzXo83S+OiT0LaBDnHU7Q9vqq3BPXlTDr8TY=" + path = "../aaa" + diff --git a/pkg/client/test_data/test_cyclic_dependency/bbb/main.k b/pkg/client/test_data/test_cyclic_dependency/bbb/main.k new file mode 100644 index 00000000..fa7048e6 --- /dev/null +++ b/pkg/client/test_data/test_cyclic_dependency/bbb/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file