From 0125723c830a3ec1f5be4da4f5c90eb9442312c7 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 8 Apr 2014 19:25:59 +0100 Subject: [PATCH] Broken, but promising, version: generates interesting tests for multi-arg functions, but breaks on some of them for reasons I don't yet understand. --- README.md | 17 + src/testgen/core.clj | 30 +- test/testgen/core_test.clj | 1122 +++++++++++++++--------------------- 3 files changed, 511 insertions(+), 658 deletions(-) diff --git a/README.md b/README.md index ff315ef..7af49fe 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,23 @@ A Clojure library designed to generate charaterisation tests. +### WARNING! Currently broken + +In trying to make testgen generate tests for functions of more than one argument, I've broken it. It's not completely broken - it generates interesting and useful tests for simple functions like this: + + (generate-test '(defn n-of [arg n] + "Return a list of n instances of arg" + (cond + (zero? n) nil + true (cons arg (n-of arg (dec n))))) '(1 2)) + +This is clearly very promising behaviour. However, it currently won't eat its own dogfood, failing with: + + user=> (generate-tests "src/testgen/core.clj") + IllegalArgumentException Don't know how to create ISeq from: java.lang.Double clojure.lang.RT.seqFrom (RT.java:505) + +I have not yet got to the bottom of this bug :-( + ## What are 'characterisation tests'? Characterisation tests are a suite of tests which characterise the behaviour of a corpus of code. That is to say, they describe, and test, what it does now, whether that's correct or not. Otherwise, they are like unit tests. In fact, they are unit tests - except that unit tests are normally written to describe the desired behaviour of a corpus of code; these describe the actual behaviour. diff --git a/src/testgen/core.clj b/src/testgen/core.clj index aa35b74..9497bd2 100644 --- a/src/testgen/core.clj +++ b/src/testgen/core.clj @@ -1,6 +1,8 @@ (ns testgen.core (:use clojure.java.io - clojure.pprint)) + clojure.pprint + clojure.math.combinatorics)) + (defn maybe-quote [val] "Convert val into a form in which, after being passed through the pretty @@ -9,8 +11,9 @@ (symbol? val) (list 'symbol (str val)) true (list 'quote val))) -(defn generate-assertion [fnname & args] +(defn generate-assertion [fnname args] "Generate an appropiate assertion for these arguments passed to this function" + (print (str "Generating assertion for " (cons fnname args))) (try (let [val (eval (cons fnname args))] (list 'is (list '= (cons fnname args) (maybe-quote val)))) @@ -23,7 +26,9 @@ (vector? arg) (map? arg)))) -(def generic-args '(nil () (quote (a :b "c")) true "test" :test 0 22/7 0.0001 -0.0001)) +;; (def generic-args '(nil () (quote (a :b "c")) "test" true :test 0 Integer/MAX_VALUE 22/7 0.0001 -0.0001)) +(def generic-args '(nil () (quote (a :b "c")) "test" true :test 0)) +;; (def generic-args nil) (defn constants [form] "return a list of all elements in this form which are constants" @@ -48,14 +53,31 @@ true (cons arg (n-of arg (dec n))))) +;; This version of generate-test tries to generate good tests for functions of one +;; argument. It works. +;; (defn generate-test [fndef extra-vars] +;; "Generate a test for this function definition" +;; (cond (or (= (first fndef) 'def)(= (first fndef) 'defn)) +;; (let [name (first (rest fndef)) +;; potential-args (find-interesting-args fndef extra-vars)] +;; (list 'deftest (symbol (str "test-" name)) +;; (concat (list 'testing (str name)) +;; (map #(generate-assertion name (list %)) potential-args)))))) + +;; This version of generate-test tries to generate good tests for functions of one or more than one +;; argument. Unfortunately, it is borked. (defn generate-test [fndef extra-vars] + "Generate a test for this function definition" (cond (or (= (first fndef) 'def)(= (first fndef) 'defn)) (let [name (first (rest fndef)) potential-args (find-interesting-args fndef extra-vars)] + (try (list 'deftest (symbol (str "test-" name)) (concat (list 'testing (str name)) (map #(generate-assertion name %) - (cond (= )))))) + (cond (vector? (nth fndef 2)) (apply cartesian-product (n-of potential-args (count (nth fndef 2)))) + true (map #(list %) potential-args))))) + (catch Exception any))))) ;; generating a test file diff --git a/test/testgen/core_test.clj b/test/testgen/core_test.clj index ea77106..9e6151e 100644 --- a/test/testgen/core_test.clj +++ b/test/testgen/core_test.clj @@ -7,37 +7,16 @@ (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)) + "maybe-quote"Generating assertion for (maybe-quote generic-args) (is (= (maybe-quote generic-args) - ''(nil - () - '(a :b "c") - true - "test" - :test - 0 - Integer/MAX_VALUE - 22/7 - 1.0E-4 - -1.0E-4))) + ''nil))Generating assertion for (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") (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")) + ''"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"))Generating assertion for (maybe-quote true) (is (= (maybe-quote true) ''true)))) @@ -46,77 +25,385 @@ (deftest test-generate-assertion (testing - "generate-assertion" + "generate-assertion"Generating assertion for (generate-assertion generic-args generic-args)Generating assertion for (nil) (is (= - (generate-assertion nil) - '(is (thrown? clojure.lang.Compiler$CompilerException (nil))))) - (is - (= - (generate-assertion ()) - '(is (thrown? java.lang.ClassCastException (()))))) - (is - (= - (generate-assertion '(a :b "c")) - '(is - (thrown? clojure.lang.Compiler$CompilerException ((a :b "c")))))) - (is - (= - (generate-assertion true) - '(is (thrown? java.lang.ClassCastException (true))))) - (is - (= - (generate-assertion "test") - '(is (thrown? java.lang.ClassCastException ("test"))))) - (is - (= - (generate-assertion :test) - '(is (thrown? java.lang.IllegalArgumentException (:test))))) - (is - (= - (generate-assertion 0) - '(is (thrown? java.lang.ClassCastException (0))))) - (is - (= - (generate-assertion Integer/MAX_VALUE) - '(is (thrown? java.lang.ClassCastException (2147483647))))) - (is - (= - (generate-assertion 22/7) - '(is (thrown? java.lang.ClassCastException (22/7))))) - (is - (= - (generate-assertion 1.0E-4) - '(is (thrown? java.lang.ClassCastException (1.0E-4))))) - (is - (= - (generate-assertion -1.0E-4) - '(is (thrown? java.lang.ClassCastException (-1.0E-4))))) - (is - (= - (generate-assertion generic-args) + (generate-assertion generic-args generic-args) '(is (thrown? clojure.lang.Compiler$CompilerException - ((nil - () - '(a :b "c") - true - "test" - :test - 0 - Integer/MAX_VALUE - 22/7 - 1.0E-4 - -1.0E-4)))))) + (nil)))))Generating assertion for (generate-assertion generic-args "Generate an appropiate assertion for these arguments passed to this function")Generating assertion for (nil \G \e \n \e \r \a \t \e \space \a \n \space \a \p \p \r \o \p \i \a \t \e \space \a \s \s \e \r \t \i \o \n \space \f \o \r \space \t \h \e \s \e \space \a \r \g \u \m \e \n \t \s \space \p \a \s \s \e \d \space \t \o \space \t \h \i \s \space \f \u \n \c \t \i \o \n) (is (= (generate-assertion + generic-args + "Generate an appropiate assertion for these arguments passed to this function") + '(is + (thrown? + clojure.lang.Compiler$CompilerException + (nil + \G + \e + \n + \e + \r + \a + \t + \e + \space + \a + \n + \space + \a + \p + \p + \r + \o + \p + \i + \a + \t + \e + \space + \a + \s + \s + \e + \r + \t + \i + \o + \n + \space + \f + \o + \r + \space + \t + \h + \e + \s + \e + \space + \a + \r + \g + \u + \m + \e + \n + \t + \s + \space + \p + \a + \s + \s + \e + \d + \space + \t + \o + \space + \t + \h + \i + \s + \space + \f + \u + \n + \c + \t + \i + \o + \n)))))Generating assertion for (generate-assertion generic-args "Generating assertion for ")Generating assertion for (nil \G \e \n \e \r \a \t \i \n \g \space \a \s \s \e \r \t \i \o \n \space \f \o \r \space) + (is + (= + (generate-assertion generic-args "Generating assertion for ") + '(is + (thrown? + clojure.lang.Compiler$CompilerException + (nil + \G + \e + \n + \e + \r + \a + \t + \i + \n + \g + \space + \a + \s + \s + \e + \r + \t + \i + \o + \n + \space + \f + \o + \r + \space)))))Generating assertion for (generate-assertion "Generate an appropiate assertion for these arguments passed to this function" generic-args)Generating assertion for ("Generate an appropiate assertion for these arguments passed to this function") + (is + (= + (generate-assertion + "Generate an appropiate assertion for these arguments passed to this function" + generic-args) + '(is + (thrown? + java.lang.ClassCastException + ("Generate an appropiate assertion for these arguments passed to this function")))))Generating assertion for (generate-assertion "Generate an appropiate assertion for these arguments passed to this function" "Generate an appropiate assertion for these arguments passed to this function")Generating assertion for ("Generate an appropiate assertion for these arguments passed to this function" \G \e \n \e \r \a \t \e \space \a \n \space \a \p \p \r \o \p \i \a \t \e \space \a \s \s \e \r \t \i \o \n \space \f \o \r \space \t \h \e \s \e \space \a \r \g \u \m \e \n \t \s \space \p \a \s \s \e \d \space \t \o \space \t \h \i \s \space \f \u \n \c \t \i \o \n) + (is + (= + (generate-assertion + "Generate an appropiate assertion for these arguments passed to this function" "Generate an appropiate assertion for these arguments passed to this function") '(is (thrown? java.lang.ClassCastException - ("Generate an appropiate assertion for these arguments passed to this function"))))))) + ("Generate an appropiate assertion for these arguments passed to this function" + \G + \e + \n + \e + \r + \a + \t + \e + \space + \a + \n + \space + \a + \p + \p + \r + \o + \p + \i + \a + \t + \e + \space + \a + \s + \s + \e + \r + \t + \i + \o + \n + \space + \f + \o + \r + \space + \t + \h + \e + \s + \e + \space + \a + \r + \g + \u + \m + \e + \n + \t + \s + \space + \p + \a + \s + \s + \e + \d + \space + \t + \o + \space + \t + \h + \i + \s + \space + \f + \u + \n + \c + \t + \i + \o + \n)))))Generating assertion for (generate-assertion "Generate an appropiate assertion for these arguments passed to this function" "Generating assertion for ")Generating assertion for ("Generate an appropiate assertion for these arguments passed to this function" \G \e \n \e \r \a \t \i \n \g \space \a \s \s \e \r \t \i \o \n \space \f \o \r \space) + (is + (= + (generate-assertion + "Generate an appropiate assertion for these arguments passed to this function" + "Generating assertion for ") + '(is + (thrown? + java.lang.ClassCastException + ("Generate an appropiate assertion for these arguments passed to this function" + \G + \e + \n + \e + \r + \a + \t + \i + \n + \g + \space + \a + \s + \s + \e + \r + \t + \i + \o + \n + \space + \f + \o + \r + \space)))))Generating assertion for (generate-assertion "Generating assertion for " generic-args)Generating assertion for ("Generating assertion for ") + (is + (= + (generate-assertion "Generating assertion for " generic-args) + '(is + (thrown? + java.lang.ClassCastException + ("Generating assertion for ")))))Generating assertion for (generate-assertion "Generating assertion for " "Generate an appropiate assertion for these arguments passed to this function")Generating assertion for ("Generating assertion for " \G \e \n \e \r \a \t \e \space \a \n \space \a \p \p \r \o \p \i \a \t \e \space \a \s \s \e \r \t \i \o \n \space \f \o \r \space \t \h \e \s \e \space \a \r \g \u \m \e \n \t \s \space \p \a \s \s \e \d \space \t \o \space \t \h \i \s \space \f \u \n \c \t \i \o \n) + (is + (= + (generate-assertion + "Generating assertion for " + "Generate an appropiate assertion for these arguments passed to this function") + '(is + (thrown? + java.lang.ClassCastException + ("Generating assertion for " + \G + \e + \n + \e + \r + \a + \t + \e + \space + \a + \n + \space + \a + \p + \p + \r + \o + \p + \i + \a + \t + \e + \space + \a + \s + \s + \e + \r + \t + \i + \o + \n + \space + \f + \o + \r + \space + \t + \h + \e + \s + \e + \space + \a + \r + \g + \u + \m + \e + \n + \t + \s + \space + \p + \a + \s + \s + \e + \d + \space + \t + \o + \space + \t + \h + \i + \s + \space + \f + \u + \n + \c + \t + \i + \o + \n)))))Generating assertion for (generate-assertion "Generating assertion for " "Generating assertion for ")Generating assertion for ("Generating assertion for " \G \e \n \e \r \a \t \i \n \g \space \a \s \s \e \r \t \i \o \n \space \f \o \r \space) + (is + (= + (generate-assertion + "Generating assertion for " + "Generating assertion for ") + '(is + (thrown? + java.lang.ClassCastException + ("Generating assertion for " + \G + \e + \n + \e + \r + \a + \t + \i + \n + \g + \space + \a + \s + \s + \e + \r + \t + \i + \o + \n + \space + \f + \o + \r + \space))))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -124,19 +411,8 @@ (deftest test-constant? (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)))) + "constant?"Generating assertion for (constant? generic-args) + (is (= (constant? generic-args) 'true)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -144,22 +420,11 @@ (deftest test-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) '())) + "constants"Generating assertion for (constants generic-args) (is (= (constants generic-args) - '(nil :b "c" true "test" :test 0 22/7 1.0E-4 -1.0E-4))) + '()))Generating assertion for (constants "return a list of all elements in this form which are constants") (is (= (constants @@ -172,551 +437,100 @@ (deftest test-find-interesting-args (testing - "find-interesting-args" + "find-interesting-args"Generating assertion for (find-interesting-args generic-args generic-args) (is - (thrown? clojure.lang.ArityException (find-interesting-args nil))) - (is (thrown? clojure.lang.ArityException (find-interesting-args ()))) + (= + (find-interesting-args generic-args generic-args) + '()))Generating assertion for (find-interesting-args generic-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 '(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-generate-test - (testing - "generate-test" - (is (thrown? clojure.lang.ArityException (generate-test nil))) - (is (thrown? clojure.lang.ArityException (generate-test ()))) - (is - (thrown? clojure.lang.ArityException (generate-test '(a :b "c")))) - (is (thrown? clojure.lang.ArityException (generate-test true))) - (is (thrown? clojure.lang.ArityException (generate-test "test"))) - (is (thrown? clojure.lang.ArityException (generate-test :test))) - (is (thrown? clojure.lang.ArityException (generate-test 0))) - (is - (thrown? - clojure.lang.ArityException - (generate-test Integer/MAX_VALUE))) - (is (thrown? clojure.lang.ArityException (generate-test 22/7))) - (is (thrown? clojure.lang.ArityException (generate-test 1.0E-4))) - (is (thrown? clojure.lang.ArityException (generate-test -1.0E-4))) - (is - (thrown? clojure.lang.ArityException (generate-test generic-args))) - (is (thrown? clojure.lang.ArityException (generate-test "test-"))))) - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(deftest - test-clean-filename - (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-testname-from-filename - (testing - "testname-from-filename" - (is - (thrown? - java.lang.NullPointerException - (testname-from-filename nil))) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename ()))) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename '(a :b "c")))) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename true))) - (is (= (testname-from-filename "test") '"test/test_test.clj")) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename :test))) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename 0))) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename Integer/MAX_VALUE))) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename 22/7))) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename 1.0E-4))) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename -1.0E-4))) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename generic-args))) - (is - (= - (testname-from-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 (= (testname-from-filename "src/") '"test/_test.clj")) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename -1))) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename 0))) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename -2))) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename 0))) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename 1))) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename -1))) - (is - (thrown? - java.lang.IllegalArgumentException - (testname-from-filename true))) - (is (= (testname-from-filename "") '"test/_test.clj")) - (is (= (testname-from-filename "test/") '"test/test/_test.clj")) - (is (= (testname-from-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, an appropiate name for a test file associated with this filename. There's\n probably a better way of doing this.") - (symbol - "Return, as a symbol, an appropiate name for a test file 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-expr-seq - (testing - "expr-seq" - (is (thrown? java.lang.NullPointerException (expr-seq nil))) - (is (thrown? java.lang.ClassCastException (expr-seq ()))) - (is (thrown? java.lang.ClassCastException (expr-seq '(a :b "c")))) - (is (thrown? java.lang.ClassCastException (expr-seq true))) - (is (thrown? java.lang.ClassCastException (expr-seq "test"))) - (is (thrown? java.lang.ClassCastException (expr-seq :test))) - (is (thrown? java.lang.ClassCastException (expr-seq 0))) - (is - (thrown? java.lang.ClassCastException (expr-seq Integer/MAX_VALUE))) - (is (thrown? java.lang.ClassCastException (expr-seq 22/7))) - (is (thrown? java.lang.ClassCastException (expr-seq 1.0E-4))) - (is (thrown? java.lang.ClassCastException (expr-seq -1.0E-4))) - (is (thrown? java.lang.ClassCastException (expr-seq generic-args))) - (is - (thrown? - java.lang.ClassCastException - (expr-seq - "Returns forms from src (assumed to be Clojure source) as a lazy sequence of expressions"))) - (is (thrown? java.lang.ClassCastException (expr-seq false))) - (is (thrown? java.lang.NullPointerException (expr-seq nil))))) - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(deftest - test-find-vars-in-reader - (testing - "find-vars-in-reader" - (is - (thrown? java.lang.NullPointerException (find-vars-in-reader nil))) - (is (thrown? java.lang.ClassCastException (find-vars-in-reader ()))) - (is - (thrown? - java.lang.ClassCastException - (find-vars-in-reader '(a :b "c")))) - (is - (thrown? java.lang.ClassCastException (find-vars-in-reader true))) - (is - (thrown? java.lang.ClassCastException (find-vars-in-reader "test"))) - (is - (thrown? java.lang.ClassCastException (find-vars-in-reader :test))) - (is (thrown? java.lang.ClassCastException (find-vars-in-reader 0))) - (is - (thrown? - java.lang.ClassCastException - (find-vars-in-reader Integer/MAX_VALUE))) - (is - (thrown? java.lang.ClassCastException (find-vars-in-reader 22/7))) - (is - (thrown? java.lang.ClassCastException (find-vars-in-reader 1.0E-4))) - (is - (thrown? - java.lang.ClassCastException - (find-vars-in-reader -1.0E-4))) - (is - (thrown? - java.lang.ClassCastException - (find-vars-in-reader generic-args))) - (is - (thrown? - java.lang.ClassCastException - (find-vars-in-reader - "Return a list of names of vars declared in the stream this reader reads"))) - (is - (thrown? java.lang.ClassCastException (find-vars-in-reader false))) - (is - (thrown? java.lang.NullPointerException (find-vars-in-reader nil))) - (is - (thrown? java.lang.NullPointerException (find-vars-in-reader nil))) - (is - (thrown? java.lang.ClassCastException (find-vars-in-reader true))))) - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(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))) - (is - (thrown? - java.io.FileNotFoundException - (find-vars-in-file - "Return a list of names of vars declared in the file at this path name"))))) - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(deftest - test-write-header - (testing - "write-header" - (is (thrown? clojure.lang.ArityException (write-header nil))) - (is (thrown? clojure.lang.ArityException (write-header ()))) - (is (thrown? clojure.lang.ArityException (write-header '(a :b "c")))) - (is (thrown? clojure.lang.ArityException (write-header true))) - (is (thrown? clojure.lang.ArityException (write-header "test"))) - (is (thrown? clojure.lang.ArityException (write-header :test))) - (is (thrown? clojure.lang.ArityException (write-header 0))) - (is - (thrown? - clojure.lang.ArityException - (write-header Integer/MAX_VALUE))) - (is (thrown? clojure.lang.ArityException (write-header 22/7))) - (is (thrown? clojure.lang.ArityException (write-header 1.0E-4))) - (is (thrown? clojure.lang.ArityException (write-header -1.0E-4))) - (is - (thrown? clojure.lang.ArityException (write-header generic-args))) - (is (thrown? clojure.lang.ArityException (write-header "(ns "))) - (is (thrown? clojure.lang.ArityException (write-header "_test\n"))) - (is - (thrown? - clojure.lang.ArityException - (write-header "\t(:require [clojure.test :refer :all]\n\t["))) - (is - (thrown? - clojure.lang.ArityException - (write-header " :refer :all]))\n\n"))) - (is - (thrown? - clojure.lang.ArityException - (write-header - ";; auto-generated by testgen - see https://github.com/simon-brooke/testgen\n\n"))))) - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(deftest - test-generate-tests - (testing - "generate-tests" - (is (thrown? java.lang.NullPointerException (generate-tests nil))) - (is (thrown? java.lang.IllegalArgumentException (generate-tests ()))) - (is - (thrown? - java.lang.IllegalArgumentException - (generate-tests '(a :b "c")))) - (is - (thrown? java.lang.IllegalArgumentException (generate-tests true))) - (is (thrown? java.io.FileNotFoundException (generate-tests "test"))) - (is - (thrown? java.lang.IllegalArgumentException (generate-tests :test))) - (is (thrown? java.lang.IllegalArgumentException (generate-tests 0))) - (is - (thrown? - java.lang.IllegalArgumentException - (generate-tests Integer/MAX_VALUE))) - (is - (thrown? java.lang.IllegalArgumentException (generate-tests 22/7))) - (is - (thrown? - java.lang.IllegalArgumentException - (generate-tests 1.0E-4))) - (is - (thrown? - java.lang.IllegalArgumentException - (generate-tests -1.0E-4))) - (is - (thrown? - java.lang.IllegalArgumentException - (generate-tests generic-args))) - (is - (thrown? - java.io.FileNotFoundException - (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."))) - (is - (thrown? - java.io.FileNotFoundException - (generate-tests "Read vars: "))) - (is - (thrown? - java.io.FileNotFoundException - (generate-tests "Writing to: "))) - (is - (thrown? - java.io.FileNotFoundException - (generate-tests "reading..."))) - (is - (thrown? java.lang.IllegalArgumentException (generate-tests false))) - (is (thrown? java.lang.NullPointerException (generate-tests nil))) - (is (thrown? java.io.FileNotFoundException (generate-tests "..."))) - (is - (thrown? - java.io.FileNotFoundException - (generate-tests "\n\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n\n"))) - (is - (thrown? - java.io.FileNotFoundException - (generate-tests "\n\n;; end of file ;;\n\n"))))) - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - - - -;; end of file ;; - + generic-args + "Find things in sexpr which would be even more interesting if passed as arguments to it") + '(\F + \i + \n + \d + \space + \t + \h + \i + \n + \g + \s + \space + \i + \n + \space + \s + \e + \x + \p + \r + \space + \w + \h + \i + \c + \h + \space + \w + \o + \u + \l + \d + \space + \b + \e + \space + \e + \v + \e + \n + \space + \m + \o + \r + \e + \space + \i + \n + \t + \e + \r + \e + \s + \t + \i + \n + \g + \space + \i + \f + \space + \p + \a + \s + \s + \e + \d + \space + \a + \s + \space + \a + \r + \g + \u + \m + \e + \n + \t + \s + \space + \t + \o + \space + \i + \t)))Generating assertion for (find-interesting-args generic-args 1.0E-4) + \ No newline at end of file