|
74 | 74 | :type :failure}))))
|
75 | 75 |
|
76 | 76 | (defmacro is
|
77 |
| - "Assert that expr is true. Must appear inside of a deftest form." |
| 77 | + "Assert that a test condition, `expr`, is true. `is` assertion failures are recorded |
| 78 | + and reported as test failures, causing the entire containing `deftest` to be marked |
| 79 | + as failed. |
| 80 | + |
| 81 | + `expr` can take multiple forms: |
| 82 | + - `(is (= expected actual))` generates a basic assertion that `expected` and `actual` |
| 83 | + are equal by `=`; error messaging will reflect that the first element is the |
| 84 | + expected value and the second element is the actual value |
| 85 | + - `(is (thrown? ExceptionType expr))` generates a basica assertion that `expr` does |
| 86 | + generate an exception of the type `ExceptionType` |
| 87 | + - `(is expr)` is the most basic assertion type that just asserts that `expr` is truthy |
| 88 | + |
| 89 | + `is` assertions must appear inside of a `deftest` form." |
78 | 90 | ([expr]
|
79 | 91 | `(is ~expr (str "Test failure: " (pr-str (quote ~expr)))))
|
80 | 92 | ([expr msg]
|
81 |
| - (let [line-num (:basilisp.lang.reader/line (meta &form))] |
| 93 | + (let [line-num (or (:basilisp.lang.reader/line (meta &form)) |
| 94 | + (:basilisp.lang.reader/line (meta (first &form))))] |
82 | 95 | `(try
|
83 | 96 | ~(gen-assert expr msg line-num)
|
84 | 97 | (catch python/Exception e#
|
|
94 | 107 | :type :error}))))))
|
95 | 108 |
|
96 | 109 | (defmacro are
|
97 |
| - "Assert that expr is true. Must appear inside of a deftest form." |
| 110 | + "Generate assertions using the template expression `expr`. Template expressions |
| 111 | + should be defined in terms of the symbols in the argument vector `argv`. |
| 112 | + |
| 113 | + Arguments will be partitioned into groups of as many arguments are in `argv` |
| 114 | + and applied to the template expression. |
| 115 | + |
| 116 | + As an example: |
| 117 | + |
| 118 | + (are [res x y] (is (= res (+ x y))) |
| 119 | + 3 1 2 |
| 120 | + 4 2 2 |
| 121 | + 0 -1 1) |
| 122 | + |
| 123 | + This would macroexpand to create a group of assertions like this: |
| 124 | + |
| 125 | + (do |
| 126 | + (is (= 3 (+ 1 2))) |
| 127 | + (is (= 4 (+ 2 2))) |
| 128 | + (is (= 0 (+ -1 1)))) |
| 129 | + |
| 130 | + This may be convenient for generating large numbers of identically formed assertions |
| 131 | + with different arguments. |
| 132 | + |
| 133 | + Note that assertions generated with `are` typically lose line numbers in test failure |
| 134 | + reports, due to the nature of the macro generation. |
| 135 | + |
| 136 | + `are` assertions must appear inside of a `deftest` form." |
98 | 137 | [argv expr & args]
|
99 | 138 | `(template/do-template ~argv (is ~expr) ~@args))
|
100 | 139 |
|
101 | 140 | (defmacro testing
|
102 |
| - "Wrapper for test cases to provide additional messaging and context |
103 |
| - around the test or group of tests contained inside. Must appear inside |
104 |
| - of a deftest form." |
| 141 | + "Wrapper for test cases to provide additional messaging and context around the test |
| 142 | + or group of tests contained inside. The value of `msg` will be shown in the report |
| 143 | + with any test failures that occur inside this block. |
| 144 | + |
| 145 | + `testing` macros may be nested. Each nested block message will be appended to the |
| 146 | + message from the previous block. |
| 147 | + |
| 148 | + `testing` forms must appear inside of a `deftest` form." |
105 | 149 | [msg & body]
|
106 | 150 | `(binding [*test-section* (if *test-section*
|
107 | 151 | (str *test-section* " :: " ~msg)
|
108 | 152 | ~msg)]
|
109 | 153 | ~@body))
|
110 | 154 |
|
111 | 155 | (defmacro deftest
|
112 |
| - "Define a new test function. Assertions can be made with the is macro. |
113 |
| - Group tests with the testing macro. |
| 156 | + "Define a new test. |
| 157 | + |
| 158 | + Assertions can be made with the `is` and `are` macros. Group tests with the `testing` |
| 159 | + macro. |
114 | 160 |
|
115 |
| - Tests defined by deftest will be run by default by the PyTest test |
116 |
| - runner using Basilisp's builtin PyTest hook." |
| 161 | + Tests defined by `deftest` will be run by default by the PyTest test runner using |
| 162 | + Basilisp's builtin PyTest hook." |
117 | 163 | [name-sym & body]
|
118 | 164 | (let [test-num (swap! current-test-number inc)
|
119 | 165 | test-name-sym (vary-meta name-sym
|
|
0 commit comments