Yesterday I finished writing the bare minimum of the testing library. I want to be able to run it from the command line. Never mind if most development happens in the REPL; I just want to run it on the command line.
So the first thing that I need is to read the arguments from the command line. I found the solution on the clojure documentation. The solution is to use *command-line-args* var to get them.
The next thing that I needed was to read a file. I found the solution on this thread in stackoverflow on reading a file in clojure. Reading through the list, it seems that using slurp is the easiest solution. So that is what I am going to do.
Now I need to evaluate a string that I just read. For that we use eval. I still did a search and found the following on evaluating a string in clojure. So on this one I decided to use load-string. As they are read, they will run the tests. Then I hand execution to my run-specky function, which is the function that will output a report from my tests.
This is how the description above looks in code.
(ns spec
(:use specky))
(run-specky
(load-string
(slurp (first *command-line-args*)))
And this is what the test file looked like:
(qtest “first test” (ok true))
(qtest “second test” (ok false))
(qtest “fourth test” (ok false))
And this is the output
1 tests. 0 passed. 1 failed.
‘first test’ failed. Expected true. Actual: false.
Success… wait, what? Damn. There goes that bug I ran into yesterday. I will investigate it tomorrow.