about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-02-08T14·32+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-02-08T14·32+0000
commite771e59178f42fd1c6005c8a35f2ecfebf0e4ce4 (patch)
tree228be7a69d5f903cbd48e60b864d76fe9caef31b /tests
parent39f50db731bb1924d3c18b153dfe4258208b8812 (diff)
* Tests for nix-env, finally!
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/init.sh2
-rw-r--r--tests/user-envs.builder.sh8
-rw-r--r--tests/user-envs.nix.in19
-rw-r--r--tests/user-envs.sh77
5 files changed, 108 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f024ca8b9694..6620ccf36ccb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -36,10 +36,11 @@ nix-push.sh: dependencies.nix
 nix-pull.sh: dependencies.nix
 gc.sh: dependencies.nix
 gc-concurrent.sh: gc-concurrent.nix gc-concurrent2.nix
+user-envs.sh: user-envs.nix
 
 TESTS = init.sh hash.sh lang.sh simple.sh dependencies.sh locking.sh parallel.sh \
   build-hook.sh substitutes.sh substitutes2.sh fallback.sh nix-push.sh gc.sh \
-  gc-concurrent.sh verify.sh nix-pull.sh referrers.sh
+  gc-concurrent.sh verify.sh nix-pull.sh referrers.sh user-envs.sh
 
 XFAIL_TESTS =
 
diff --git a/tests/init.sh b/tests/init.sh
index c3a7aac29f16..316b2ec3d623 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -28,6 +28,8 @@ ln -s $TOP/scripts/readmanifest.pm $NIX_BIN_DIR/nix/
 mkdir -p "$NIX_STATE_DIR"/manifests
 mkdir -p "$NIX_STATE_DIR"/gcroots
 mkdir -p "$NIX_STATE_DIR"/temproots
+mkdir -p "$NIX_STATE_DIR"/profiles
+ln -s "$NIX_STATE_DIR"/profiles "$NIX_STATE_DIR"/gcroots/
 
 cat > "$NIX_CONF_DIR"/nix.conf <<EOF
 gc-keep-outputs = false
diff --git a/tests/user-envs.builder.sh b/tests/user-envs.builder.sh
new file mode 100644
index 000000000000..c84c045e4308
--- /dev/null
+++ b/tests/user-envs.builder.sh
@@ -0,0 +1,8 @@
+export PATH=/bin:/usr/bin:$PATH
+
+mkdir $out
+mkdir $out/bin
+echo "#! $shell" > $out/bin/$progName
+echo "echo $name" >> $out/bin/$progName
+chmod +x $out/bin/$progName
+
diff --git a/tests/user-envs.nix.in b/tests/user-envs.nix.in
new file mode 100644
index 000000000000..5700a33227b0
--- /dev/null
+++ b/tests/user-envs.nix.in
@@ -0,0 +1,19 @@
+let {
+
+  makeDrv = name: progName: derivation {
+    inherit name progName;
+    system = "@system@";
+    builder = "@shell@";
+    shell = "@shell@";
+    args = ["-e" "-x" ./user-envs.builder.sh];
+  };
+
+  body = [
+    (makeDrv "foo-1.0" "foo")
+    (makeDrv "foo-2.0pre1" "foo")
+    (makeDrv "bar-0.1" "bar")
+    (makeDrv "foo-2.0" "foo")
+    (makeDrv "bar-0.1.1" "bar")
+  ];
+  
+}
diff --git a/tests/user-envs.sh b/tests/user-envs.sh
new file mode 100644
index 000000000000..01d2d90d6785
--- /dev/null
+++ b/tests/user-envs.sh
@@ -0,0 +1,77 @@
+nixenv=$TOP/src/nix-env/nix-env
+profiles="$NIX_STATE_DIR"/profiles
+
+# Query installed: should be empty.
+test "$($nixenv -p $profiles/test -q | wc -l)" -eq 0
+
+# Query available: should contain several.
+test "$($nixenv -p $profiles/test -f ./user-envs.nix -qa | wc -l)" -eq 5
+
+# Install "foo-1.0".
+$nixenv -p $profiles/test -f ./user-envs.nix -i foo-1.0
+
+# Query installed: should contain foo-1.0 now (which should be
+# executable).
+test "$($nixenv -p $profiles/test -q | wc -l)" -eq 1
+$nixenv -p $profiles/test -q | grep -q foo-1.0
+test "$($profiles/test/bin/foo)" = "foo-1.0"
+
+# Store the path of foo-1.0.
+outPath10=$($nixenv -p $profiles/test -q --out-path --no-name | grep foo-1.0)
+echo "foo-1.0 = $outPath10"
+test -n "$outPath10"
+
+# Install "foo-2.0pre1": should remove foo-1.0.
+$nixenv -p $profiles/test -f ./user-envs.nix -i foo-2.0pre1
+
+# Query installed: should contain foo-2.0pre1 now.
+test "$($nixenv -p $profiles/test -q | wc -l)" -eq 1
+$nixenv -p $profiles/test -q | grep -q foo-2.0pre1
+test "$($profiles/test/bin/foo)" = "foo-2.0pre1"
+
+# Upgrade "foo": should install foo-2.0.
+$nixenv -p $profiles/test -f ./user-envs.nix -u foo
+
+# Query installed: should contain foo-2.0 now.
+test "$($nixenv -p $profiles/test -q | wc -l)" -eq 1
+$nixenv -p $profiles/test -q | grep -q foo-2.0
+test "$($profiles/test/bin/foo)" = "foo-2.0"
+
+# Store the path of foo-2.0.
+outPath20=$($nixenv -p $profiles/test -q --out-path --no-name | grep foo-2.0)
+test -n "$outPath20"
+
+# Install bar-0.1, uninstall foo.
+$nixenv -p $profiles/test -f ./user-envs.nix -i bar-0.1
+$nixenv -p $profiles/test -f ./user-envs.nix -e foo
+
+# Query installed: should only contain bar-0.1 now.
+if $nixenv -p $profiles/test -q | grep -q foo; then false; fi
+$nixenv -p $profiles/test -q | grep -q bar
+
+# Rollback: should bring "foo" back.
+$nixenv -p $profiles/test --rollback
+$nixenv -p $profiles/test -q | grep -q foo-2.0
+$nixenv -p $profiles/test -q | grep -q bar
+
+# Rollback again: should remove "bar".
+$nixenv -p $profiles/test --rollback
+$nixenv -p $profiles/test -q | grep -q foo-2.0
+if $nixenv -p $profiles/test -q | grep -q bar; then false; fi
+
+# Count generations.
+test "$($nixenv -p $profiles/test --list-generations | wc -l)" -eq 5
+
+# Install foo-1.0, now using its store path.
+echo $outPath10
+$nixenv -p $profiles/test -i "$outPath10"
+$nixenv -p $profiles/test -q | grep -q foo-1.0
+
+# Delete all old generations.
+$nixenv -p $profiles/test --delete-generations old
+
+# Run the garbage collector.  This should get rid of foo-2.0 but not
+# foo-1.0.
+$NIX_BIN_DIR/nix-collect-garbage
+test -e "$outPath10"
+if test -e "$outPath20"; then false; fi