From 0b8b47631efe950df74d17d8f410eb8196342359 Mon Sep 17 00:00:00 2001 From: Aaron Bedra and Stuart Halloway Date: Sun, 23 Aug 2009 14:06:35 -0400 Subject: added adapter test --- src/clojure/contrib/expect/test_adapter.clj | 37 ++++++++++++++++++++++ src/clojure/contrib/expect/test_is_adapter.clj | 37 ---------------------- src/clojure/contrib/test_contrib.clj | 2 +- .../test_contrib/expect_test/test_adapter_test.clj | 18 +++++++++++ 4 files changed, 56 insertions(+), 38 deletions(-) create mode 100644 src/clojure/contrib/expect/test_adapter.clj delete mode 100644 src/clojure/contrib/expect/test_is_adapter.clj create mode 100644 src/clojure/contrib/test_contrib/expect_test/test_adapter_test.clj diff --git a/src/clojure/contrib/expect/test_adapter.clj b/src/clojure/contrib/expect/test_adapter.clj new file mode 100644 index 00000000..50e50125 --- /dev/null +++ b/src/clojure/contrib/expect/test_adapter.clj @@ -0,0 +1,37 @@ +;;; test_adapter.clj: clojure.test adapter for mocking/expectation framework for Clojure + +;; by Matt Clark + +;; Copyright (c) Matt Clark, 2009. 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). +;; 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. + +(ns clojure.contrib.expect.test-adapter + (:require [clojure.contrib.expect :as expect]) + (:use clojure.test + clojure.contrib.ns-utils)) + +(immigrate 'clojure.contrib.expect) + +(defn report-problem + "This function is designed to be used in a binding macro to override +the report-problem function in the test-expect namespace. Instead of printing +the error to the console, the error is logged via test-is." + [fn-name expected actual msg] + (report {:type :fail, + :message (str msg " Function name: " fn-name), + :expected expected, + :actual actual})) + + +(defmacro expect [& body] + "Use this macro instead of the standard test-expect expect macro to have +failures reported through test-is." + `(binding [expect/report-problem report-problem] + (expect/expect ~@body))) + + + diff --git a/src/clojure/contrib/expect/test_is_adapter.clj b/src/clojure/contrib/expect/test_is_adapter.clj deleted file mode 100644 index ebe09773..00000000 --- a/src/clojure/contrib/expect/test_is_adapter.clj +++ /dev/null @@ -1,37 +0,0 @@ -;;; test_is_adapter.clj: test-is adapter for mocking/expectation framework for Clojure - -;; by Matt Clark - -;; Copyright (c) Matt Clark, 2009. 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). -;; 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. - -(ns clojure.contrib.expect.test-is-adapter - (:require [clojure.contrib.expect :as expect]) - (:use clojure.test - clojure.contrib.ns-utils)) - -(immigrate 'clojure.contrib.expect) - -(defn report-problem - "This function is designed to be used in a binding macro to override -the report-problem function in the test-expect namespace. Instead of printing -the error to the console, the error is logged via test-is." - [fn-name expected actual msg] - (report {:type :fail, - :message (str msg " Function name: " fn-name), - :expected expected, - :actual actual})) - - -(defmacro expect [& body] - "Use this macro instead of the standard test-expect expect macro to have -failures reported through test-is." - `(binding [expect/report-problem report-problem] - (expect/expect ~@body))) - - - diff --git a/src/clojure/contrib/test_contrib.clj b/src/clojure/contrib/test_contrib.clj index 9624e987..13498076 100644 --- a/src/clojure/contrib/test_contrib.clj +++ b/src/clojure/contrib/test_contrib.clj @@ -20,7 +20,7 @@ [:complex-numbers :fnmap :macro-utils :monads :pprint.pretty :pprint.cl-format :str-utils :shell-out :test-graph :test-dataflow :test-java-utils :test-lazy-seqs - :test-trace :test-jmx :java-utils :expect-test]) + :test-trace :test-jmx :java-utils :expect-test :expect-test.test-adapter-test]) (def test-namespaces (map #(symbol (str "clojure.contrib.test-contrib." (name %))) diff --git a/src/clojure/contrib/test_contrib/expect_test/test_adapter_test.clj b/src/clojure/contrib/test_contrib/expect_test/test_adapter_test.clj new file mode 100644 index 00000000..c7fceb83 --- /dev/null +++ b/src/clojure/contrib/test_contrib/expect_test/test_adapter_test.clj @@ -0,0 +1,18 @@ +(ns clojure.contrib.test-contrib.expect-test.test-adapter-test + (:use clojure.contrib.expect.test-adapter + [clojure.contrib.test-contrib.expect-test.util :only (assert-called)] + clojure.test)) + +(deftest test-report-problem-called + (def #^{:private true} fn1 (fn [x] "dummy code")) + (def #^{:private true} fn2 (fn [x y] "dummy code2")) + (let [under-test (fn [x] (fn1 x))] + (assert-called clojure.contrib.expect.test-adapter/report-problem + true (expect [fn1 (times 5)] (under-test "hi"))))) + +(deftest test-is-report-called + (assert-called clojure.test/report true + (clojure.contrib.expect.test-adapter/report-problem + 'fn-name 5 6 "fake problem"))) + + -- cgit v1.2.3-18-g5258