From 0fdcbf0a159c9ee4df69bad2c617de01dcb0fd3c Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Sun, 16 Apr 2023 19:55:53 +0200
Subject: Add test system
Write a test for the `write-xfdf` function.
Worked out how to create the test system from:
- https://lispcookbook.github.io/cl-cookbook/testing.html
- https://github.com/sjl/cl-digraph/blob/master/cl-digraph.test.asd
- https://github.com/fukamachi/dexador/blob/master/dexador-test.asd
Add the test string to the `write-xfdf` function to pass the test and
check that the test runner is set up correctly.
---
Makefile | 5 +++++
scratch.lisp | 1 +
src/package.lisp | 4 +++-
src/xfdf.lisp | 17 +++++++++++++++--
test/run.lisp | 3 +++
test/xfdf.lisp | 37 +++++++++++++++++++++++++++++++++++++
xfdf-test.asd | 17 +++++++++++++++++
7 files changed, 81 insertions(+), 3 deletions(-)
create mode 100644 Makefile
create mode 100644 scratch.lisp
create mode 100644 test/run.lisp
create mode 100644 test/xfdf.lisp
create mode 100644 xfdf-test.asd
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..cc12c71
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,5 @@
+LISP := sbcl
+
+.PHONY: test
+test:
+ $(LISP) --load test/run.lisp
diff --git a/scratch.lisp b/scratch.lisp
new file mode 100644
index 0000000..7e2d577
--- /dev/null
+++ b/scratch.lisp
@@ -0,0 +1 @@
+(ql:quickload "xfdf-test")
diff --git a/src/package.lisp b/src/package.lisp
index d535a24..e914975 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -1,2 +1,4 @@
(defpackage :xfdf
- (:use :cl))
+ (:use :cl)
+
+ (:export #:write-xfdf))
diff --git a/src/xfdf.lisp b/src/xfdf.lisp
index 315c63c..a61fcdd 100644
--- a/src/xfdf.lisp
+++ b/src/xfdf.lisp
@@ -1,13 +1,26 @@
(in-package :xfdf)
(defun write-xfdf (output-stream fields)
- (format output-stream "
+ (format output-stream "~
+
")
;; TODO
; (loop do)
+ (format output-stream "
+ Yes
+
+
+ Off
+
+
+ 123 Fake Street, Springfield
+
+")
(format output-stream "
-"))
+")
+
+ output-stream)
diff --git a/test/run.lisp b/test/run.lisp
new file mode 100644
index 0000000..067bcff
--- /dev/null
+++ b/test/run.lisp
@@ -0,0 +1,3 @@
+(ql:quickload "xfdf-test")
+(asdf:test-system :xfdf-test)
+(quit)
diff --git a/test/xfdf.lisp b/test/xfdf.lisp
new file mode 100644
index 0000000..87accaf
--- /dev/null
+++ b/test/xfdf.lisp
@@ -0,0 +1,37 @@
+(defpackage :xfdf-test
+ (:use :cl
+ :1am
+ :xfdf)
+
+ ; (:export #:run)
+ )
+
+(in-package :xfdf-test)
+
+; (defun run ()
+; (1am:run))
+
+(test generates-xfdf-xml
+ (let ((xfdf-string
+ (with-output-to-string (xfdf-stream)
+ (xfdf:write-xfdf
+ xfdf-stream
+ '(("checkbox-on" . T)
+ ("checkbox-off" . nil)
+ ("text" . "123 Fake Street, Springfield"))))))
+ (is (string=
+ xfdf-string
+ "
+
+
+
+ Yes
+
+
+ Off
+
+
+ 123 Fake Street, Springfield
+
+
+"))))
diff --git a/xfdf-test.asd b/xfdf-test.asd
new file mode 100644
index 0000000..9a5b0ab
--- /dev/null
+++ b/xfdf-test.asd
@@ -0,0 +1,17 @@
+(asdf:defsystem xfdf-test
+ :description "Test suite for xfdf"
+ :version "0.0.1"
+ :license "GPL-3.0-or-later"
+ :author "Teddy Wing"
+
+ :depends-on (:1am
+ :xfdf)
+
+ :components ((:module "test"
+ :serial t
+ :components ((:file "xfdf"))))
+
+ :perform (test-op
+ (op system)
+ ; (symbol-call :xfdf-test :run)
+ (symbol-call :1am :run)))
--
cgit v1.2.3