Permalink
Browse files

add bin tests

  • Loading branch information...
1 parent e456e95 commit a7b9edee6dda4b71fa52caaca8005e517796156a @lancepantz lancepantz committed with Nov 13, 2010
Showing with 63 additions and 38 deletions.
  1. +2 −1 .gitignore
  2. +2 −1 examples/test/project.clj
  3. +8 −0 examples/test/src/speak.clj
  4. +4 −3 test/cake/tasks/compile_test.clj
  5. +47 −33 test/cake/tasks/jar_test.clj
View
@@ -8,4 +8,5 @@ lib/
classes/
build/
releases/
-.*
+.*
+examples/test/test-example
@@ -6,7 +6,8 @@
:dev-dependencies [[clojure-complete "0.1.0"]
[autodoc "0.7.1"]]
:context development
- :aot [bar])
+ :aot [speak]
+ :main speak)
(defcontext qa
:foo 1
@@ -0,0 +1,8 @@
+(ns speak
+ (:gen-class))
+
+(defn sayhi []
+ (println "hi!"))
+
+(defn -main []
+ (sayhi))
@@ -11,6 +11,7 @@
(let [results (cake "compile")
classes (fileset-seq {:dir classes :includes "*.class"})]
(is (< 1 (count classes)))
- (is (some #(.contains (.getPath %) "bar$foo") classes))
- (is (some #(.contains (.getPath %) "bar$inc") classes))
- (is (some #(.contains (.getPath %) "bar__init") classes)))))
+ (is (some #(.contains (.getPath %) "speak") classes))
+ (is (some #(.contains (.getPath %) "speak$_main") classes))
+ (is (some #(.contains (.getPath %) "speak$sayhi") classes))
+ (is (some #(.contains (.getPath %) "speak__init") classes)))))
@@ -1,45 +1,59 @@
(ns cake.tasks.jar-test
(:use clojure.test helpers
[cake.ant :only [fileset-seq]]
- [cake.file :only [file rmdir]]
+ [cake.file :only [file rm]]
[clojure.java.shell :only [sh]]))
(use-fixtures :once in-test-project)
+(defn get-jar-contents [jarfile]
+ (into #{} (.split (:out (sh "jar" "tf" (.toString jarfile))) "\n")))
+
+(defn assert-jar
+ "passed a file object for a jar and optionally a list of files expected to be contained within. Asserts that the jar exists and contains every file expected."
+ [jarfile & [expected-files]]
+ (is (.exists jarfile))
+ (when expected-files
+ (let [jarcontents (get-jar-contents jarfile)]
+ (doseq [f expected-files]
+ (is (contains? jarcontents f))))))
+
(deftest jar
- (let [results (cake "jar")
- jarfile (file "test-example-0.1.0-SNAPSHOT.jar")
- jarcontents (into #{}
- (.split (:out (sh "jar" "tf" (.toString jarfile)))
- "\n"))
- expected ["META-INF/cake/test-example/test-example/"
- "META-INF/cake/" "META-INF/MANIFEST.MF"
- "bar.clj"
- "META-INF/maven/test-example/"
- "cake.clj"
- "META-INF/cake/test-example/test-example/project.clj"
- "bar__init.class"
- "baz.clj"
- "META-INF/"
- "bar$inc.class"
- "foo.clj"
- "META-INF/maven/test-example/test-example/"
- "META-INF/maven/"
- "META-INF/maven/test-example/test-example/pom.xml"
- "META-INF/cake/test-example/"
- "bar$foo.class"]]
- (is (.exists jarfile))
- (doseq [f expected]
- (is (contains? jarcontents f)))))
+ (let [jarfile (file "test-example-0.1.0-SNAPSHOT.jar")]
+ (rm jarfile)
+ (cake "jar")
+ (assert-jar jarfile
+ ["META-INF/cake/test-example/test-example/"
+ "META-INF/cake/"
+ "META-INF/MANIFEST.MF"
+ "speak$sayhi.class"
+ "speak.clj"
+ "bar.clj"
+ "META-INF/maven/test-example/"
+ "cake.clj"
+ "META-INF/cake/test-example/test-example/project.clj"
+ "speak__init.class"
+ "baz.clj"
+ "speak$_main.class"
+ "META-INF/"
+ "foo.clj"
+ "META-INF/maven/test-example/test-example/"
+ "META-INF/maven/"
+ "speak.class"
+ "META-INF/maven/test-example/test-example/pom.xml"
+ "META-INF/cake/test-example/"])))
(deftest uberjar
- (let [results (cake "uberjar")
- uberjarfile (file "test-example-0.1.0-SNAPSHOT-standalone.jar")
- uberjarcontents (into #{}
- (.split (:out (sh "jar" "tf"
- (.toString uberjarfile)))
- "\n"))]
+ (cake "uberjar")
+ (let [uberjarfile (file "test-example-0.1.0-SNAPSHOT-standalone.jar")]
+ (assert-jar uberjarfile)
;; this is a bit brittle, but that's the point, the test project should
;; be locked down to specific versions so nothing changes, ever.
- ;; forever ever. -l
- (is (= 2699 (count uberjarcontents)))))
+ ;; forever ever. -lance
+ (is (= 2701 (count (get-jar-contents uberjarfile))))))
+
+(deftest bin
+ (let [binfile (file "test-example")]
+ (rm binfile)
+ (cake "bin")
+ (is (= "hi!\n" (:out (sh (.toString binfile)))))))

0 comments on commit a7b9ede

Please sign in to comment.