summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Faulhaber <git_com@infolace.com>2010-11-04 21:22:46 -0700
committerStuart Halloway <stu@thinkrelevance.com>2010-12-17 17:08:46 -0500
commitafe9d402684f8a8a675b90591621387bb55c0fd4 (patch)
treeb17d76cf519991727d629dcb9482a3c4e324fd78
parentc7c7c01edd7e88fc41a5bf644fa8f9b67cc9cb11 (diff)
Update tests to recogize appropriate newlines for the platform that they're on.
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r--test/clojure/test_clojure/java/io.clj5
-rw-r--r--test/clojure/test_clojure/main.clj9
-rw-r--r--test/clojure/test_clojure/pprint.clj1
-rw-r--r--test/clojure/test_clojure/pprint/test_cl_format.clj13
-rw-r--r--test/clojure/test_clojure/pprint/test_helper.clj12
-rw-r--r--test/clojure/test_clojure/pprint/test_pretty.clj18
-rw-r--r--test/clojure/test_clojure/repl.clj5
-rw-r--r--test/clojure/test_helper.clj21
8 files changed, 54 insertions, 30 deletions
diff --git a/test/clojure/test_clojure/java/io.clj b/test/clojure/test_clojure/java/io.clj
index eaaf7891..1e533d72 100644
--- a/test/clojure/test_clojure/java/io.clj
+++ b/test/clojure/test_clojure/java/io.clj
@@ -7,7 +7,8 @@
; You must not remove this notice, or any other, from this software.
(ns clojure.test-clojure.java.io
- (:use clojure.test clojure.java.io)
+ (:use clojure.test clojure.java.io
+ [clojure.test-helper :only [platform-newlines]])
(:import (java.io File BufferedInputStream
FileInputStream InputStreamReader InputStream
FileOutputStream OutputStreamWriter OutputStream
@@ -27,7 +28,7 @@
(is (= "foobar" (slurp f :encoding "UTF-16")))
(testing "deprecated arity"
(is (=
- "WARNING: (slurp f enc) is deprecated, use (slurp f :encoding enc).\n"
+ (platform-newlines "WARNING: (slurp f enc) is deprecated, use (slurp f :encoding enc).\n")
(with-out-str
(is (= "foobar" (slurp f "UTF-16")))))))))
diff --git a/test/clojure/test_clojure/main.clj b/test/clojure/test_clojure/main.clj
index edcf7a2e..039a200d 100644
--- a/test/clojure/test_clojure/main.clj
+++ b/test/clojure/test_clojure/main.clj
@@ -10,19 +10,20 @@
(ns clojure.test-clojure.main
- (:use clojure.test)
+ (:use clojure.test
+ [clojure.test-helper :only [platform-newlines]])
(:require [clojure.main :as main]))
(deftest eval-opt
(testing "evals and prints forms"
- (is (= "2\n4\n" (with-out-str (#'clojure.main/eval-opt "(+ 1 1) (+ 2 2)")))))
+ (is (= (platform-newlines "2\n4\n") (with-out-str (#'clojure.main/eval-opt "(+ 1 1) (+ 2 2)")))))
(testing "skips printing nils"
- (is (= ":a\n:c\n" (with-out-str (#'clojure.main/eval-opt ":a nil :c")))))
+ (is (= (platform-newlines ":a\n:c\n") (with-out-str (#'clojure.main/eval-opt ":a nil :c")))))
(testing "does not block access to *in* (#299)"
(with-in-str "(+ 1 1)"
- (is (= "(+ 1 1)\n" (with-out-str (#'clojure.main/eval-opt "(read)")))))))
+ (is (= (platform-newlines "(+ 1 1)\n") (with-out-str (#'clojure.main/eval-opt "(read)")))))))
(defmacro with-err-str
"Evaluates exprs in a context in which *err* is bound to a fresh
diff --git a/test/clojure/test_clojure/pprint.clj b/test/clojure/test_clojure/pprint.clj
index 221236fe..066d1b5d 100644
--- a/test/clojure/test_clojure/pprint.clj
+++ b/test/clojure/test_clojure/pprint.clj
@@ -11,6 +11,7 @@
(ns clojure.test-clojure.pprint
(:refer-clojure :exclude [format])
(:use [clojure.test :only (deftest are run-tests)]
+ [clojure.test-helper :only [platform-newlines]]
clojure.test-clojure.pprint.test-helper
clojure.pprint))
diff --git a/test/clojure/test_clojure/pprint/test_cl_format.clj b/test/clojure/test_clojure/pprint/test_cl_format.clj
index c8fdf18d..95b324d1 100644
--- a/test/clojure/test_clojure/pprint/test_cl_format.clj
+++ b/test/clojure/test_clojure/pprint/test_cl_format.clj
@@ -48,12 +48,7 @@
(binding [*print-radix* true ;print the integer 10 and
*print-base* pb] ;the ratio 1/10 in bases 2,
(cl-format true "~&~S ~S~%" 10 1/10)))) ;3, 8, 10, 16
- "#b1010 #b1/1010
-#3r101 #3r1/101
-#o12 #o1/12
-10. #10r1/10
-#xa #x1/a
-")
+ "#b1010 #b1/1010\n#3r101 #3r1/101\n#o12 #o1/12\n10. #10r1/10\n#xa #x1/a\n")
@@ -222,11 +217,11 @@
"The quick brown elephant jumped over 5 lazy dogs"
(cl-format nil "The quick brown ~&~a jumped over ~d lazy dogs" 'elephant 5)
"The quick brown \nelephant jumped over 5 lazy dogs"
- (cl-format nil "The quick brown ~&~a jumped\n~& over ~d lazy dogs" 'elephant 5)
+ (cl-format nil (platform-newlines "The quick brown ~&~a jumped\n~& over ~d lazy dogs") 'elephant 5)
"The quick brown \nelephant jumped\n over 5 lazy dogs"
- (cl-format nil "~&The quick brown ~&~a jumped\n~& over ~d lazy dogs" 'elephant 5)
+ (cl-format nil (platform-newlines "~&The quick brown ~&~a jumped\n~& over ~d lazy dogs") 'elephant 5)
"The quick brown \nelephant jumped\n over 5 lazy dogs"
- (cl-format nil "~3&The quick brown ~&~a jumped\n~& over ~d lazy dogs" 'elephant 5)
+ (cl-format nil (platform-newlines "~3&The quick brown ~&~a jumped\n~& over ~d lazy dogs") 'elephant 5)
"\n\nThe quick brown \nelephant jumped\n over 5 lazy dogs"
(cl-format nil "~@{~&The quick brown ~a jumped over ~d lazy dogs~}" 'elephant 5 'fox 10)
"The quick brown elephant jumped over 5 lazy dogs\nThe quick brown fox jumped over 10 lazy dogs"
diff --git a/test/clojure/test_clojure/pprint/test_helper.clj b/test/clojure/test_clojure/pprint/test_helper.clj
index b59be6bb..a7edd74e 100644
--- a/test/clojure/test_clojure/pprint/test_helper.clj
+++ b/test/clojure/test_clojure/pprint/test_helper.clj
@@ -15,13 +15,17 @@
;; This is just a macro to make my tests a little cleaner
(ns clojure.test-clojure.pprint.test-helper
- (:use [clojure.test :only (deftest is)]))
+ (:use [clojure.test :only (deftest is)]
+ [clojure.test-helper :only [platform-newlines]]))
(defn- back-match [x y] (re-matches y x))
+
(defmacro simple-tests [name & test-pairs]
`(deftest ~name
~@(for [[x y] (partition 2 test-pairs)]
- (if (instance? java.util.regex.Pattern y)
- `(is (#'clojure.test-clojure.pprint.test-helper/back-match ~x ~y))
- `(is (= ~x ~y))))))
+ (cond
+ (instance? java.util.regex.Pattern y)
+ `(is (#'clojure.test-clojure.pprint.test-helper/back-match ~x ~y))
+ (instance? java.lang.String y) `(is (= ~x (platform-newlines ~y)))
+ :else `(is (= ~x ~y))))))
diff --git a/test/clojure/test_clojure/pprint/test_pretty.clj b/test/clojure/test_clojure/pprint/test_pretty.clj
index 93edab79..ebbb29a1 100644
--- a/test/clojure/test_clojure/pprint/test_pretty.clj
+++ b/test/clojure/test_clojure/pprint/test_pretty.clj
@@ -224,16 +224,16 @@ Usage: *hello*
(defrecord pprint-test-rec [a b c])
(simple-tests pprint-datastructures-tests
- (tst-pprint 20 future-filled) #"#<Future@[0-9a-f]+: \n 100>"
- (tst-pprint 20 future-unfilled) #"#<Future@[0-9a-f]+: \n :pending>"
- (tst-pprint 20 promise-filled) #"#<Promise@[0-9a-f]+: \n \(first\n second\n third\)>"
+ (tst-pprint 20 future-filled) #"#<Future@[0-9a-f]+: \r?\n 100>"
+ (tst-pprint 20 future-unfilled) #"#<Future@[0-9a-f]+: \r?\n :pending>"
+ (tst-pprint 20 promise-filled) #"#<Promise@[0-9a-f]+: \r?\n \(first\r?\n second\r?\n third\)>"
;; This hangs currently, cause we can't figure out whether a promise is filled
- ;;(tst-pprint 20 promise-unfilled) #"#<Promise@[0-9a-f]+: \n :pending>"
- (tst-pprint 20 basic-agent) #"#<Agent@[0-9a-f]+: \n \(first\n second\n third\)>"
- (tst-pprint 20 (failed-agent)) #"#<Agent@[0-9a-f]+ FAILED: \n \"foo\">"
- (tst-pprint 20 basic-atom) #"#<Atom@[0-9a-f]+: \n \(first\n second\n third\)>"
- (tst-pprint 20 basic-ref) #"#<Ref@[0-9a-f]+: \n \(first\n second\n third\)>"
- (tst-pprint 20 delay-forced) #"#<Delay@[0-9a-f]+: \n \(first\n second\n third\)>"
+ ;;(tst-pprint 20 promise-unfilled) #"#<Promise@[0-9a-f]+: \r?\n :pending>"
+ (tst-pprint 20 basic-agent) #"#<Agent@[0-9a-f]+: \r?\n \(first\r?\n second\r?\n third\)>"
+ (tst-pprint 20 (failed-agent)) #"#<Agent@[0-9a-f]+ FAILED: \r?\n \"foo\">"
+ (tst-pprint 20 basic-atom) #"#<Atom@[0-9a-f]+: \r?\n \(first\r?\n second\r?\n third\r?\)>"
+ (tst-pprint 20 basic-ref) #"#<Ref@[0-9a-f]+: \r?\n \(first\r?\n second\r?\n third\)>"
+ (tst-pprint 20 delay-forced) #"#<Delay@[0-9a-f]+: \r?\n \(first\r?\n second\r?\n third\)>"
;; Currently no way not to force the delay
;;(tst-pprint 20 delay-unforced) #"#<Delay@[0-9a-f]+: \n :pending>"
(tst-pprint 20 (pprint-test-rec. 'first 'second 'third)) "{:a first,\n :b second,\n :c third}"
diff --git a/test/clojure/test_clojure/repl.clj b/test/clojure/test_clojure/repl.clj
index 1f7a147a..8921c2cd 100644
--- a/test/clojure/test_clojure/repl.clj
+++ b/test/clojure/test_clojure/repl.clj
@@ -1,17 +1,18 @@
(ns clojure.test-clojure.repl
(:use clojure.test
clojure.repl
+ [clojure.test-helper :only [platform-newlines]]
clojure.test-clojure.repl.example))
(deftest test-source
(is (= "(defn foo [])" (source-fn 'clojure.test-clojure.repl.example/foo)))
- (is (= "(defn foo [])\n" (with-out-str (source clojure.test-clojure.repl.example/foo))))
+ (is (= (platform-newlines "(defn foo [])\n") (with-out-str (source clojure.test-clojure.repl.example/foo))))
(is (nil? (source-fn 'non-existent-fn))))
(deftest test-dir
(is (thrown? Exception (dir-fn 'non-existent-ns)))
(is (= '[bar foo] (dir-fn 'clojure.test-clojure.repl.example)))
- (is (= "bar\nfoo\n" (with-out-str (dir clojure.test-clojure.repl.example)))))
+ (is (= (platform-newlines "bar\nfoo\n") (with-out-str (dir clojure.test-clojure.repl.example)))))
(deftest test-apropos
(testing "with a regular expression"
diff --git a/test/clojure/test_helper.clj b/test/clojure/test_helper.clj
new file mode 100644
index 00000000..7e7cfb55
--- /dev/null
+++ b/test/clojure/test_helper.clj
@@ -0,0 +1,21 @@
+; Copyright (c) Rich Hickey. All rights reserved.
+; The use and distribution terms for this software are covered by the
+; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+; which can be found in the file epl-v10.html at the root of this distribution.
+; By using this software in any fashion, you are agreeing to be bound by
+; the terms of this license.
+; You must not remove this notice, or any other, from this software.
+;
+
+;; clojure.test-helper
+;;
+;; Utility functions shared by various tests in the Clojure
+;; test suite
+;;
+;; tomfaulhaber (gmail)
+;; Created 04 November 2010
+
+(ns clojure.test-helper)
+
+(let [nl (System/getProperty "line.separator")]
+ (defn platform-newlines [s] (.replace s "\n" nl)))