Created
September 6, 2011 14:07
-
-
Save eungju/1197621 to your computer and use it in GitHub Desktop.
stdio test runner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns markup.test | |
(:use (clojure.java shell))) | |
(defn run-test [name input expected dut] | |
(let [actual (:out (sh dut :in input))] | |
(if (= actual expected) | |
:pass | |
:fail))) | |
(defn print-plan [tests] | |
(printf "%d..%d\n" 1 (count tests))) | |
(defn print-result [result number] | |
(if (= (:result result) :pass) | |
(printf "\033[1;32mok %d - %s\033[0m\n" number (:name result)) | |
(printf "\033[1;31mnot ok %d - %s\033[0m\n" number (:name result))) | |
(flush)) | |
(defn run-tests | |
([dut tests results] | |
(if (empty? tests) | |
(reverse results) | |
(let [name (first tests) | |
input (slurp (str name ".in")) | |
expected (slurp (str name ".out")) | |
result {:name name :result (run-test name input expected dut)}] | |
(print-result result (inc (count results))) | |
(recur dut (rest tests) (cons result results))))) | |
([dut tests] | |
(print-plan tests) | |
(run-tests dut tests []))) | |
(defn -main [& args] | |
(run-tests (first *command-line-args*) | |
["markdown-empty-document" | |
"markdown-single-line-paragraph"]) | |
(System/exit 0)) | |
(apply -main *command-line-args*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment