From c10865a46e6e3083ceb2c6a450568fa2df91ec99 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 2 Mar 2022 11:14:31 +0100 Subject: [PATCH 1/3] tests: Rename nix-profile.sh -> bash-profile.sh --- tests/{nix-profile.sh => bash-profile.sh} | 0 tests/local.mk | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/{nix-profile.sh => bash-profile.sh} (100%) diff --git a/tests/nix-profile.sh b/tests/bash-profile.sh similarity index 100% rename from tests/nix-profile.sh rename to tests/bash-profile.sh diff --git a/tests/local.mk b/tests/local.mk index 53a9179a3..aba5aa651 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -89,7 +89,7 @@ nix_tests = \ build.sh \ ca/nix-run.sh \ db-migration.sh \ - nix-profile.sh \ + bash-profile.sh \ pass-as-file.sh \ describe-stores.sh \ store-ping.sh From b39ef074140485c528cab29064318c8fe1254f6b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 2 Mar 2022 11:46:15 +0100 Subject: [PATCH 2/3] Style --- src/nix/profile.cc | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 0e8dc4380..82507db2c 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -373,15 +373,15 @@ struct CmdProfileRemove : virtual EvalCommand, MixDefaultProfile, MixProfileElem if (removedCount == 0) { for (auto matcher: matchers) { - if (const size_t* index = std::get_if(&matcher)){ - warn("'%d' is not a valid index in profile", *index); - } else if (const Path* path = std::get_if(&matcher)){ - warn("'%s' does not match any paths in profile", *path); - } else if (const RegexPattern* regex = std::get_if(&matcher)){ - warn("'%s' does not match any packages in profile", regex->pattern); + if (const size_t * index = std::get_if(&matcher)){ + warn("'%d' is not a valid index", *index); + } else if (const Path * path = std::get_if(&matcher)){ + warn("'%s' does not match any paths", *path); + } else if (const RegexPattern * regex = std::get_if(&matcher)){ + warn("'%s' does not match any packages", regex->pattern); } } - warn ("Try `nix profile list` to see the current profile."); + warn ("Use 'nix profile list' to see the current profile."); } updateProfile(newManifest.build(store)); } @@ -454,12 +454,12 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf if (upgradedCount == 0) { for (auto & matcher : matchers) { - if (const size_t* index = std::get_if(&matcher)){ - warn("'%d' is not a valid index in profile", *index); - } else if (const Path* path = std::get_if(&matcher)){ - warn("'%s' does not match any paths in profile", *path); - } else if (const RegexPattern* regex = std::get_if(&matcher)){ - warn("'%s' does not match any packages in profile", regex->pattern); + if (const size_t * index = std::get_if(&matcher)){ + warn("'%d' is not a valid index", *index); + } else if (const Path * path = std::get_if(&matcher)){ + warn("'%s' does not match any paths", *path); + } else if (const RegexPattern * regex = std::get_if(&matcher)){ + warn("'%s' does not match any packages", regex->pattern); } } warn ("Use 'nix profile list' to see the current profile."); From 5850fd17b4aff50ac9f6b5f8570acc5cf4f43226 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 2 Mar 2022 11:46:24 +0100 Subject: [PATCH 3/3] Add basic tests for 'nix profile' Fixes #6193. --- tests/local.mk | 3 +- tests/nix-profile.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++ tests/user-envs.sh | 1 - 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 tests/nix-profile.sh diff --git a/tests/local.mk b/tests/local.mk index aba5aa651..c3a6aa1fc 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -92,7 +92,8 @@ nix_tests = \ bash-profile.sh \ pass-as-file.sh \ describe-stores.sh \ - store-ping.sh + store-ping.sh \ + nix-profile.sh ifeq ($(HAVE_LIBCPUID), 1) nix_tests += compute-levels.sh diff --git a/tests/nix-profile.sh b/tests/nix-profile.sh new file mode 100644 index 000000000..f134d70a4 --- /dev/null +++ b/tests/nix-profile.sh @@ -0,0 +1,68 @@ +source common.sh + +clearStore +clearProfiles + +# Make a flake. +flake1Dir=$TEST_ROOT/flake1 +mkdir -p $flake1Dir + +cat > $flake1Dir/flake.nix < \$out/bin/hello < $flake1Dir/who +printf 1.0 > $flake1Dir/version + +cp ./config.nix $flake1Dir/ + +# Test upgrading from nix-env. +nix-env -f ./user-envs.nix -i foo-1.0 +nix profile list | grep '0 - - .*-foo-1.0' +nix profile install $flake1Dir -L +[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]] +nix profile history +nix profile history | grep "packages.$system.default: ∅ -> 1.0" +nix profile diff-closures | grep 'env-manifest.nix: ε → ∅' + +# Test upgrading a package. +printf NixOS > $flake1Dir/who +printf 2.0 > $flake1Dir/version +nix profile upgrade 1 +[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello NixOS" ]] +nix profile history | grep "packages.$system.default: 1.0 -> 2.0" + +# Test 'history', 'diff-closures'. +nix profile diff-closures + +# Test rollback. +nix profile rollback +[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]] + +# Test uninstall. +[ -e $TEST_HOME/.nix-profile/bin/foo ] +nix profile remove 0 +(! [ -e $TEST_HOME/.nix-profile/bin/foo ]) +nix profile history | grep 'foo: 1.0 -> ∅' +nix profile diff-closures | grep 'Version 3 -> 4' + +# Test wipe-history. +nix profile wipe-history +[[ $(nix profile history | grep Version | wc -l) -eq 1 ]] diff --git a/tests/user-envs.sh b/tests/user-envs.sh index aebf6a2a2..430688de1 100644 --- a/tests/user-envs.sh +++ b/tests/user-envs.sh @@ -9,7 +9,6 @@ clearProfiles # Query installed: should be empty. test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 0 -mkdir -p $TEST_HOME nix-env --switch-profile $profiles/test # Query available: should contain several.