Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to tweak the output of clojure.test?

I have this test:

(ns opengltuts.core-test
  (:use clojure.test
        opengltuts.util)
  (:import (org.lwjgl.opengl
             GL11 GL12 GL13 GL14 GL15 GL20 GL21 GL30 GL31 GL32 GL33)))

(def gl-classes [GL11 GL12 GL13 GL14 GL15 GL20 GL21 GL30 GL31 GL32 GL33])

(deftest find-method-test
  (testing "find-method finds method in single class"
    (is (= (find-method "toString" Object)
           ["public java.lang.String java.lang.Object.toString()"])))
  (testing "find-method finds all methods in list of classes"
    (is (= (apply find-method "glShaderSource" gl-classes)
           (comment "Omitted a 'p' to trigger failure")
           ["ublic static void org.lwjgl.opengl.GL20.glShaderSource(int,java.nio.ByteBuffer)"
            "public static void org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence)"
            "public static void org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence[])"]))))

Now I made sure this fails, I get output like

lein test opengltuts.core-test

FAIL in (find-method-test) (core_test.clj:14)
find-method finds all methods in list of classes
expected: (= (apply find-method "glShaderSource" gl-classes) ["ublic static void 
org.lwjgl.opengl.GL20.glShaderSource(int,java.nio.ByteBuffer)" "public static void 
org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence)" "public static void 
org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence[])"])
      actual: (not (= ("public static void org.lwjgl.opengl.GL20.glShaderSource(int,java.nio.ByteBuffer)" "public static void 
org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence)" "public static void 
org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence[])") ["ublic static void 
org.lwjgl.opengl.GL20.glShaderSource(int,java.nio.ByteBuffer)" "public static void 
org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence)" "public static void 
org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence[])"]))

Ran 1 tests containing 2 assertions.
1 failures, 0 errors.
Tests failed.

I find this fairly unreadable. Rather than that, I would prefer output like:

<all that info stuff, like the name of the test>
Expected: [something]
Got: [something-else]

As is, I have troubles just figuring out what I was comparing with what.

like image 713
Cubic Avatar asked Oct 08 '12 18:10

Cubic


2 Answers

clojure.test's reporting is configurable by rebinding the clojure.test/report function. This is described in the docs for the namespace. Your function will be called with a succession of event maps, each representing some phase of the test run. There's an example of generating JUnit-compatible output in the clojure.test source here.

like image 188
Dave Ray Avatar answered Sep 20 '22 02:09

Dave Ray


There are several popular testing frameworks for Clojure, clojure.test (which you are using) is popular though Midje looks like it's output is closer to what you're looking for. Here is an example test failure:

FAIL at (t_core.clj:13)
    Expected: "I am a test file fact"
      Actual: 3

https://github.com/marick/Midje/wiki/Migrating-from-clojure.test

like image 34
Arthur Ulfeldt Avatar answered Sep 22 '22 02:09

Arthur Ulfeldt