A huge amount of work, but have not necessarily advanced very far.

Trying to get to the point that this can effectively be called on
other projects, and to be honest I think I'm almost there...
This commit is contained in:
Simon Brooke 2014-04-06 00:02:57 +01:00
parent adca01416c
commit ef6b042d64
2 changed files with 501 additions and 430 deletions

View file

@ -2,11 +2,18 @@
(:use clojure.java.io (:use clojure.java.io
clojure.pprint)) clojure.pprint))
(defn write-test [fnname arg] (defn maybe-quote [val]
(try "Convert val into a form in which, after being passed through the pretty
(list 'is (list '= (list fnname arg) (list 'quote (eval (list fnname arg))))) printer, it will be reconstituted in a form useful to the test"
(catch Exception e (list 'is (list 'thrown? (.getClass e) (list fnname arg)))))) (cond
(symbol? val) (list 'symbol (str val))
true (list 'quote val)))
(defn write-test [fnname arg]
(try
(let [val (eval (list fnname arg))]
(list 'is (list '= (list fnname arg) (maybe-quote val))))
(catch Exception e (list 'is (list 'thrown? (.getClass e) (list fnname arg))))))
(defn constant? [arg] (defn constant? [arg]
(not (or (not (or
@ -21,9 +28,9 @@
"return a list of all elements in this form which are constants" "return a list of all elements in this form which are constants"
(filter constant? (flatten form))) (filter constant? (flatten form)))
(defn find-interesting-args [sexpr] (defn find-interesting-args [sexpr extra-vars]
"Find things in sexpr which would be even more interesting if passed as arguments to it" "Find things in sexpr which would be even more interesting if passed as arguments to it"
(concat generic-args (concat generic-args extra-vars
(flatten (flatten
(map (map
#(cond #(cond
@ -32,20 +39,32 @@
true %) true %)
(constants sexpr))))) (constants sexpr)))))
(defn testgen [fndef] (defn testgen [fndef extra-vars]
(cond (or (= (first fndef) 'def)(= (first fndef) 'defn)) (cond (or (= (first fndef) 'def)(= (first fndef) 'defn))
(let [name (first (rest fndef))] (let [name (first (rest fndef))]
(concat (list 'deftest (symbol (str "test-" name))) (list 'deftest (symbol (str "test-" name))
(map #(write-test name %) (find-interesting-args fndef)))))) (concat (list 'testing (str name))
(map #(write-test name %)
(find-interesting-args fndef extra-vars)))))))
;; (defn gen-tests [fnname form] ;; generating a test file
;; (map (partial write-test fnname) (constants form)))
(defn clean-filename [filename] (defn clean-filename [filename]
"remove the trailing '.clj' from a Clojure file name" "remove the leading 'src/' and trailing '.clj' (if present) from a Clojure file name"
(cond (let [without-suffix (cond
(.endsWith filename ".clj") (.substring filename 0 (- (count filename) 4)) (.endsWith filename ".clj") (.substring filename 0 (- (count filename) 4))
true filename)) true filename)
prefix-position (.indexOf filename "src/")]
(cond (> prefix-position -1) (.substring without-suffix (+ prefix-position 4))
true without-suffix)))
(defn test-filename [filename]
"return an approximately-correct filename in which to save tests"
(let [prefix-position (.indexOf filename "src/")
prefix (cond (> prefix-position -1) (.substring filename 0 prefix-position)
true "")]
(str prefix "test/" (clean-filename filename) "_test.clj")))
(defn packagename-from-filename [filename] (defn packagename-from-filename [filename]
"Return, as a symbol, the package name associated with this filename. There's "Return, as a symbol, the package name associated with this filename. There's
@ -53,6 +72,18 @@
(let [fn (clean-filename filename)] (let [fn (clean-filename filename)]
(symbol (.replace fn "/" ".")))) (symbol (.replace fn "/" "."))))
(defn find-vars-in-reader [eddie]
(try
(let [sexpr (read eddie)]
(cond
(nil? sexpr) nil
(= (first sexpr) 'def) (cons (first (rest sexpr)) (find-vars-in-reader eddie))
true (find-vars-in-reader eddie)))
(catch RuntimeException eof)))
(defn find-vars-in-file [filename]
(with-open [eddie (java.io.PushbackReader. (reader filename))]
(find-vars-in-reader eddie)))
(defn generate-tests [filename] (defn generate-tests [filename]
"Generate a suite of characterisation tests for the file indicated by this filename. "Generate a suite of characterisation tests for the file indicated by this filename.
@ -60,14 +91,26 @@
filename: the file path name of a file containing Clojure code to be tested." filename: the file path name of a file containing Clojure code to be tested."
(try (try
(let [fn (clean-filename filename) (let [fn (clean-filename filename)
pn (packagename-from-filename filename)] pn (packagename-from-filename filename)
extra-vars (find-vars-in-file filename)]
(println "Read vars: " extra-vars)
(println "Writing to: " (test-filename filename))
;; load the file so that any functions in it are usable ;; load the file so that any functions in it are usable
;; (load fn) (load fn)
;; (refer pn) (refer pn)
(with-open [eddie (java.io.PushbackReader. (reader filename)) (with-open [eddie (java.io.PushbackReader. (reader filename))
dickens (writer "output")] dickens (writer (test-filename filename))]
(while (.ready eddie) (.write dickens (str "(ns " pn "_test\n"))
(let [form (macroexpand (read eddie))] (.write dickens (str "\t(:require [clojure.test :refer :all]\n\t["
(cond (= (first form) 'def) pn " :refer :all]))\n\n"))
(pprint (testgen form) dickens)))))) (.write dickens
";; auto-generated by testgen - see https://github.com/simon-brooke/testgen\n\n")
(while (.ready eddie)
(println "reading...")
(let [form (read eddie)]
(cond (= (first form) 'defn)
(do
(println (first (rest form)) "...")
(pprint (testgen form extra-vars) dickens)))))))
(catch Exception eof))) (catch Exception eof)))

View file

@ -1,419 +1,447 @@
(ns testgen.core-test (ns testgen.core_test
"In the spirit of eating your own dogfood, all these tests are generated (:require [clojure.test :refer :all]
with testgen." [testgen.core :refer :all]))
(:require [clojure.test :refer :all]
[testgen.core :refer :all])) ;; auto-generated by testgen - see https://github.com/simon-brooke/testgen
(deftest
test-maybe-quote
(testing
"maybe-quote"
(is (= (maybe-quote nil) ''nil))
(is (= (maybe-quote ()) ''()))
(is (= (maybe-quote '(a :b "c")) ''(a :b "c")))
(is (= (maybe-quote true) ''true))
(is (= (maybe-quote "test") ''"test"))
(is (= (maybe-quote :test) '':test))
(is (= (maybe-quote 0) ''0))
(is (= (maybe-quote Integer/MAX_VALUE) ''2147483647))
(is (= (maybe-quote 22/7) ''22/7))
(is (= (maybe-quote 1.0E-4) ''1.0E-4))
(is (= (maybe-quote -1.0E-4) ''-1.0E-4))
(is
(=
(maybe-quote generic-args)
''(nil
()
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4)))
(is
(=
(maybe-quote
"Convert val into a form in which, after being passed through the pretty\n\tprinter, it will be reconstituted in a form useful to the test")
''"Convert val into a form in which, after being passed through the pretty\n\tprinter, it will be reconstituted in a form useful to the test"))
(is (= (maybe-quote true) ''true))))
(deftest (deftest
test-write-test test-write-test
(is (thrown? clojure.lang.ArityException (write-test nil))) (testing
(is (thrown? clojure.lang.ArityException (write-test ()))) "write-test"
(is (thrown? clojure.lang.ArityException (write-test '(a :b "c")))) (is (thrown? clojure.lang.ArityException (write-test nil)))
(is (thrown? clojure.lang.ArityException (write-test true))) (is (thrown? clojure.lang.ArityException (write-test ())))
(is (thrown? clojure.lang.ArityException (write-test "test"))) (is (thrown? clojure.lang.ArityException (write-test '(a :b "c"))))
(is (thrown? clojure.lang.ArityException (write-test :test))) (is (thrown? clojure.lang.ArityException (write-test true)))
(is (thrown? clojure.lang.ArityException (write-test 0))) (is (thrown? clojure.lang.ArityException (write-test "test")))
(is (is (thrown? clojure.lang.ArityException (write-test :test)))
(thrown? clojure.lang.ArityException (write-test Integer/MAX_VALUE))) (is (thrown? clojure.lang.ArityException (write-test 0)))
(is (thrown? clojure.lang.ArityException (write-test 22/7))) (is
(is (thrown? clojure.lang.ArityException (write-test 1.0E-4))) (thrown?
(is (thrown? clojure.lang.ArityException (write-test -1.0E-4)))) clojure.lang.ArityException
(write-test Integer/MAX_VALUE)))
(is (thrown? clojure.lang.ArityException (write-test 22/7)))
(is (thrown? clojure.lang.ArityException (write-test 1.0E-4)))
(is (thrown? clojure.lang.ArityException (write-test -1.0E-4)))
(is (thrown? clojure.lang.ArityException (write-test generic-args)))))
(deftest (deftest
test-constant? test-constant?
(is (= (constant? nil) 'true)) (testing
(is (= (constant? ()) 'false)) "constant?"
(is (= (constant? '(a :b "c")) 'false)) (is (= (constant? nil) 'true))
(is (= (constant? true) 'true)) (is (= (constant? ()) 'false))
(is (= (constant? "test") 'true)) (is (= (constant? '(a :b "c")) 'false))
(is (= (constant? :test) 'true)) (is (= (constant? true) 'true))
(is (= (constant? 0) 'true)) (is (= (constant? "test") 'true))
(is (= (constant? Integer/MAX_VALUE) 'true)) (is (= (constant? :test) 'true))
(is (= (constant? 22/7) 'true)) (is (= (constant? 0) 'true))
(is (= (constant? 1.0E-4) 'true)) (is (= (constant? Integer/MAX_VALUE) 'true))
(is (= (constant? -1.0E-4) 'true))) (is (= (constant? 22/7) 'true))
(deftest (is (= (constant? 1.0E-4) 'true))
test-generic-args (is (= (constant? -1.0E-4) 'true))
(is (thrown? java.lang.ClassCastException (generic-args nil))) (is (= (constant? generic-args) 'false))))
(is (thrown? java.lang.ClassCastException (generic-args ())))
(is (thrown? java.lang.ClassCastException (generic-args '(a :b "c"))))
(is (thrown? java.lang.ClassCastException (generic-args true)))
(is (thrown? java.lang.ClassCastException (generic-args "test")))
(is (thrown? java.lang.ClassCastException (generic-args :test)))
(is (thrown? java.lang.ClassCastException (generic-args 0)))
(is
(thrown?
java.lang.ClassCastException
(generic-args Integer/MAX_VALUE)))
(is (thrown? java.lang.ClassCastException (generic-args 22/7)))
(is (thrown? java.lang.ClassCastException (generic-args 1.0E-4)))
(is (thrown? java.lang.ClassCastException (generic-args -1.0E-4)))
(is (thrown? java.lang.ClassCastException (generic-args nil)))
(is (thrown? java.lang.ClassCastException (generic-args :b)))
(is (thrown? java.lang.ClassCastException (generic-args "c")))
(is (thrown? java.lang.ClassCastException (generic-args true)))
(is (thrown? java.lang.ClassCastException (generic-args "test")))
(is (thrown? java.lang.ClassCastException (generic-args :test)))
(is (thrown? java.lang.ClassCastException (generic-args 0)))
(is (thrown? java.lang.ClassCastException (generic-args 1)))
(is (thrown? java.lang.ClassCastException (generic-args -1)))
(is (thrown? java.lang.ClassCastException (generic-args 22/7)))
(is
(thrown?
java.lang.ClassCastException
(generic-args 3.142957142857143)))
(is
(thrown?
java.lang.ClassCastException
(generic-args 3.1427571428571426)))
(is (thrown? java.lang.ClassCastException (generic-args 1.0E-4)))
(is (thrown? java.lang.ClassCastException (generic-args 2.0E-4)))
(is (thrown? java.lang.ClassCastException (generic-args 0.0)))
(is (thrown? java.lang.ClassCastException (generic-args -1.0E-4)))
(is (thrown? java.lang.ClassCastException (generic-args 0.0)))
(is (thrown? java.lang.ClassCastException (generic-args -2.0E-4))))
(deftest (deftest
test-constants test-constants
(is (= (constants nil) '())) (testing
(is (= (constants ()) '())) "constants"
(is (= (constants '(a :b "c")) '(:b "c"))) (is (= (constants nil) '()))
(is (= (constants true) '())) (is (= (constants ()) '()))
(is (= (constants "test") '())) (is (= (constants '(a :b "c")) '(:b "c")))
(is (= (constants :test) '())) (is (= (constants true) '()))
(is (= (constants 0) '())) (is (= (constants "test") '()))
(is (= (constants Integer/MAX_VALUE) '())) (is (= (constants :test) '()))
(is (= (constants 22/7) '())) (is (= (constants 0) '()))
(is (= (constants 1.0E-4) '())) (is (= (constants Integer/MAX_VALUE) '()))
(is (= (constants -1.0E-4) '())) (is (= (constants 22/7) '()))
(is (is (= (constants 1.0E-4) '()))
(= (is (= (constants -1.0E-4) '()))
(constants (is
"return a list of all elements in this form which are constants") (=
'()))) (constants generic-args)
'(nil :b "c" true "test" :test 0 22/7 1.0E-4 -1.0E-4)))
(is
(=
(constants
"return a list of all elements in this form which are constants")
'()))))
(deftest (deftest
test-find-interesting-args test-find-interesting-args
(is (testing
(= "find-interesting-args"
(find-interesting-args nil) (is
'(nil (thrown? clojure.lang.ArityException (find-interesting-args nil)))
() (is (thrown? clojure.lang.ArityException (find-interesting-args ())))
'(a :b "c") (is
true (thrown?
"test" clojure.lang.ArityException
:test (find-interesting-args '(a :b "c"))))
0 (is
Integer/MAX_VALUE (thrown? clojure.lang.ArityException (find-interesting-args true)))
22/7 (is
1.0E-4 (thrown?
-1.0E-4))) clojure.lang.ArityException
(is (find-interesting-args "test")))
(= (is
(find-interesting-args ()) (thrown? clojure.lang.ArityException (find-interesting-args :test)))
'(nil (is (thrown? clojure.lang.ArityException (find-interesting-args 0)))
() (is
'(a :b "c") (thrown?
true clojure.lang.ArityException
"test" (find-interesting-args Integer/MAX_VALUE)))
:test (is
0 (thrown? clojure.lang.ArityException (find-interesting-args 22/7)))
Integer/MAX_VALUE (is
22/7 (thrown?
1.0E-4 clojure.lang.ArityException
-1.0E-4))) (find-interesting-args 1.0E-4)))
(is (is
(= (thrown?
(find-interesting-args '(a :b "c")) clojure.lang.ArityException
'(nil (find-interesting-args -1.0E-4)))
() (is
'(a :b "c") (thrown?
true clojure.lang.ArityException
"test" (find-interesting-args generic-args)))
:test (is
0 (thrown?
Integer/MAX_VALUE clojure.lang.ArityException
22/7 (find-interesting-args
1.0E-4 "Find things in sexpr which would be even more interesting if passed as arguments to it")))
-1.0E-4 (is
:b (thrown?
"c"))) clojure.lang.ArityException
(is (find-interesting-args 1.0E-4)))
(= (is
(find-interesting-args true) (thrown?
'(nil clojure.lang.ArityException
() (find-interesting-args 2.0E-4)))
'(a :b "c") (is
true (thrown? clojure.lang.ArityException (find-interesting-args 0.0)))
"test" (is
:test (thrown?
0 clojure.lang.ArityException
Integer/MAX_VALUE (find-interesting-args 1.0E-4)))
22/7 (is
1.0E-4 (thrown?
-1.0E-4))) clojure.lang.ArityException
(is (find-interesting-args 2.0E-4)))
(= (is
(find-interesting-args "test") (thrown? clojure.lang.ArityException (find-interesting-args 0.0)))
'(nil (is
() (thrown? clojure.lang.ArityException (find-interesting-args true)))))
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4)))
(is
(=
(find-interesting-args :test)
'(nil
()
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4)))
(is
(=
(find-interesting-args 0)
'(nil
()
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4)))
(is
(=
(find-interesting-args Integer/MAX_VALUE)
'(nil
()
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4)))
(is
(=
(find-interesting-args 22/7)
'(nil
()
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4)))
(is
(=
(find-interesting-args 1.0E-4)
'(nil
()
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4)))
(is
(=
(find-interesting-args -1.0E-4)
'(nil
()
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4)))
(is
(=
(find-interesting-args
"Find things in sexpr which would be even more interesting if passed as arguments to it")
'(nil
()
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4)))
(is
(=
(find-interesting-args 1.0E-4)
'(nil
()
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4)))
(is
(=
(find-interesting-args 2.0E-4)
'(nil
()
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4)))
(is
(=
(find-interesting-args 0.0)
'(nil
()
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4)))
(is
(=
(find-interesting-args 1.0E-4)
'(nil
()
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4)))
(is
(=
(find-interesting-args 2.0E-4)
'(nil
()
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4)))
(is
(=
(find-interesting-args 0.0)
'(nil
()
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4)))
(is
(=
(find-interesting-args true)
'(nil
()
'(a :b "c")
true
"test"
:test
0
Integer/MAX_VALUE
22/7
1.0E-4
-1.0E-4))))
(deftest (deftest
test-testgen test-testgen
(is (= (testgen nil) 'nil)) (testing
(is (= (testgen ()) 'nil)) "testgen"
(is (= (testgen '(a :b "c")) 'nil)) (is (thrown? clojure.lang.ArityException (testgen nil)))
(is (thrown? java.lang.IllegalArgumentException (testgen true))) (is (thrown? clojure.lang.ArityException (testgen ())))
(is (= (testgen "test") 'nil)) (is (thrown? clojure.lang.ArityException (testgen '(a :b "c"))))
(is (thrown? java.lang.IllegalArgumentException (testgen :test))) (is (thrown? clojure.lang.ArityException (testgen true)))
(is (thrown? java.lang.IllegalArgumentException (testgen 0))) (is (thrown? clojure.lang.ArityException (testgen "test")))
(is (is (thrown? clojure.lang.ArityException (testgen :test)))
(thrown? (is (thrown? clojure.lang.ArityException (testgen 0)))
java.lang.IllegalArgumentException (is
(testgen Integer/MAX_VALUE))) (thrown? clojure.lang.ArityException (testgen Integer/MAX_VALUE)))
(is (thrown? java.lang.IllegalArgumentException (testgen 22/7))) (is (thrown? clojure.lang.ArityException (testgen 22/7)))
(is (thrown? java.lang.IllegalArgumentException (testgen 1.0E-4))) (is (thrown? clojure.lang.ArityException (testgen 1.0E-4)))
(is (thrown? java.lang.IllegalArgumentException (testgen -1.0E-4))) (is (thrown? clojure.lang.ArityException (testgen -1.0E-4)))
(is (= (testgen "test-") 'nil))) (is (thrown? clojure.lang.ArityException (testgen generic-args)))
(is (thrown? clojure.lang.ArityException (testgen "test-")))))
(deftest (deftest
test-clean-filename test-clean-filename
(is (thrown? java.lang.NullPointerException (clean-filename nil))) (testing
(is (thrown? java.lang.IllegalArgumentException (clean-filename ()))) "clean-filename"
(is (is (thrown? java.lang.NullPointerException (clean-filename nil)))
(thrown? (is (thrown? java.lang.IllegalArgumentException (clean-filename ())))
java.lang.IllegalArgumentException (is
(clean-filename '(a :b "c")))) (thrown?
(is java.lang.IllegalArgumentException
(thrown? java.lang.IllegalArgumentException (clean-filename true))) (clean-filename '(a :b "c"))))
(is (= (clean-filename "test") '"test")) (is
(is (thrown? java.lang.IllegalArgumentException (clean-filename true)))
(thrown? java.lang.IllegalArgumentException (clean-filename :test))) (is (= (clean-filename "test") '"test"))
(is (thrown? java.lang.IllegalArgumentException (clean-filename 0))) (is
(is (thrown? java.lang.IllegalArgumentException (clean-filename :test)))
(thrown? (is (thrown? java.lang.IllegalArgumentException (clean-filename 0)))
java.lang.IllegalArgumentException (is
(clean-filename Integer/MAX_VALUE))) (thrown?
(is java.lang.IllegalArgumentException
(thrown? java.lang.IllegalArgumentException (clean-filename 22/7))) (clean-filename Integer/MAX_VALUE)))
(is (is
(thrown? java.lang.IllegalArgumentException (clean-filename 1.0E-4))) (thrown? java.lang.IllegalArgumentException (clean-filename 22/7)))
(is (is
(thrown? (thrown?
java.lang.IllegalArgumentException java.lang.IllegalArgumentException
(clean-filename -1.0E-4))) (clean-filename 1.0E-4)))
(is (is
(= (thrown?
(clean-filename java.lang.IllegalArgumentException
"remove the trailing '.clj' from a Clojure file name") (clean-filename -1.0E-4)))
'"remove the trailing '.clj' from a Clojure file name")) (is
(is (= (clean-filename ".clj") '"")) (thrown?
(is (thrown? java.lang.IllegalArgumentException (clean-filename 0))) java.lang.IllegalArgumentException
(is (thrown? java.lang.IllegalArgumentException (clean-filename 1))) (clean-filename generic-args)))
(is (thrown? java.lang.IllegalArgumentException (clean-filename -1))) (is
(is (thrown? java.lang.IllegalArgumentException (clean-filename 4))) (=
(is (thrown? java.lang.IllegalArgumentException (clean-filename 5))) (clean-filename
(is (thrown? java.lang.IllegalArgumentException (clean-filename 3))) "remove the leading 'src/' and trailing '.clj' (if present) from a Clojure file name")
(is '"' and trailing '.clj' (if present) from a Clojure file name"))
(thrown? java.lang.IllegalArgumentException (clean-filename true)))) (is (= (clean-filename ".clj") '""))
(is (thrown? java.lang.IllegalArgumentException (clean-filename 0)))
(is (thrown? java.lang.IllegalArgumentException (clean-filename 1)))
(is (thrown? java.lang.IllegalArgumentException (clean-filename -1)))
(is (thrown? java.lang.IllegalArgumentException (clean-filename 4)))
(is (thrown? java.lang.IllegalArgumentException (clean-filename 5)))
(is (thrown? java.lang.IllegalArgumentException (clean-filename 3)))
(is
(thrown? java.lang.IllegalArgumentException (clean-filename true)))
(is (= (clean-filename "src/") '""))
(is (thrown? java.lang.IllegalArgumentException (clean-filename -1)))
(is (thrown? java.lang.IllegalArgumentException (clean-filename 0)))
(is (thrown? java.lang.IllegalArgumentException (clean-filename -2)))
(is (thrown? java.lang.IllegalArgumentException (clean-filename 4)))
(is (thrown? java.lang.IllegalArgumentException (clean-filename 5)))
(is (thrown? java.lang.IllegalArgumentException (clean-filename 3)))
(is
(thrown? java.lang.IllegalArgumentException (clean-filename true)))))
(deftest
test-test-filename
(testing
"test-filename"
(is (thrown? java.lang.NullPointerException (test-filename nil)))
(is (thrown? java.lang.IllegalArgumentException (test-filename ())))
(is
(thrown?
java.lang.IllegalArgumentException
(test-filename '(a :b "c"))))
(is
(thrown? java.lang.IllegalArgumentException (test-filename true)))
(is (= (test-filename "test") '"test/test_test.clj"))
(is
(thrown? java.lang.IllegalArgumentException (test-filename :test)))
(is (thrown? java.lang.IllegalArgumentException (test-filename 0)))
(is
(thrown?
java.lang.IllegalArgumentException
(test-filename Integer/MAX_VALUE)))
(is
(thrown? java.lang.IllegalArgumentException (test-filename 22/7)))
(is
(thrown? java.lang.IllegalArgumentException (test-filename 1.0E-4)))
(is
(thrown?
java.lang.IllegalArgumentException
(test-filename -1.0E-4)))
(is
(thrown?
java.lang.IllegalArgumentException
(test-filename generic-args)))
(is
(=
(test-filename
"return an approximately-correct filename in which to save tests")
'"test/return an approximately-correct filename in which to save tests_test.clj"))
(is (= (test-filename "src/") '"test/_test.clj"))
(is (thrown? java.lang.IllegalArgumentException (test-filename -1)))
(is (thrown? java.lang.IllegalArgumentException (test-filename 0)))
(is (thrown? java.lang.IllegalArgumentException (test-filename -2)))
(is (thrown? java.lang.IllegalArgumentException (test-filename 0)))
(is (thrown? java.lang.IllegalArgumentException (test-filename 1)))
(is (thrown? java.lang.IllegalArgumentException (test-filename -1)))
(is
(thrown? java.lang.IllegalArgumentException (test-filename true)))
(is (= (test-filename "") '"test/_test.clj"))
(is (= (test-filename "test/") '"test/test/_test.clj"))
(is (= (test-filename "_test.clj") '"test/_test_test.clj"))))
(deftest
test-packagename-from-filename
(testing
"packagename-from-filename"
(is
(thrown?
java.lang.NullPointerException
(packagename-from-filename nil)))
(is
(thrown?
java.lang.IllegalArgumentException
(packagename-from-filename ())))
(is
(thrown?
java.lang.IllegalArgumentException
(packagename-from-filename '(a :b "c"))))
(is
(thrown?
java.lang.IllegalArgumentException
(packagename-from-filename true)))
(is (= (packagename-from-filename "test") (symbol "test")))
(is
(thrown?
java.lang.IllegalArgumentException
(packagename-from-filename :test)))
(is
(thrown?
java.lang.IllegalArgumentException
(packagename-from-filename 0)))
(is
(thrown?
java.lang.IllegalArgumentException
(packagename-from-filename Integer/MAX_VALUE)))
(is
(thrown?
java.lang.IllegalArgumentException
(packagename-from-filename 22/7)))
(is
(thrown?
java.lang.IllegalArgumentException
(packagename-from-filename 1.0E-4)))
(is
(thrown?
java.lang.IllegalArgumentException
(packagename-from-filename -1.0E-4)))
(is
(thrown?
java.lang.IllegalArgumentException
(packagename-from-filename generic-args)))
(is
(=
(packagename-from-filename
"Return, as a symbol, the package name associated with this filename. There's\n probably a better way of doing this.")
(symbol
"Return, as a symbol, the package name associated with this filename. There's\n probably a better way of doing this.")))
(is (= (packagename-from-filename "/") (symbol ".")))
(is (= (packagename-from-filename ".") (symbol ".")))))
(deftest
test-find-vars-in-reader
(testing
"find-vars-in-reader"
(is (= (find-vars-in-reader nil) 'nil))
(is (= (find-vars-in-reader ()) 'nil))
(is (= (find-vars-in-reader '(a :b "c")) 'nil))
(is (= (find-vars-in-reader true) 'nil))
(is (= (find-vars-in-reader "test") 'nil))
(is (= (find-vars-in-reader :test) 'nil))
(is (= (find-vars-in-reader 0) 'nil))
(is (= (find-vars-in-reader Integer/MAX_VALUE) 'nil))
(is (= (find-vars-in-reader 22/7) 'nil))
(is (= (find-vars-in-reader 1.0E-4) 'nil))
(is (= (find-vars-in-reader -1.0E-4) 'nil))
(is (= (find-vars-in-reader generic-args) 'nil))
(is (= (find-vars-in-reader nil) 'nil))
(is (= (find-vars-in-reader true) 'nil))))
(deftest
test-find-vars-in-file
(testing
"find-vars-in-file"
(is
(thrown?
java.lang.IllegalArgumentException
(find-vars-in-file nil)))
(is
(thrown? java.lang.IllegalArgumentException (find-vars-in-file ())))
(is
(thrown?
java.lang.IllegalArgumentException
(find-vars-in-file '(a :b "c"))))
(is
(thrown?
java.lang.IllegalArgumentException
(find-vars-in-file true)))
(is
(thrown? java.io.FileNotFoundException (find-vars-in-file "test")))
(is
(thrown?
java.lang.IllegalArgumentException
(find-vars-in-file :test)))
(is
(thrown? java.lang.IllegalArgumentException (find-vars-in-file 0)))
(is
(thrown?
java.lang.IllegalArgumentException
(find-vars-in-file Integer/MAX_VALUE)))
(is
(thrown?
java.lang.IllegalArgumentException
(find-vars-in-file 22/7)))
(is
(thrown?
java.lang.IllegalArgumentException
(find-vars-in-file 1.0E-4)))
(is
(thrown?
java.lang.IllegalArgumentException
(find-vars-in-file -1.0E-4)))
(is
(thrown?
java.lang.IllegalArgumentException
(find-vars-in-file generic-args)))))
(deftest
test-generate-tests
(testing
"generate-tests"
(is (= (generate-tests nil) 'nil))
(is (= (generate-tests ()) 'nil))
(is (= (generate-tests '(a :b "c")) 'nil))
(is (= (generate-tests true) 'nil))
(is (= (generate-tests "test") 'nil))
(is (= (generate-tests :test) 'nil))
(is (= (generate-tests 0) 'nil))
(is (= (generate-tests Integer/MAX_VALUE) 'nil))
(is (= (generate-tests 22/7) 'nil))
(is (= (generate-tests 1.0E-4) 'nil))
(is (= (generate-tests -1.0E-4) 'nil))
(is (= (generate-tests generic-args) 'nil))
(is
(=
(generate-tests
"Generate a suite of characterisation tests for the file indicated by this filename.\n\n filename: the file path name of a file containing Clojure code to be tested.")
'nil))
(is (= (generate-tests "Read vars: ") 'nil))
(is (= (generate-tests "Writing to: ") 'nil))
(is (= (generate-tests "(ns ") 'nil))
(is (= (generate-tests "_test\n") 'nil))
(is
(=
(generate-tests "\t(:require [clojure.test :refer :all]\n\t[")
'nil))
(is (= (generate-tests " :refer :all]))\n\n") 'nil))
(is
(=
(generate-tests
";; auto-generated by testgen - see https://github.com/simon-brooke/testgen\n\n")
'nil))
(is (= (generate-tests "reading...") 'nil))
(is (= (generate-tests "...") 'nil))))