unofficial mirror of gwl-devel@gnu.org
 help / color / mirror / Atom feed
* [PATCH] tests/examples: Add running of workflow examples
@ 2022-04-29 17:55 Olivier Dion
  2022-04-29 20:32 ` Ricardo Wurmus
  2022-05-07 16:47 ` [PATCH v2] " Olivier Dion
  0 siblings, 2 replies; 8+ messages in thread
From: Olivier Dion @ 2022-04-29 17:55 UTC (permalink / raw)
  To: gwl-devel; +Cc: Olivier Dion

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 | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/tests/examples.scm b/tests/examples.scm
index 6f7a64e..38dac3e 100644
--- a/tests/examples.scm
+++ b/tests/examples.scm
@@ -30,6 +30,8 @@
   (lambda (port)
     (wisp-reader port (user-module-for-file "test.w"))))
 
+(define top-srcdir (getenv "abs_top_srcdir"))
+
 (test-equal "wisp syntax produces the expected S-expression"
   '(process haiku
             (outputs "haiku.txt")
@@ -39,8 +41,43 @@
                         (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))
 
+(define-syntax-rule (with-directory-excursion dir body body* ...)
+  (let ((old-dir (getcwd)))
+    (dynamic-wind
+      (lambda () (chdir dir))
+      (lambda () body body* ...)
+      (lambda () (chdir old-dir)))))
+
+(with-directory-excursion
+    (string-append top-srcdir "/doc/examples")
+
+  (define (process-success? status)
+    (= 0 (or (status:exit-val status)
+             (status:term-sig status))))
+
+  (define scenarios
+       (list "extended-example-workflow.w"))
+
+  (for-each (lambda (example)
+              (test-assert example
+                (let* ((tmp-dir (mkdtemp
+                                 (format #f "gwl-example-~a.XXXXXX" example)))
+                       (abs-example (canonicalize-path example))
+                       (success?
+                        (with-directory-excursion tmp-dir
+                          (process-success?
+                           (system
+                            (format #f "guix workflow run -fc ~a -l all"
+                                    abs-example))))))
+                  (if success?
+                      (system* "rm" "-rf" tmp-dir)
+                      (format (error-output-port)
+                              "Example directory: ~a\n" tmp-dir))
+                  success?)))
+            scenarios))
+
 (test-end "examples")
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-06-03 15:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v2] " Olivier Dion
2022-06-03  9:06   ` Ricardo Wurmus
2022-06-03 13:11     ` Olivier Dion via
2022-06-03 15:46       ` Ricardo Wurmus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).