diff --git a/tests/pkg/assets/git-pkg/gold/install.gold b/tests/pkg/assets/git-pkg/gold/install.gold index eba602a56..a730fde6f 100644 --- a/tests/pkg/assets/git-pkg/gold/install.gold +++ b/tests/pkg/assets/git-pkg/gold/install.gold @@ -3,6 +3,7 @@ OK ================== OK [pkg, install, pkg1] +Package 'pkg1@1.0.0' installed with prefix 'pkg1'. ================== == package.lock prefixes: diff --git a/tests/pkg/assets/git-pkg2/gold/00-install.gold b/tests/pkg/assets/git-pkg2/gold/00-install.gold index eba602a56..a730fde6f 100644 --- a/tests/pkg/assets/git-pkg2/gold/00-install.gold +++ b/tests/pkg/assets/git-pkg2/gold/00-install.gold @@ -3,6 +3,7 @@ OK ================== OK [pkg, install, pkg1] +Package 'pkg1@1.0.0' installed with prefix 'pkg1'. ================== == package.lock prefixes: diff --git a/tests/pkg/assets/git-pkg2/gold/10-git package search.gold b/tests/pkg/assets/git-pkg2/gold/10-git package search.gold index 0ee58c743..458dc168f 100644 --- a/tests/pkg/assets/git-pkg2/gold/10-git package search.gold +++ b/tests/pkg/assets/git-pkg2/gold/10-git package search.gold @@ -25,9 +25,11 @@ OK ================== OK [pkg, install, foo] +Package 'foo@1.2.3' installed with prefix 'foo'. ================== OK [pkg, install, bar] +Package 'bar@2.0.1' installed with prefix 'bar'. ================== // Execution should succeed now ================== @@ -58,9 +60,11 @@ Exit Code: 1 ================== OK [pkg, install, --prefix=pre1, foo] +Package 'foo@1.2.3' installed with prefix 'foo'. ================== OK [pkg, install, --prefix=pre2, bar] +Package 'bar@2.0.1' installed with prefix 'bar'. ================== // Execution should succeed now ================== diff --git a/tests/pkg/assets/install-in-package/gold/00-test.gold b/tests/pkg/assets/install-in-package/gold/00-test.gold new file mode 100644 index 000000000..9ccc0b318 --- /dev/null +++ b/tests/pkg/assets/install-in-package/gold/00-test.gold @@ -0,0 +1,44 @@ +OK +[pkg, init] +================== +OK +[pkg, registry, add, --local, test-reg, registry] +================== +OK +[pkg, install, foo] +Package 'foo@1.2.3' installed with prefix 'foo'. +================== +OK +[pkg, install, bar] +Package 'bar@2.0.1' installed with prefix 'bar'. +================== +== package.lock +sdk: ^0.1.30 +prefixes: + bar: http_//localhost_<[*PORT*]>/pkg/bar-2 + foo: http_//localhost_<[*PORT*]>/pkg/foo-1 +packages: + http_//localhost_<[*PORT*]>/pkg/bar-2: + prefixes: + foo: http_//localhost_<[*PORT*]>/pkg/foo-1 + sub: http_//localhost_<[*PORT*]>/pkg/sub-3 + url: http://localhost:<[*PORT*]>/pkg/bar + version: 2.0.1 + hash: <[*HASH*]> + http_//localhost_<[*PORT*]>/pkg/foo-1: + url: http://localhost:<[*PORT*]>/pkg/foo + version: 1.2.3 + hash: <[*HASH*]> + http_//localhost_<[*PORT*]>/pkg/sub-3: + url: http://localhost:<[*PORT*]>/pkg/sub + version: 3.1.4 + hash: <[*HASH*]> +================== +== package.yaml +dependencies: + foo: + url: http://localhost:<[*PORT*]>/pkg/foo + version: ^1.2.3 + bar: + url: http://localhost:<[*PORT*]>/pkg/bar + version: ^2.0.1 diff --git a/tests/pkg/assets/install1/gold/install-existing-prefix.gold b/tests/pkg/assets/install1/gold/install-existing-prefix.gold index e0b17158f..2b76610d9 100644 --- a/tests/pkg/assets/install1/gold/install-existing-prefix.gold +++ b/tests/pkg/assets/install1/gold/install-existing-prefix.gold @@ -1,2 +1,3 @@ OK [pkg, install, --local, --prefix=pkg1, pkg2] +Package 'pkg2' installed with prefix 'pkg1'. diff --git a/tests/pkg/assets/install1/gold/install.gold b/tests/pkg/assets/install1/gold/install.gold index a82a8ac8b..11c615ed0 100644 --- a/tests/pkg/assets/install1/gold/install.gold +++ b/tests/pkg/assets/install1/gold/install.gold @@ -12,6 +12,7 @@ Exit Code: 1 ================== OK [pkg, install, --local, pkg] +Package 'pkg' installed with prefix 'pkg'. ================== exec main.toit hello from pkg @@ -21,6 +22,7 @@ Exit Code: 0 ================== OK [pkg, install, --local, --prefix=prepkg, pkg2] +Package 'pkg2' installed with prefix 'prepkg'. ================== exec main2.toit hello from pkg2 @@ -30,11 +32,13 @@ Exit Code: 0 ================== OK [pkg, install, --local, pkg] +Package 'pkg' installed with prefix 'pkg'. ================== // Installing a package where the directory name is not the package name. ================== OK [pkg, install, --local, pkg3] +Package 'pkg3' installed with prefix 'pkg3_modified'. ================== exec main3.toit hello from pkg3_modified diff --git a/tests/pkg/gold-tester.toit b/tests/pkg/gold-tester.toit index 846cda48a..b03de6b83 100644 --- a/tests/pkg/gold-tester.toit +++ b/tests/pkg/gold-tester.toit @@ -128,6 +128,9 @@ class GoldTester: else if command == "package.lock": lock-content := file.read-contents "$working-dir_/package.lock" outputs.add "== package.lock\n$lock-content.to-string" + else if command == "package.yaml": + yaml-content := file.read-contents "$working-dir_/package.yaml" + outputs.add "== package.yaml\n$yaml-content.to-string" else if command == "pkg": test-ui := TestUi --quiet=false cli := Cli "pkg" --ui=test-ui diff --git a/tests/pkg/install-in-package-gold-test.toit b/tests/pkg/install-in-package-gold-test.toit new file mode 100644 index 000000000..f488bf8e3 --- /dev/null +++ b/tests/pkg/install-in-package-gold-test.toit @@ -0,0 +1,18 @@ +// Copyright (C) 2025 Toit contributors. +// Use of this source code is governed by a Zero-Clause BSD license that can +// be found in the tests/LICENSE file. + +import .gold-tester + +main args: + with-gold-tester --with-git-pkg-registry args: test it + +test tester/GoldTester: + tester.gold "00-test" [ + ["pkg", "init"], // So we don't accidentally use a /tmp/package.yaml. + ["pkg", "registry", "add", "--local", "test-reg", "registry"], + ["pkg", "install", "foo"], + ["pkg", "install", "bar"], + ["package.lock"], + ["package.yaml"] + ] diff --git a/tools/pkg/commands/install.toit b/tools/pkg/commands/install.toit index ece732d1c..1029cd42d 100644 --- a/tools/pkg/commands/install.toit +++ b/tools/pkg/commands/install.toit @@ -71,9 +71,12 @@ class InstallCommand extends PkgProjectCommand: if not prefix: prefix = remote-package.name if project.specification.has-package prefix: - error "Project already has a package with name '$prefix'." + error "Project already has a package with prefix '$prefix'." project.install-remote prefix remote-package --registries=registries + id := "$remote-package.name@$remote-package.version" + name := remote-package.name + ui.emit --info "Package '$id' installed with prefix '$name'." execute-local: specification-name := "$package/$Specification.FILE-NAME" @@ -88,6 +91,7 @@ class InstallCommand extends PkgProjectCommand: if not prefix: prefix = specification.name project.install-local prefix package --registries=registries + ui.emit --info "Package '$package' installed with prefix '$prefix'." static CLI-COMMAND ::= cli.Command "install"