gnu: Add rust-ansi-colours-1.
[jackhill/guix/guix.git] / tests / guix-environment.sh
index b44aca0..2faf38d 100644 (file)
@@ -1,5 +1,5 @@
 # GNU Guix --- Functional package management for GNU
-# Copyright © 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
+# Copyright © 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
 #
 # This file is part of GNU Guix.
 #
@@ -49,6 +49,19 @@ test -x `sed -r 's/^export PATH="(.*)"/\1/' "$tmpdir/a"`/guile
 
 cmp "$tmpdir/a" "$tmpdir/b"
 
+# Check '--preserve'.
+GUIX_TEST_ABC=1
+GUIX_TEST_DEF=2
+GUIX_TEST_XYZ=3
+export GUIX_TEST_ABC GUIX_TEST_DEF GUIX_TEST_XYZ
+guix environment --bootstrap --ad-hoc guile-bootstrap --pure   \
+     --preserve='^GUIX_TEST_A' --preserve='^GUIX_TEST_D'       \
+     -- "$SHELL" -c set > "$tmpdir/a"
+grep '^PATH=' "$tmpdir/a"
+grep '^GUIX_TEST_ABC=' "$tmpdir/a"
+grep '^GUIX_TEST_DEF=' "$tmpdir/a"
+if grep '^GUIX_TEST_XYZ=' "$tmpdir/a"; then false; else true; fi
+
 # Make sure the exit value is preserved.
 if guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
         -- guile -c '(exit 42)'
@@ -71,6 +84,29 @@ echo "(use-modules (guix profiles) (gnu packages bootstrap))
 guix environment --bootstrap --manifest=$tmpdir/manifest.scm --pure \
      -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile"'
 
+# Make sure '--manifest' can be specified multiple times.
+cat > "$tmpdir/manifest2.scm" <<EOF
+(use-modules (guix) (guix profiles)
+             (guix build-system trivial)
+             (gnu packages bootstrap))
+
+(packages->manifest
+ (list (package
+         (inherit %bootstrap-guile)
+         (name "eliug")
+         (build-system trivial-build-system)
+         (arguments
+          (quasiquote
+           (#:guile ,%bootstrap-guile
+            #:builder
+            (begin
+              (mkdir %output)
+              (mkdir (string-append %output "/eliug")))))))))
+EOF
+guix environment --bootstrap -m "$tmpdir/manifest.scm" \
+     -m "$tmpdir/manifest2.scm" --pure \
+     -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile" && test -d "$GUIX_ENVIRONMENT/eliug"'
+
 # Make sure '-r' works as expected.
 rm -f "$gcroot"
 expected="`guix environment --bootstrap --ad-hoc guile-bootstrap \
@@ -104,25 +140,46 @@ case "`uname -m`" in
        ;;
 esac
 
-
-# Same as above, but with deprecated -E flag.
-if guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
-        -E "guile -c '(exit 42)'"
-then
-    false
-else
-    test $? = 42
-fi
-
 # Make sure we can build the environment of 'guix'.  There may be collisions
 # in its profile (e.g., for 'gzip'), but we have to accept them.
 guix environment guix --bootstrap -n
 
+# Try program transformation options.
+mkdir "$tmpdir/emacs-36.8"
+drv="`guix environment --ad-hoc emacs -n 2>&1 | grep 'emacs.*\.drv'`"
+transformed_drv="`guix environment --ad-hoc emacs --with-source="$tmpdir/emacs-36.8" -n 2>&1 | grep 'emacs.*\.drv'`"
+test -n "$drv"
+test "$drv" != "$transformed_drv"
+case "$transformed_drv" in
+    *-emacs-36.8.drv) true;;
+    *)                false;;
+esac
+rmdir "$tmpdir/emacs-36.8"
+
+# Transformation options without '--ad-hoc'.
+drv="`guix environment -n emacs-geiser 2>&1 | grep '\.drv$'`"
+transformed_drv="`guix environment -n emacs-geiser \
+  --with-input=emacs-minimal=vim 2>&1 | grep '\.drv$'`"
+test "$drv" != "$transformed_drv"
+case "$drv" in
+    *-emacs-minimal*.drv*) true;;
+    *)                     false;;
+esac
+case "$transformed_drv" in
+    *-emacs-minimal*.drv*) false;;
+    *)                     true;;
+esac
+case "$transformed_drv" in
+    *-vim*.drv*) true;;
+    *)           false;;
+esac
+
+
 if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
 then
     # Compute the build environment for the initial GNU Make.
     guix environment --bootstrap --no-substitutes --search-paths --pure \
