From ef6b042d6420fb945f07debe9f75a2675f42add8 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Sun, 6 Apr 2014 00:02:57 +0100 Subject: [PATCH] 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... --- src/testgen/core.clj | 91 ++-- test/testgen/core_test.clj | 840 +++++++++++++++++++------------------ 2 files changed, 501 insertions(+), 430 deletions(-) diff --git a/src/testgen/core.clj b/src/testgen/core.clj index 5699fdc..11aed05 100644 --- a/src/testgen/core.clj +++ b/src/testgen/core.clj @@ -2,11 +2,18 @@ (:use clojure.java.io clojure.pprint)) -(defn write-test [fnname arg] - (try - (list 'is (list '= (list fnname arg) (list 'quote (eval (list fnname arg))))) - (catch Exception e (list 'is (list 'thrown? (.getClass e) (list fnname arg)))))) +(defn maybe-quote [val] + "Convert val into a form in which, after being passed through the pretty + printer, it will be reconstituted in a form useful to the test" + (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] (not (or @@ -21,9 +28,9 @@ "return a list of all elements in this form which are constants" (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" - (concat generic-args + (concat generic-args extra-vars (flatten (map #(cond @@ -32,20 +39,32 @@ true %) (constants sexpr))))) -(defn testgen [fndef] +(defn testgen [fndef extra-vars] (cond (or (= (first fndef) 'def)(= (first fndef) 'defn)) (let [name (first (rest fndef))] - (concat (list 'deftest (symbol (str "test-" name))) - (map #(write-test name %) (find-interesting-args fndef)))))) + (list 'deftest (symbol (str "test-" name)) + (concat (list 'testing (str name)) + (map #(write-test name %) + (find-interesting-args fndef extra-vars))))))) -;; (defn gen-tests [fnname form] -;; (map (partial write-test fnname) (constants form))) +;; generating a test file (defn clean-filename [filename] - "remove the trailing '.clj' from a Clojure file name" - (cond - (.endsWith filename ".clj") (.substring filename 0 (- (count filename) 4)) - true filename)) + "remove the leading 'src/' and trailing '.clj' (if present) from a Clojure file name" + (let [without-suffix (cond + (.endsWith filename ".clj") (.substring filename 0 (- (count filename) 4)) + 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] "Return, as a symbol, the package name associated with this filename. There's @@ -53,6 +72,18 @@ (let [fn (clean-filename filename)] (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] "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." (try (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 fn) - ;; (refer pn) - (with-open [eddie (java.io.PushbackReader. (reader filename)) - dickens (writer "output")] - (while (.ready eddie) - (let [form (macroexpand (read eddie))] - (cond (= (first form) 'def) - (pprint (testgen form) dickens)))))) + (load fn) + (refer pn) + (with-open [eddie (java.io.PushbackReader. (reader filename)) + dickens (writer (test-filename filename))] + (.write dickens (str "(ns " pn "_test\n")) + (.write dickens (str "\t(:require [clojure.test :refer :all]\n\t[" + pn " :refer :all]))\n\n")) + (.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))) + diff --git a/test/testgen/core_test.clj b/test/testgen/core_test.clj index 5eb848c..69348e9 100644 --- a/test/testgen/core_test.clj +++ b/test/testgen/core_test.clj @@ -1,419 +1,447 @@ -(ns testgen.core-test - "In the spirit of eating your own dogfood, all these tests are generated - with testgen." - (:require [clojure.test :refer :all] - [testgen.core :refer :all])) +(ns testgen.core_test + (: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 test-write-test - (is (thrown? clojure.lang.ArityException (write-test nil))) - (is (thrown? clojure.lang.ArityException (write-test ()))) - (is (thrown? clojure.lang.ArityException (write-test '(a :b "c")))) - (is (thrown? clojure.lang.ArityException (write-test true))) - (is (thrown? clojure.lang.ArityException (write-test "test"))) - (is (thrown? clojure.lang.ArityException (write-test :test))) - (is (thrown? clojure.lang.ArityException (write-test 0))) - (is - (thrown? 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)))) + (testing + "write-test" + (is (thrown? clojure.lang.ArityException (write-test nil))) + (is (thrown? clojure.lang.ArityException (write-test ()))) + (is (thrown? clojure.lang.ArityException (write-test '(a :b "c")))) + (is (thrown? clojure.lang.ArityException (write-test true))) + (is (thrown? clojure.lang.ArityException (write-test "test"))) + (is (thrown? clojure.lang.ArityException (write-test :test))) + (is (thrown? clojure.lang.ArityException (write-test 0))) + (is + (thrown? + 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 test-constant? - (is (= (constant? nil) 'true)) - (is (= (constant? ()) 'false)) - (is (= (constant? '(a :b "c")) 'false)) - (is (= (constant? true) 'true)) - (is (= (constant? "test") 'true)) - (is (= (constant? :test) 'true)) - (is (= (constant? 0) 'true)) - (is (= (constant? Integer/MAX_VALUE) 'true)) - (is (= (constant? 22/7) 'true)) - (is (= (constant? 1.0E-4) 'true)) - (is (= (constant? -1.0E-4) 'true))) -(deftest - test-generic-args - (is (thrown? java.lang.ClassCastException (generic-args nil))) - (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)))) + (testing + "constant?" + (is (= (constant? nil) 'true)) + (is (= (constant? ()) 'false)) + (is (= (constant? '(a :b "c")) 'false)) + (is (= (constant? true) 'true)) + (is (= (constant? "test") 'true)) + (is (= (constant? :test) 'true)) + (is (= (constant? 0) 'true)) + (is (= (constant? Integer/MAX_VALUE) 'true)) + (is (= (constant? 22/7) 'true)) + (is (= (constant? 1.0E-4) 'true)) + (is (= (constant? -1.0E-4) 'true)) + (is (= (constant? generic-args) 'false)))) (deftest test-constants - (is (= (constants nil) '())) - (is (= (constants ()) '())) - (is (= (constants '(a :b "c")) '(:b "c"))) - (is (= (constants true) '())) - (is (= (constants "test") '())) - (is (= (constants :test) '())) - (is (= (constants 0) '())) - (is (= (constants Integer/MAX_VALUE) '())) - (is (= (constants 22/7) '())) - (is (= (constants 1.0E-4) '())) - (is (= (constants -1.0E-4) '())) - (is - (= - (constants - "return a list of all elements in this form which are constants") - '()))) + (testing + "constants" + (is (= (constants nil) '())) + (is (= (constants ()) '())) + (is (= (constants '(a :b "c")) '(:b "c"))) + (is (= (constants true) '())) + (is (= (constants "test") '())) + (is (= (constants :test) '())) + (is (= (constants 0) '())) + (is (= (constants Integer/MAX_VALUE) '())) + (is (= (constants 22/7) '())) + (is (= (constants 1.0E-4) '())) + (is (= (constants -1.0E-4) '())) + (is + (= + (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 test-find-interesting-args - (is - (= - (find-interesting-args nil) - '(nil - () - '(a :b "c") - true - "test" - :test - 0 - Integer/MAX_VALUE - 22/7 - 1.0E-4 - -1.0E-4))) - (is - (= - (find-interesting-args ()) - '(nil - () - '(a :b "c") - true - "test" - :test - 0 - Integer/MAX_VALUE - 22/7 - 1.0E-4 - -1.0E-4))) - (is - (= - (find-interesting-args '(a :b "c")) - '(nil - () - '(a :b "c") - true - "test" - :test - 0 - Integer/MAX_VALUE - 22/7 - 1.0E-4 - -1.0E-4 - :b - "c"))) - (is - (= - (find-interesting-args true) - '(nil - () - '(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 :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)))) + (testing + "find-interesting-args" + (is + (thrown? clojure.lang.ArityException (find-interesting-args nil))) + (is (thrown? clojure.lang.ArityException (find-interesting-args ()))) + (is + (thrown? + clojure.lang.ArityException + (find-interesting-args '(a :b "c")))) + (is + (thrown? clojure.lang.ArityException (find-interesting-args true))) + (is + (thrown? + clojure.lang.ArityException + (find-interesting-args "test"))) + (is + (thrown? clojure.lang.ArityException (find-interesting-args :test))) + (is (thrown? clojure.lang.ArityException (find-interesting-args 0))) + (is + (thrown? + clojure.lang.ArityException + (find-interesting-args Integer/MAX_VALUE))) + (is + (thrown? clojure.lang.ArityException (find-interesting-args 22/7))) + (is + (thrown? + clojure.lang.ArityException + (find-interesting-args 1.0E-4))) + (is + (thrown? + clojure.lang.ArityException + (find-interesting-args -1.0E-4))) + (is + (thrown? + clojure.lang.ArityException + (find-interesting-args generic-args))) + (is + (thrown? + clojure.lang.ArityException + (find-interesting-args + "Find things in sexpr which would be even more interesting if passed as arguments to it"))) + (is + (thrown? + clojure.lang.ArityException + (find-interesting-args 1.0E-4))) + (is + (thrown? + clojure.lang.ArityException + (find-interesting-args 2.0E-4))) + (is + (thrown? clojure.lang.ArityException (find-interesting-args 0.0))) + (is + (thrown? + clojure.lang.ArityException + (find-interesting-args 1.0E-4))) + (is + (thrown? + clojure.lang.ArityException + (find-interesting-args 2.0E-4))) + (is + (thrown? clojure.lang.ArityException (find-interesting-args 0.0))) + (is + (thrown? clojure.lang.ArityException (find-interesting-args true))))) (deftest test-testgen - (is (= (testgen nil) 'nil)) - (is (= (testgen ()) 'nil)) - (is (= (testgen '(a :b "c")) 'nil)) - (is (thrown? java.lang.IllegalArgumentException (testgen true))) - (is (= (testgen "test") 'nil)) - (is (thrown? java.lang.IllegalArgumentException (testgen :test))) - (is (thrown? java.lang.IllegalArgumentException (testgen 0))) - (is - (thrown? - java.lang.IllegalArgumentException - (testgen Integer/MAX_VALUE))) - (is (thrown? java.lang.IllegalArgumentException (testgen 22/7))) - (is (thrown? java.lang.IllegalArgumentException (testgen 1.0E-4))) - (is (thrown? java.lang.IllegalArgumentException (testgen -1.0E-4))) - (is (= (testgen "test-") 'nil))) + (testing + "testgen" + (is (thrown? clojure.lang.ArityException (testgen nil))) + (is (thrown? clojure.lang.ArityException (testgen ()))) + (is (thrown? clojure.lang.ArityException (testgen '(a :b "c")))) + (is (thrown? clojure.lang.ArityException (testgen true))) + (is (thrown? clojure.lang.ArityException (testgen "test"))) + (is (thrown? clojure.lang.ArityException (testgen :test))) + (is (thrown? clojure.lang.ArityException (testgen 0))) + (is + (thrown? clojure.lang.ArityException (testgen Integer/MAX_VALUE))) + (is (thrown? clojure.lang.ArityException (testgen 22/7))) + (is (thrown? clojure.lang.ArityException (testgen 1.0E-4))) + (is (thrown? clojure.lang.ArityException (testgen -1.0E-4))) + (is (thrown? clojure.lang.ArityException (testgen generic-args))) + (is (thrown? clojure.lang.ArityException (testgen "test-"))))) (deftest test-clean-filename - (is (thrown? java.lang.NullPointerException (clean-filename nil))) - (is (thrown? java.lang.IllegalArgumentException (clean-filename ()))) - (is - (thrown? - java.lang.IllegalArgumentException - (clean-filename '(a :b "c")))) - (is - (thrown? java.lang.IllegalArgumentException (clean-filename true))) - (is (= (clean-filename "test") '"test")) - (is - (thrown? java.lang.IllegalArgumentException (clean-filename :test))) - (is (thrown? java.lang.IllegalArgumentException (clean-filename 0))) - (is - (thrown? - java.lang.IllegalArgumentException - (clean-filename Integer/MAX_VALUE))) - (is - (thrown? java.lang.IllegalArgumentException (clean-filename 22/7))) - (is - (thrown? java.lang.IllegalArgumentException (clean-filename 1.0E-4))) - (is - (thrown? - java.lang.IllegalArgumentException - (clean-filename -1.0E-4))) - (is - (= - (clean-filename - "remove the trailing '.clj' from a Clojure file name") - '"remove the trailing '.clj' from a Clojure file name")) - (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)))) + (testing + "clean-filename" + (is (thrown? java.lang.NullPointerException (clean-filename nil))) + (is (thrown? java.lang.IllegalArgumentException (clean-filename ()))) + (is + (thrown? + java.lang.IllegalArgumentException + (clean-filename '(a :b "c")))) + (is + (thrown? java.lang.IllegalArgumentException (clean-filename true))) + (is (= (clean-filename "test") '"test")) + (is + (thrown? java.lang.IllegalArgumentException (clean-filename :test))) + (is (thrown? java.lang.IllegalArgumentException (clean-filename 0))) + (is + (thrown? + java.lang.IllegalArgumentException + (clean-filename Integer/MAX_VALUE))) + (is + (thrown? java.lang.IllegalArgumentException (clean-filename 22/7))) + (is + (thrown? + java.lang.IllegalArgumentException + (clean-filename 1.0E-4))) + (is + (thrown? + java.lang.IllegalArgumentException + (clean-filename -1.0E-4))) + (is + (thrown? + java.lang.IllegalArgumentException + (clean-filename generic-args))) + (is + (= + (clean-filename + "remove the leading 'src/' and trailing '.clj' (if present) from a Clojure file name") + '"' and trailing '.clj' (if present) from a Clojure file name")) + (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))))