aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/guix-package-net.sh170
-rw-r--r--tests/guix-package.sh143
-rw-r--r--tests/publish.scm114
-rw-r--r--tests/store.scm10
-rw-r--r--tests/syscalls.scm6
5 files changed, 313 insertions, 130 deletions
diff --git a/tests/guix-package-net.sh b/tests/guix-package-net.sh
new file mode 100644
index 0000000000..cedfa3217b
--- /dev/null
+++ b/tests/guix-package-net.sh
@@ -0,0 +1,170 @@
+# GNU Guix --- Functional package management for GNU
+# Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
+# Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
+#
+# This file is part of GNU Guix.
+#
+# GNU Guix is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or (at
+# your option) any later version.
+#
+# GNU Guix is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+#
+# Test the `guix package' command-line utility. This test requires network
+# access and is skipped when that is lacking.
+#
+
+guix package --version
+
+readlink_base ()
+{
+ basename `readlink "$1"`
+}
+
+# Return true if a typical shebang in the store would exceed Linux's default
+# static limit.
+shebang_too_long ()
+{
+ test `echo $NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash | wc -c` \
+ -ge 128
+}
+
+profile="t-profile-$$"
+rm -f "$profile"
+
+trap 'rm -f "$profile" "$profile-"[0-9]* ; rm -rf t-home-'"$$" EXIT
+
+
+guix package --bootstrap -p "$profile" -i guile-bootstrap
+test -L "$profile" && test -L "$profile-1-link"
+! test -f "$profile-2-link"
+test -f "$profile/bin/guile"
+
+boot_make="(@@ (gnu packages commencement) gnu-make-boot0)"
+boot_make_drv="`guix build -e "$boot_make" | grep -v -e -debug`"
+guix package --bootstrap -p "$profile" -i "$boot_make_drv"
+test -L "$profile-2-link"
+test -f "$profile/bin/make" && test -f "$profile/bin/guile"
+
+# Check whether `--list-installed' works.
+# XXX: Change the tests when `--install' properly extracts the package
+# name and version string.
+installed="`guix package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`"
+case "x$installed" in
+ "guile-bootstrap make-boot0")
+ true;;
+ "make-boot0 guile-bootstrap")
+ true;;
+ "*")
+ false;;
+esac
+
+test "`guix package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap"
+
+# List generations.
+test "`guix package -p "$profile" -l | cut -f1 | grep guile | head -n1`" \
+ = " guile-bootstrap"
+
+# Exit with 1 when a generation does not exist.
+if guix package -p "$profile" --list-generations=42;
+then false; else true; fi
+if guix package -p "$profile" --switch-generation=99;
+then false; else true; fi
+
+# Remove a package.
+guix package --bootstrap -p "$profile" -r "guile-bootstrap"
+test -L "$profile-3-link"
+test -f "$profile/bin/make" && ! test -f "$profile/bin/guile"
+
+# Roll back.
+guix package --roll-back -p "$profile"
+test "`readlink_base "$profile"`" = "$profile-2-link"
+test -x "$profile/bin/guile" && test -x "$profile/bin/make"
+guix package --roll-back -p "$profile"
+test "`readlink_base "$profile"`" = "$profile-1-link"
+test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
+
+# Switch to the rolled generation and switch back.
+guix package -p "$profile" --switch-generation=2
+test "`readlink_base "$profile"`" = "$profile-2-link"
+guix package -p "$profile" --switch-generation=-1
+test "`readlink_base "$profile"`" = "$profile-1-link"
+
+# Move to the empty profile.
+for i in `seq 1 3`
+do
+ guix package --bootstrap --roll-back -p "$profile"
+ ! test -f "$profile/bin"
+ ! test -f "$profile/lib"
+ test "`readlink_base "$profile"`" = "$profile-0-link"
+done
+
+# Test that '--list-generations' does not output the zeroth generation.
+test -z "`guix package -p "$profile" -l 0`"
+
+# Reinstall after roll-back to the empty profile.
+guix package --bootstrap -p "$profile" -e "$boot_make"
+test "`readlink_base "$profile"`" = "$profile-1-link"
+test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
+
+# Check that the first generation is the current one.
+test "`guix package -p "$profile" -l 1 | cut -f3 | head -n1`" = "(current)"
+
+# Roll-back to generation 0, and install---all at once.
+guix package --bootstrap -p "$profile" --roll-back -i guile-bootstrap
+test "`readlink_base "$profile"`" = "$profile-1-link"
+test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
+
+# Install Make.
+guix package --bootstrap -p "$profile" -e "$boot_make"
+test "`readlink_base "$profile"`" = "$profile-2-link"
+test -x "$profile/bin/guile" && test -x "$profile/bin/make"
+grep "`guix build -e "$boot_make"`" "$profile/manifest"
+
+# Make a "hole" in the list of generations, and make sure we can
+# roll back and switch "over" it.
+rm "$profile-1-link"
+guix package --bootstrap -p "$profile" --roll-back
+test "`readlink_base "$profile"`" = "$profile-0-link"
+guix package -p "$profile" --switch-generation=+1
+test "`readlink_base "$profile"`" = "$profile-2-link"
+
+# Make sure LIBRARY_PATH gets listed by `--search-paths'.
+guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap
+guix package --search-paths -p "$profile" | grep LIBRARY_PATH
+
+# Roll back so we can delete #3 below.
+guix package -p "$profile" --switch-generation=2
+
+# Delete the third generation and check that it was actually deleted.
+guix package -p "$profile" --delete-generations=3
+test -z "`guix package -p "$profile" -l 3`"
+
+
+#
+# Try with the default profile.
+#
+
+XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
+export XDG_CACHE_HOME
+HOME="$PWD/t-home-$$"
+export HOME
+
+mkdir -p "$HOME"
+
+# Get the canonical directory name so that 'guix package' recognizes it.
+HOME="`cd $HOME; pwd -P`"
+
+guix package --bootstrap -e "$boot_make"
+test -f "$HOME/.guix-profile/bin/make"
+
+guix package --bootstrap --roll-back
+! test -f "$HOME/.guix-profile/bin/make"
diff --git a/tests/guix-package.sh b/tests/guix-package.sh
index 94cf927420..6cfd50b5e5 100644
--- a/tests/guix-package.sh
+++ b/tests/guix-package.sh
@@ -28,14 +28,6 @@ readlink_base ()
basename `readlink "$1"`
}
-# Return true if a typical shebang in the store would not exceed Linux's
-# default static limit.
-shebang_not_too_long ()
-{
- test `echo $NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash | wc -c` \
- -lt 128
-}
-
module_dir="t-guix-package-$$"
profile="t-profile-$$"
rm -f "$profile"
@@ -63,115 +55,12 @@ test -f "$profile/bin/guile"
guix package --search-paths -p "$profile"
test "`guix package --search-paths -p "$profile" | wc -l`" = 0
-# Check whether we have network access and an acceptable shebang length.
-if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null \
- && shebang_not_too_long
-then
- boot_make="(@@ (gnu packages commencement) gnu-make-boot0)"
- boot_make_drv="`guix build -e "$boot_make" | grep -v -e -debug`"
- guix package --bootstrap -p "$profile" -i "$boot_make_drv"
- test -L "$profile-2-link"
- test -f "$profile/bin/make" && test -f "$profile/bin/guile"
-
-
- # Check whether `--list-installed' works.
- # XXX: Change the tests when `--install' properly extracts the package
- # name and version string.
- installed="`guix package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`"
- case "x$installed" in
- "guile-bootstrap make-boot0")
- true;;
- "make-boot0 guile-bootstrap")
- true;;
- "*")
- false;;
- esac
-
- test "`guix package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap"
-
- # List generations.
- test "`guix package -p "$profile" -l | cut -f1 | grep guile | head -n1`" \
- = " guile-bootstrap"
-
- # Exit with 1 when a generation does not exist.
- if guix package -p "$profile" --list-generations=42;
- then false; else true; fi
- if guix package -p "$profile" --switch-generation=99;
- then false; else true; fi
-
- # Remove a package.
- guix package --bootstrap -p "$profile" -r "guile-bootstrap"
- test -L "$profile-3-link"
- test -f "$profile/bin/make" && ! test -f "$profile/bin/guile"
-
- # Roll back.
- guix package --roll-back -p "$profile"
- test "`readlink_base "$profile"`" = "$profile-2-link"
- test -x "$profile/bin/guile" && test -x "$profile/bin/make"
- guix package --roll-back -p "$profile"
- test "`readlink_base "$profile"`" = "$profile-1-link"
- test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
-
- # Switch to the rolled generation and switch back.
- guix package -p "$profile" --switch-generation=2
- test "`readlink_base "$profile"`" = "$profile-2-link"
- guix package -p "$profile" --switch-generation=-1
- test "`readlink_base "$profile"`" = "$profile-1-link"
-
- # Move to the empty profile.
- for i in `seq 1 3`
- do
- guix package --bootstrap --roll-back -p "$profile"
- ! test -f "$profile/bin"
- ! test -f "$profile/lib"
- test "`readlink_base "$profile"`" = "$profile-0-link"
- done
-
- # Test that '--list-generations' does not output the zeroth generation.
- test -z "`guix package -p "$profile" -l 0`"
-
- # Reinstall after roll-back to the empty profile.
- guix package --bootstrap -p "$profile" -e "$boot_make"
- test "`readlink_base "$profile"`" = "$profile-1-link"
- test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
-
- # Check that the first generation is the current one.
- test "`guix package -p "$profile" -l 1 | cut -f3 | head -n1`" = "(current)"
-
- # Roll-back to generation 0, and install---all at once.
- guix package --bootstrap -p "$profile" --roll-back -i guile-bootstrap
- test "`readlink_base "$profile"`" = "$profile-1-link"
- test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
-
- # Install Make.
- guix package --bootstrap -p "$profile" -e "$boot_make"
- test "`readlink_base "$profile"`" = "$profile-2-link"
- test -x "$profile/bin/guile" && test -x "$profile/bin/make"
- grep "`guix build -e "$boot_make"`" "$profile/manifest"
-
- # Make a "hole" in the list of generations, and make sure we can
- # roll back and switch "over" it.
- rm "$profile-1-link"
- guix package --bootstrap -p "$profile" --roll-back
- test "`readlink_base "$profile"`" = "$profile-0-link"
- guix package -p "$profile" --switch-generation=+1
- test "`readlink_base "$profile"`" = "$profile-2-link"
-
- # Make sure LIBRARY_PATH gets listed by `--search-paths'.
- guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap
- guix package --search-paths -p "$profile" | grep LIBRARY_PATH
-
- # Delete the third generation and check that it was actually deleted.
- guix package -p "$profile" --delete-generations=3
- test -z "`guix package -p "$profile" -l 3`"
-
- # Exit with 1 when a generation does not exist.
- if guix package -p "$profile" --delete-generations=42;
- then false; else true; fi
-
- # Exit with 0 when trying to delete the zeroth generation.
- guix package -p "$profile" --delete-generations=0
-fi
+# Exit with 1 when a generation does not exist.
+if guix package -p "$profile" --delete-generations=42;
+then false; else true; fi
+
+# Exit with 0 when trying to delete the zeroth generation.
+guix package -p "$profile" --delete-generations=0
# Make sure multiple arguments to -i works.
guix package --bootstrap -i guile gcc -p "$profile" -n
@@ -212,6 +101,14 @@ if guix package -p "$profile" --delete-generations=12m;
then false; else true; fi
test "`readlink_base "$profile"`" = "$generation"
+# The following command should not delete the current generation, even though
+# it matches the given pattern (see <http://bugs.gnu.org/19978>.) And since
+# there's nothing else to delete, it should just fail.
+guix package --list-generations -p "$profile"
+if guix package --bootstrap -p "$profile" --delete-generations=1..
+then false; else true; fi
+test "`readlink_base "$profile"`" = "$generation"
+
# Make sure $profile is a GC root at this point.
real_profile="`readlink -f "$profile"`"
if guix gc -d "$real_profile"
@@ -242,18 +139,6 @@ guix package --bootstrap -i guile-bootstrap
test -L "$HOME/.guix-profile"
test -f "$HOME/.guix-profile/bin/guile"
-if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
-then
- guix package --bootstrap -e "$boot_make"
- test -f "$HOME/.guix-profile/bin/make"
- first_environment="`cd $HOME/.guix-profile ; pwd`"
-
- guix package --bootstrap --roll-back
- test -f "$HOME/.guix-profile/bin/guile"
- ! test -f "$HOME/.guix-profile/bin/make"
- test "`cd $HOME/.guix-profile ; pwd`" = "$first_environment"
-fi
-
# Move to the empty profile.
default_profile="`readlink "$HOME/.guix-profile"`"
for i in `seq 1 3`
diff --git a/tests/publish.scm b/tests/publish.scm
new file mode 100644
index 0000000000..60f57a8ddb
--- /dev/null
+++ b/tests/publish.scm
@@ -0,0 +1,114 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2015 David Thompson <davet@gnu.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (test-publish)
+ #:use-module (guix scripts publish)
+ #:use-module (guix tests)
+ #:use-module (guix config)
+ #:use-module (guix utils)
+ #:use-module (guix hash)
+ #:use-module (guix store)
+ #:use-module (guix base32)
+ #:use-module (guix base64)
+ #:use-module ((guix serialization) #:select (restore-file))
+ #:use-module (guix pk-crypto)
+ #:use-module (web client)
+ #:use-module (web response)
+ #:use-module (rnrs bytevectors)
+ #:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-26)
+ #:use-module (srfi srfi-64)
+ #:use-module (ice-9 match)
+ #:use-module (ice-9 rdelim))
+
+(define %store
+ (open-connection-for-tests))
+
+(define %reference (add-text-to-store %store "ref" "foo"))
+
+(define %item (add-text-to-store %store "item" "bar" (list %reference)))
+
+(define (http-get-body uri)
+ (call-with-values (lambda () (http-get uri))
+ (lambda (response body) body)))
+
+(define (publish-uri route)
+ (string-append "http://localhost:6789" route))
+
+;; Run a local publishing server in a separate thread.
+(call-with-new-thread
+ (lambda ()
+ (guix-publish "--port=6789"))) ; attempt to avoid port collision
+
+;; Wait until the server is accepting connections.
+(let ((conn (socket PF_INET SOCK_STREAM 0)))
+ (let loop ()
+ (unless (false-if-exception
+ (connect conn AF_INET (inet-pton AF_INET "127.0.0.1") 6789))
+ (loop))))
+
+(test-begin "publish")
+
+(test-equal "/nix-cache-info"
+ (format #f "StoreDir: ~a\nWantMassQuery: 0\nPriority: 100\n"
+ %store-directory)
+ (http-get-body (publish-uri "/nix-cache-info")))
+
+(test-equal "/*.narinfo"
+ (let* ((info (query-path-info %store %item))
+ (unsigned-info
+ (format #f
+ "StorePath: ~a
+URL: nar/~a
+Compression: none
+NarHash: sha256:~a
+NarSize: ~d
+References: ~a~%"
+ %item
+ (basename %item)
+ (bytevector->base32-string
+ (path-info-hash info))
+ (path-info-nar-size info)
+ (basename (first (path-info-references info)))))
+ (signature (base64-encode
+ (string->utf8
+ (canonical-sexp->string
+ ((@@ (guix scripts publish) signed-string)
+ unsigned-info))))))
+ (format #f "~aSignature: 1;~a;~a~%"
+ unsigned-info (gethostname) signature))
+ (utf8->string
+ (http-get-body
+ (publish-uri
+ (string-append "/" (store-path-hash-part %item) ".narinfo")))))
+
+(test-equal "/nar/*"
+ "bar"
+ (call-with-temporary-output-file
+ (lambda (temp port)
+ (let ((nar (utf8->string
+ (http-get-body
+ (publish-uri
+ (string-append "/nar/" (basename %item)))))))
+ (call-with-input-string nar (cut restore-file <> temp)))
+ (call-with-input-file temp read-string))))
+
+(test-end "publish")
+
+
+(exit (= (test-runner-fail-count (test-runner-current)) 0))
diff --git a/tests/store.scm b/tests/store.scm
index f778c2086d..eeceed45c1 100644
--- a/tests/store.scm
+++ b/tests/store.scm
@@ -606,6 +606,16 @@
(file (add %store "foo" "Lowered.")))
(call-with-input-file file get-string-all)))
+(test-assert "query-path-info"
+ (let* ((ref (add-text-to-store %store "ref" "foo"))
+ (item (add-text-to-store %store "item" "bar" (list ref)))
+ (info (query-path-info %store item)))
+ (and (equal? (path-info-references info) (list ref))
+ (equal? (path-info-hash info)
+ (sha256
+ (string->utf8
+ (call-with-output-string (cut write-file item <>))))))))
+
(test-end "store")
diff --git a/tests/syscalls.scm b/tests/syscalls.scm
index f26331e164..706f3dff44 100644
--- a/tests/syscalls.scm
+++ b/tests/syscalls.scm
@@ -19,6 +19,7 @@
(define-module (test-syscalls)
#:use-module (guix build syscalls)
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-26)
#:use-module (srfi srfi-64)
#:use-module (ice-9 match))
@@ -45,7 +46,10 @@
(memv (system-error-errno args) (list EPERM ENOENT)))))
(test-assert "mount-points"
- (member "/" (mount-points)))
+ ;; Reportedly "/" is not always listed as a mount point, so check a few
+ ;; others (see <http://bugs.gnu.org/20261>.)
+ (any (cute member <> (mount-points))
+ '("/" "/proc" "/sys" "/dev")))
(test-assert "swapon, ENOENT/EPERM"
(catch 'system-error