Skip to content

Commit

Permalink
Tests were rewritten to use Rove and to support (asdf:test-system :40…
Browse files Browse the repository at this point in the history
…ants-doc)
  • Loading branch information
svetlyak40wt committed Apr 4, 2021
1 parent 2e12dc9 commit abc843b
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 180 deletions.
5 changes: 0 additions & 5 deletions 40ants-doc-test.asd
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
:pathname "test"
:depends-on ("40ants-doc-test/test-transcribe"
"40ants-doc-test/test")
;; :components ((:module "test"
;; :serial t
;; :components ((:file "package")
;; (:file "test-transcribe")
;; (:file "test"))))
:perform (test-op (op c)
(unless (symbol-call :rove :run c)
(error "Tests failed"))))
1 change: 1 addition & 0 deletions Changes.org
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ file-subseq function was rewritten.
* Locatives can be specified without a package prefix inside the defsection
because all locative symbols now live in 40ANTS-DOC/LOCATIVES package.
* Function update-asdf-system-readmes was renamed to update-asdf-system-readmes and now it generates only one README file
* Tests were rewritten to use Rove and to support (asdf:test-system :40ants-doc)
4 changes: 1 addition & 3 deletions src/builder.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,7 @@
(40ants-doc/builder/footer::emit-footer stream))
(unless (eq format :markdown)
(let ((markdown-string (40ants-doc/page::with-temp-input-from-page (stream page)
(uiop:slurp-stream-string stream)
;; (40ants-doc/utils::read-stream-into-string stream)
)))
(uiop:slurp-stream-string stream))))
(40ants-doc/utils::delete-stream-spec (40ants-doc/page::page-temp-stream-spec page))
(40ants-doc/page::with-final-output-to-page (stream page)
(when (40ants-doc/page::page-header-fn page)
Expand Down
7 changes: 4 additions & 3 deletions src/transcribe.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#:read-prefixed-lines
#:read-line*
#:whitespacep)
(:import-from #:40ants-doc/reference))
(:import-from #:40ants-doc/reference)
(:import-from #:40ants-doc/page)
(:import-from #:swank))
(in-package 40ants-doc/transcribe)

(named-readtables:in-readtable pythonic-string-reader:pythonic-string-syntax)
Expand Down Expand Up @@ -477,8 +479,7 @@
;; There is no way to guarantee that FILE-POSITION will work
;; on a stream so let's just read the entire INPUT into a
;; string.
(with-input-from-string (stream ;; (40ants-doc/utils::read-stream-into-string input)
(uiop:slurp-stream-string input))
(with-input-from-string (stream (uiop:slurp-stream-string input))
(funcall fn stream)))
((stringp input)
(with-input-from-string (input input)
Expand Down
12 changes: 3 additions & 9 deletions src/utils.lisp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(uiop:define-package #:40ants-doc/utils
(:use #:cl)
(:import-from #:40ants-doc/builder/vars))
(:import-from #:40ants-doc/builder/vars)
(:import-from #:alexandria))
(in-package 40ants-doc/utils)


Expand All @@ -13,18 +14,11 @@
#-(or sbcl allegro)
(ignore-errors (symbol-value symbol)))

;; TODO: probably replace with uiop
;; (defun read-stream-into-string (stream &key (buffer-size 4096))
;; (let ((*print-pretty* nil))
;; (with-output-to-string (datum)
;; (let ((buffer (make-array buffer-size :element-type 'character)))
;; (loop for bytes-read = (read-sequence buffer stream)
;; do (write-sequence buffer datum :start 0 :end bytes-read)
;; while (= bytes-read buffer-size))))))

(defun subseq* (seq start)
(subseq seq (min (length seq) start)))


(defun relativize-pathname (pathname reference-pathname)
"Return a pathname that's equivalent to PATHNAME but relative to
REFERENCE-PATHNAME if possible. Like ENOUGH-NAMESTRING, but inserts
Expand Down
164 changes: 85 additions & 79 deletions test/test-transcribe.lisp
Original file line number Diff line number Diff line change
@@ -1,62 +1,67 @@
(defpackage #:40ants-doc-test/test-transcribe
(:use #:cl)
(:import-from #:40ants-doc/utils)
(:import-from #:40ants-doc/transcribe))
(:import-from #:40ants-doc/transcribe)
(:import-from #:rove
#:testing
#:ok
#:deftest))
(in-package 40ants-doc-test/test-transcribe)


(defun test-read-prefixed-lines ()
(assert
(deftest test-read-prefixed-lines
(ok
(equal (multiple-value-list
(with-input-from-string (stream (format nil ">1"))
(40ants-doc/utils::read-prefixed-lines stream ">")))
'("1" 1 nil t 2)))
(assert
(ok
(equal (multiple-value-list
(with-input-from-string (stream (format nil ">1~%"))
(40ants-doc/utils::read-prefixed-lines stream ">")))
'("1" 1 nil t 3)))
(assert
(ok
(equal (multiple-value-list
(with-input-from-string (stream (format nil ">1~%>"))
(40ants-doc/utils::read-prefixed-lines stream ">")))
`(,(format nil "1~%") 2 nil t 4)))
(assert
(ok
(equal (multiple-value-list
(with-input-from-string (stream (format nil ">1~%>2~%> 3"))
(40ants-doc/utils::read-prefixed-lines stream ">")))
`(,(format nil "1~%2~%3") 3 nil t 9)))
(assert
(ok
(equal (multiple-value-list
(with-input-from-string (stream (format nil ">1~%>2~%> 3~%xy~%"))
(40ants-doc/utils::read-prefixed-lines stream ">")))
`(,(format nil "1~%2~%3") 3 "xy" nil 10)))
(assert
(ok
(equal (multiple-value-list
(with-input-from-string (stream (format nil ">1~%>2~%> 3~%xy"))
(40ants-doc/utils::read-prefixed-lines stream ">")))
`(,(format nil "1~%2~%3") 3 "xy" t 10)))
(assert
(ok
(equal (multiple-value-list
(with-input-from-string (stream (format nil ">1"))
(40ants-doc/utils::read-prefixed-lines stream ">" :first-line-prefix "")))
'(">1" 1 nil t 2)))
(assert
(ok
(equal (multiple-value-list
(with-input-from-string (stream (format nil ">1~%>2~%> 3"))
(40ants-doc/utils::read-prefixed-lines stream ">" :first-line-prefix "")))
`(,(format nil ">1~%2~%3") 3 nil t 9)))
(assert
(ok
(equal (multiple-value-list
(with-input-from-string (stream (format nil ">1~%>2~%> 3~%xy~%"))
(40ants-doc/utils::read-prefixed-lines stream ">" :first-line-prefix "")))
`(,(format nil ">1~%2~%3") 3 "xy" nil 10)))
(assert
(ok
(equal (multiple-value-list
(with-input-from-string (stream (format nil ">1~%>2~%> 3~%xy"))
(40ants-doc/utils::read-prefixed-lines stream ">" :first-line-prefix "")))
`(,(format nil ">1~%2~%3") 3 "xy" t 10))))


(defclass bbb ()
())

Expand All @@ -77,6 +82,7 @@
#+ecl
(format stream "#<BBB* ~%>"))


(defparameter *transcribe-test-cases*
'((:input "1"
:transcript (((1 "1") nil))
Expand Down Expand Up @@ -278,57 +284,61 @@
(values node t nil)))
tree))

(defun test-read-write-transcript ()
(let ((*package* (find-package :40ants-doc-test/test-transcribe)))
(loop for test-case in *transcribe-test-cases* do
(format t "test case: ~S~%" test-case)
(destructuring-bind (&key input transcript output check-consistency
update-only (include-no-output update-only)
(include-no-value update-only)
default-syntax errors output-consistency-errors
values-consistency-errors)
test-case
(let ((output-consistency-errors* ())
(values-consistency-errors* ())
(errors* ()))
(catch 'here
(handler-bind
((40ants-doc/transcribe::transcription-output-consistency-error
(lambda (e)
(push (40ants-doc/transcribe::transcription-error-file-position e)
output-consistency-errors*)
(continue)))
(40ants-doc/transcribe::transcription-values-consistency-error
(lambda (e)
(push (40ants-doc/transcribe::transcription-error-file-position e)
values-consistency-errors*)
(continue)))
(40ants-doc/transcribe::transcription-error
(lambda (e)
(push (40ants-doc/transcribe::transcription-error-file-position e)
errors*)
(throw 'here nil))))
(let* ((input (format nil input))
(output (when output (format nil output)))
(transcript (call-format-on-strings transcript))
(transcript* (40ants-doc/transcribe::read-transcript input))
(output*
(40ants-doc/transcribe::write-transcript
transcript* nil
:check-consistency check-consistency
:update-only update-only
:include-no-output include-no-output
:include-no-value include-no-value
:default-syntax default-syntax)))
(when transcript
(assert (equal transcript transcript*)))
(when output
(assert (equal output output*))))))
(assert (equal (reverse errors*) errors))
(assert (equal (reverse output-consistency-errors*)
output-consistency-errors))
(assert (equal (reverse values-consistency-errors*)
values-consistency-errors)))))))
(deftest test-read-write-transcript
(loop with *package* = (find-package :40ants-doc-test/test-transcribe)
for test-case in *transcribe-test-cases*
do (testing (format nil "test case: ~S" test-case)
(destructuring-bind (&key input transcript output check-consistency
update-only (include-no-output update-only)
(include-no-value update-only)
default-syntax errors output-consistency-errors
values-consistency-errors)
test-case
(let ((output-consistency-errors* ())
(values-consistency-errors* ())
(errors* ()))
(catch 'here
(handler-bind
((40ants-doc/transcribe::transcription-output-consistency-error
(lambda (e)
(push (40ants-doc/transcribe::transcription-error-file-position e)
output-consistency-errors*)
(continue)))
(40ants-doc/transcribe::transcription-values-consistency-error
(lambda (e)
(push (40ants-doc/transcribe::transcription-error-file-position e)
values-consistency-errors*)
(continue)))
(40ants-doc/transcribe::transcription-error
(lambda (e)
(push (40ants-doc/transcribe::transcription-error-file-position e)
errors*)
(throw 'here nil))))
(let* ((input (format nil input))
(output (when output (format nil output)))
(transcript (call-format-on-strings transcript))
(transcript* (40ants-doc/transcribe::read-transcript input))
(output*
(40ants-doc/transcribe::write-transcript
transcript* nil
:check-consistency check-consistency
:update-only update-only
:include-no-output include-no-output
:include-no-value include-no-value
:default-syntax default-syntax)))
(when transcript
(ok (equal transcript
transcript*)))
(when output
(ok (equal output
output*))))))
(ok (equal (reverse errors*)
errors))
(ok (equal (reverse output-consistency-errors*)
output-consistency-errors))
(ok (equal (reverse values-consistency-errors*)
values-consistency-errors)))))))


(defparameter *transcribe-source-file*
(asdf:system-relative-pathname
Expand All @@ -338,17 +348,6 @@
(asdf:system-relative-pathname
:40ants-doc-test "test/data/baseline/transcribe-transcription.lisp"))

(defun test-transcribe-from-source ()
(check-transcription *transcribe-source-file*
*transcribe-transcription-file*
:check-consistency nil))

;;; Check that repeated transcription produces the same results.
(defun test-transcribe-stability ()
(check-transcription *transcribe-transcription-file*
*transcribe-transcription-file*
:check-consistency t))


(defun get-diff (baseline new-content)
(uiop:with-temporary-file (:stream new :pathname new-path :direction :output)
Expand All @@ -364,6 +363,7 @@

(defun check-transcription (source-file transcription-file
&key check-consistency)
"Check that repeated transcription produces the same results."
(let ((result (with-output-to-string (transcription)
(with-open-file (source source-file)
(40ants-doc/transcribe::transcribe source
Expand All @@ -380,8 +380,14 @@
(alexandria:write-string-into-file result transcription-file
:if-exists :rename-and-delete))))

(defun test ()
(test-read-prefixed-lines)
(test-read-write-transcript)
(test-transcribe-from-source)
(test-transcribe-stability))

(deftest test-transcribe-from-source
(check-transcription *transcribe-source-file*
*transcribe-transcription-file*
:check-consistency nil))


(deftest test-transcribe-stability
(check-transcription *transcribe-transcription-file*
*transcribe-transcription-file*
:check-consistency t))
Loading

0 comments on commit abc843b

Please sign in to comment.