-         -e '(@@ (gnu packages commencement) gnu-make-boot0)' > "$tmpdir/a"
+         -e '(@ (guix tests) gnu-make-for-tests)' > "$tmpdir/a"
 
     # Make sure bootstrap binaries are in the profile.
     profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
@@ -143,30 +200,15 @@ then
     # Make sure that the shell spawned with '--exec' sees the same environment
     # as returned by '--search-paths'.
     guix environment --bootstrap --no-substitutes --pure \
-         -e '(@@ (gnu packages commencement) gnu-make-boot0)' \
+         -e '(@ (guix tests) gnu-make-for-tests)' \
          -- /bin/sh -c 'echo $PATH $CPATH $LIBRARY_PATH' > "$tmpdir/b"
     ( . "$tmpdir/a" ; echo $PATH $CPATH $LIBRARY_PATH ) > "$tmpdir/c"
     cmp "$tmpdir/b" "$tmpdir/c"
 
     rm "$tmpdir"/*
 
-    # Compute the build environment for the initial GNU Findutils.
-    guix environment --bootstrap --no-substitutes --search-paths --pure \
-         -e '(@@ (gnu packages commencement) findutils-boot0)' > "$tmpdir/a"
-    profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
-
-    # Make sure the bootstrap binaries are all listed where they belong.
-    grep -E "^export PATH=\"$profile/bin\""         "$tmpdir/a"
-    grep -E "^export CPATH=\"$profile/include\""    "$tmpdir/a"
-    grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
-    for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0 \
-                                   make-boot0
-    do
-       guix gc --references "$profile" | grep "$dep"
-    done
-
     # The following test assumes 'make-boot0' has a "debug" output.
-    make_boot0_debug="`guix build -e '(@@ (gnu packages commencement) gnu-make-boot0)' | grep -e -debug`"
+    make_boot0_debug="`guix build -e '(@ (guix tests) gnu-make-for-tests)' | grep -e -debug`"
     test "x$make_boot0_debug" != "x"
 
     # Make sure the "debug" output is not listed.
@@ -176,7 +218,7 @@ then
     # Compute the build environment for the initial GNU Make, but add in the
     # bootstrap Guile as an ad-hoc addition.
     guix environment --bootstrap --no-substitutes --search-paths --pure        \
-         -e '(@@ (gnu packages commencement) gnu-make-boot0)'          \
+         -e '(@ (guix tests) gnu-make-for-tests)'              \
          --ad-hoc guile-bootstrap > "$tmpdir/a"
     profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
 
@@ -193,14 +235,14 @@ then
     # Make sure a package list with plain package objects and package+output
     # tuples can be used with -e.
     expr_list_test_code="
-(list (@@ (gnu packages commencement) gnu-make-boot0)
+(list (@ (guix tests) gnu-make-for-tests)
       (list (@ (gnu packages bootstrap) %bootstrap-guile) \"out\"))"
 
     guix environment --bootstrap --ad-hoc --no-substitutes --search-paths \
          --pure -e "$expr_list_test_code" > "$tmpdir/a"
     profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
 
-    for dep in make-boot0 guile-bootstrap
+    for dep in make-test-boot0 guile-bootstrap
     do
        guix gc --references "$profile" | grep "$dep"
     done