guix-repl.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
  3. # Copyright © 2020 Konrad Hinsen <konrad.hinsen@fastmail.net>
  4. #
  5. # This file is part of GNU Guix.
  6. #
  7. # GNU Guix is free software; you can redistribute it and/or modify it
  8. # under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 3 of the License, or (at
  10. # your option) any later version.
  11. #
  12. # GNU Guix is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. # Test the `guix repl' command-line utility.
  21. #
  22. guix repl --version
  23. test_directory="`mktemp -d`"
  24. export test_directory
  25. trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
  26. tmpfile="$test_directory/foo.scm"
  27. rm -f "$tmpfile"
  28. trap 'rm -f "$tmpfile"' EXIT
  29. module_dir="t-guix-repl-$$"
  30. mkdir "$module_dir"
  31. trap 'rm -rf "$module_dir"' EXIT
  32. cat > "$tmpfile"<<EOF
  33. (use-modules (guix packages)
  34. (gnu packages base))
  35. (format #t "~a\n" (package-name coreutils))
  36. EOF
  37. test "`guix repl "$tmpfile"`" = "coreutils"
  38. # Make sure that the file can also be loaded when passed as a relative file
  39. # name.
  40. (cd "$(dirname "$tmpfile")"; test "$(guix repl "$(basename "$tmpfile")")" = "coreutils")
  41. cat > "$module_dir/foo.scm"<<EOF
  42. (define-module (foo)
  43. #:use-module (guix packages)
  44. #:use-module (gnu packages base))
  45. (define-public dummy
  46. (package (inherit hello)
  47. (name "dummy")
  48. (version "42")
  49. (synopsis "dummy package")
  50. (description "dummy package. Only used for testing purposes.")))
  51. EOF
  52. cat > "$tmpfile"<<EOF
  53. (use-modules (guix packages)
  54. (foo))
  55. (format #t "~a\n" (package-version dummy))
  56. EOF
  57. test "`guix repl "$tmpfile" -L "$module_dir"`" = "42"
  58. cat > "$tmpfile"<<EOF
  59. (format #t "~a\n" (cdr (command-line)))
  60. EOF
  61. test "`guix repl -- "$tmpfile" -a b --input=foo.txt`" = "(-a b --input=foo.txt)"
  62. cat > "$tmpfile"<<EOF
  63. #!$(type -P env) -S guix repl --
  64. !#
  65. (format #t "~a\n" (cdr (command-line)))
  66. EOF
  67. chmod 755 $tmpfile
  68. test "`"$tmpfile" -a b --input=foo.txt`" = "(-a b --input=foo.txt)"