all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Olivier Dion <olivier.dion@polymtl.ca>
To: Olivier Dion <olivier.dion@polymtl.ca>, gwl-devel@gnu.org
Subject: [PATCH v2] tests/examples: Add running of workflow examples
Date: Sat,  7 May 2022 12:47:03 -0400	[thread overview]
Message-ID: <20220507164703.27219-1-olivier.dion@polymtl.ca> (raw)
In-Reply-To: <20220429175500.17176-1-olivier.dion@polymtl.ca>

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



  parent reply	other threads:[~2022-05-07 16:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-29 17:55 [PATCH] tests/examples: Add running of workflow examples Olivier Dion
2022-04-29 20:32 ` Ricardo Wurmus
2022-04-29 21:05   ` Olivier Dion via
2022-05-07  6:46     ` Ricardo Wurmus
2022-05-07 16:47 ` Olivier Dion [this message]
2022-06-03  9:06   ` [PATCH v2] " Ricardo Wurmus
2022-06-03 13:11     ` Olivier Dion via
2022-06-03 15:46       ` Ricardo Wurmus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220507164703.27219-1-olivier.dion@polymtl.ca \
    --to=olivier.dion@polymtl.ca \
    --cc=gwl-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.