SummaryRefsLogTreeCommitDiffStats
path: root/tests/environment.scm
diff options
context:
space:
mode:
authorMathieu Lirzin <mthl@gnu.org>2018-03-24 20:23:45 +0100
committerMathieu Lirzin <mthl@gnu.org>2018-03-24 20:32:13 +0100
commitb8cbf635cc4dad9be860d4489ba8e9a308082c3d (patch)
tree8d8a293834099c076c204959e76cdfff3d11f8f6 /tests/environment.scm
parente013e2a6d64da700a3a096e2dbb5ff6856f97697 (diff)
downloadmcron-b8cbf635cc4dad9be860d4489ba8e9a308082c3d.tar.gz
mcron-b8cbf635cc4dad9be860d4489ba8e9a308082c3d.tar.bz2
mcron-b8cbf635cc4dad9be860d4489ba8e9a308082c3d.zip
environment: Check configuration environment
* tests/environment.scm ("current-environment-mods-copy: empty") ("current-environment-mods: init", "append-environment-mods: basic") ("append-environment-mods: twice", "clear-environment-mods: effect") ("current-environment-mods-copy: basic"): New tests.
Diffstat (limited to 'tests/environment.scm')
-rw-r--r--tests/environment.scm55
1 files changed, 54 insertions, 1 deletions
diff --git a/tests/environment.scm b/tests/environment.scm
index 1bc34a6..05ad3be 100644
--- a/tests/environment.scm
+++ b/tests/environment.scm
@@ -1,5 +1,5 @@
;;;; environment.scm -- tests for (mcron environment) module
-;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
+;;; Copyright © 2016, 2018 Mathieu Lirzin <mthl@gnu.org>
;;;
;;; This file is part of GNU Mcron.
;;;
@@ -17,10 +17,63 @@
;;; along with GNU Mcron. If not, see <http://www.gnu.org/licenses/>.
(use-modules (srfi srfi-64)
+ (srfi srfi-111)
(mcron environment))
(test-begin "environment")
+;;; Check 'current-environment-mods' initial value which should be empty.
+(test-equal "current-environment-mods: init"
+ '()
+ (unbox (@@ (mcron environment) %current-environment-mods)))
+
+;;; Check 'current-environment-mods-copy' with an empty environment
+(test-assert "current-environment-mods-copy: empty"
+ (let* ((env (box '()))
+ (copy0 (get-current-environment-mods-copy #:environ env))
+ (copy1 (get-current-environment-mods-copy #:environ env)))
+ (set! copy1 (assoc-set! copy1 "FOO" "BAR"))
+ (and (equal? '() (unbox env))
+ (equal? '() copy0)
+ (equal? '(("FOO" . "BAR")) copy1))))
+
+;;; Check 'current-environment-mods-copy' with a basic environment
+(test-assert "current-environment-mods-copy: basic"
+ (let* ((init-env '(("a" . "1") ("b" . "2")))
+ (env (box init-env))
+ (copy0 (get-current-environment-mods-copy #:environ env))
+ (copy1 (get-current-environment-mods-copy #:environ env)))
+ (set! copy1 (assoc-set! copy1 "c" "3"))
+ (and (equal? init-env (unbox env))
+ (equal? init-env copy0)
+ (equal? `(("c" . "3") . ,init-env) copy1))))
+
+;;; Check 'append-environment-mods' basic call
+(test-equal "append-environment-mods: basic"
+ "BAR"
+ (let ((env (box '())))
+ (append-environment-mods "FOO" "BAR" #:environ env)
+ (assoc-ref (unbox env) "FOO")))
+
+;;; Check 'append-environment-mods' that when adding the same key twice the
+;;; later is placed after the previous one.
+(test-equal "append-environment-mods: twice"
+ '(("FOO" . "BAR") ("FOO" . "BAZ"))
+ (let ((env (box '())))
+ (append-environment-mods "FOO" "BAR" #:environ env)
+ (append-environment-mods "FOO" "BAZ" #:environ env)
+ (unbox env)))
+
+;;; Check 'clear-environment-mods' side effect
+(test-equal "clear-environment-mods: effect"
+ '()
+ (let ((env (box '())))
+ (append-environment-mods "FOO" "BAR" #:environ env)
+ (append-environment-mods "FOO" "BAZ" #:environ env)
+ (clear-environment-mods #:environ env)
+ (unbox env)))
+
+;;; Check 'modify-environment' basic call
(test-assert "modifiy-environment: basic"
(begin
(modify-environment '(("FOO" . "bar")) (getpw))