gwl-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] tests/examples: Add running of workflow examples


From: Olivier Dion
Subject: [PATCH v2] tests/examples: Add running of workflow examples
Date: Sat, 7 May 2022 12:47:03 -0400

End to end testing of pre-defined scenarios are a good way to check for
regression.

Here we introduce testing of some examples available in the documentation.  That
way, we're sure that new users should be able to run them without problems.

Each scenario is a different test and is run in a different temporary
directory which get destroyed if the scenario succeeded.
---
 tests/examples.scm | 51 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 48 insertions(+), 3 deletions(-)

diff --git a/tests/examples.scm b/tests/examples.scm
index 6f7a64e..22edd12 100644
--- a/tests/examples.scm
+++ b/tests/examples.scm
@@ -14,12 +14,13 @@
 ;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (test-examples)
+  #:use-module (gwl ui)
   #:use-module (gwl utils)
   #:use-module (gwl errors)
+  #:use-module ((guix build utils)
+                #:select (delete-file-recursively))
   #:use-module (srfi srfi-64))
 
-(test-begin "examples")
-
 (define user-module-for-file
   (@@ (gwl workflows utils) user-module-for-file))
 
@@ -30,6 +31,48 @@
   (lambda (port)
     (wisp-reader port (user-module-for-file "test.w"))))
 
+(define top-srcdir (getenv "abs_top_srcdir"))
+
+(define-syntax-rule (with-temporary-directory prefix body body* ...)
+  (let ((old-dir (getcwd))
+        (tmp-dir (mkdtemp
+                  (format #f "/tmp/~a.XXXXXX" prefix))))
+    (dynamic-wind
+      (lambda ()
+        (log-event 'info (G_ "Changing directory: ~a") tmp-dir)
+        (chdir tmp-dir))
+      (lambda () body body* ...)
+      (lambda ()
+        (log-event 'info (G_ "Changing directory: ~a") old-dir)
+        (chdir old-dir)
+        (delete-file-recursively tmp-dir)))))
+
+(define (process-success? status)
+  (zero? (or (status:exit-val status)
+             (status:term-sig status))))
+
+(define (run-example example)
+
+  (define abs-example
+    (canonicalize-path
+     (string-append top-srcdir "/doc/examples/" example)))
+
+  (with-temporary-directory
+   (string-append "gwl-example-" example)
+   (process-success?
+    (system* "guix"
+             "workflow"
+             "run"
+             "--force"
+             "--container"
+             "--log-events=all"
+             abs-example))))
+
+(define-syntax-rule (test-example example)
+  (test-assert example (run-example example)))
+
+(test-begin "examples")
+
 (test-equal "wisp syntax produces the expected S-expression"
   '(process haiku
             (outputs "haiku.txt")
@@ -39,8 +82,10 @@
                         (with-output-to-file (unquote outputs)
                           (lambda () (display "the library 
book\noverdue?\nslow falling snow"))))))
 
-  (call-with-input-file (string-append (getenv "abs_top_srcdir")
+  (call-with-input-file (string-append top-srcdir
                                        "/doc/examples/haiku.w")
     read-wisp))
 
+(test-example "extended-example-workflow.w")
+
 (test-end "examples")
-- 
2.36.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]