geiser-users
[Top][All Lists]
Advanced

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

[Geiser-users] [PATCH] Add test functionality for Racket and rackunit


From: Diogo F. S. Ramos
Subject: [Geiser-users] [PATCH] Add test functionality for Racket and rackunit
Date: Fri, 22 Mar 2013 11:57:15 -0300

Using the command `geiser-racket-test' it's possible to run the tests
in a `test' submodule defined inside the current buffer.

A new buffer, using the Geiser Racket Test Mode (a mode derived from
Compilation Mode), will be open.

As `raco test ...' always returns 0, a wrapper racket program is used
to check if there was any output to stderr. Any output to stderr is
interpret as a failure in some check and the wrapper racket program
returns 1, after letting all the checks run.
---

This one uses a Compilation Mode derivative so there is no need to
install the alist to the global compilation-error-* variables.

I'm still not sure about the names I picked, like "Geiser Racket
Test".

OK, I think it's time to start considering the usefulness of this
feature and if it's appropriate for geiser.

AFAICS having a test submodule inside your file is encouraged by the
Racket community and it's also mentioned in the docs. Using `raco
test' is the standard way and rackunit the preferred unit-testing
framework.

The design of Compilation Mode is very flexible so if later some other
unit-testing framework comes, with a different syntax, it's very easy
to accommodate both.

 elisp/geiser-racket.el        |   30 ++++++++++++++++++++++++++++++
 scheme/racket/geiser/test.rkt |   17 +++++++++++++++++
 2 files changed, 47 insertions(+)
 create mode 100644 scheme/racket/geiser/test.rkt

diff --git a/elisp/geiser-racket.el b/elisp/geiser-racket.el
index d9d59d1..b847ecf 100644
--- a/elisp/geiser-racket.el
+++ b/elisp/geiser-racket.el
@@ -216,6 +216,36 @@ using start-geiser, a procedure in the geiser/server 
module."
   t)
 
 
+;;; Test module
+(defconst geiser-racket-test-regexp-alist
+  (list (list (concat "^location: *(#<path:\\(.*\\)> "
+                      "\\([0-9]*\\) \\([0-9]*\\) "
+                      "\\([0-9]*\\) \\([0-9]*\\))$")
+              1 2 3))
+  "Regexp used to match rackunit hits.")
+
+(define-compilation-mode geiser-racket-test-mode "Geiser Racket Test"
+  "Compilation mode for Geiser Racket Test"
+  (set (make-local-variable 'compilation-error-regexp-alist)
+       geiser-racket-test-regexp-alist))
+
+(defun geiser-racket--test-module (filename)
+  "Test a file module with a `test' submodule"
+  (compilation-start
+   (mapconcat
+    #'shell-quote-argument
+    (list (geiser-racket--binary)
+          (expand-file-name "racket/geiser/test.rkt" geiser-scheme-dir)
+          filename)
+    " ")
+   'geiser-racket-test-mode))
+
+(defun geiser-racket-test ()
+  "Runs tests defined inside a `test' submodule in the current buffer"
+  (interactive)
+  (geiser-racket--test-module (buffer-file-name)))
+
+
 ;;; Error display
 
 (defconst geiser-racket--file-rxs
diff --git a/scheme/racket/geiser/test.rkt b/scheme/racket/geiser/test.rkt
new file mode 100644
index 0000000..6dc5d6c
--- /dev/null
+++ b/scheme/racket/geiser/test.rkt
@@ -0,0 +1,17 @@
+#lang racket/base
+
+(require racket/cmdline
+         racket/port)
+
+(module+ main
+  (define filename (command-line #:args (filename) filename))
+  (define status 0)
+  (let-values (((subproc stdout stdin stderr)
+                (subprocess #f #f #f
+                            (find-executable-path "raco")
+                            "test" filename)))
+    (unless (eof-object? (peek-byte stderr))
+      (copy-port stderr (current-error-port))
+      (set! status 1))
+    (subprocess-wait subproc)
+    (exit status)))
-- 
1.7.9.5




reply via email to

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