|
2 | 2 |
|
3 | 3 | ## Helpers |
4 | 4 |
|
5 | | -(defn copy-file |
6 | | - [src-path dst-path] |
7 | | - (def buf-size 4096) |
8 | | - (def buf (buffer/new buf-size)) |
9 | | - (with [src (file/open src-path :rb)] |
10 | | - (with [dst (file/open dst-path :wb)] |
11 | | - (while (def bytes (file/read src buf-size buf)) |
12 | | - (file/write dst bytes) |
13 | | - (buffer/clear buf))))) |
14 | | - |
15 | 5 | (defn- lines-to-stream [lines] |
16 | 6 | (def [r w] (os/pipe)) |
17 | 7 | (:write w lines) |
|
36 | 26 | (:wait x) |
37 | 27 | [(get x :return-code) o e])) |
38 | 28 |
|
39 | | -(defn- expected-version [] |
40 | | - (def info (-> (slurp "info.jdn") parse)) |
41 | | - (def version (get info :version)) |
42 | | - (if (not= "DEVEL" version) |
43 | | - version |
44 | | - (do |
45 | | - (def [r w] (os/pipe)) |
46 | | - (def [ok? _result] |
47 | | - (protect |
48 | | - (os/execute ["git" "describe" "--always" "--dirty"] |
49 | | - :px |
50 | | - {:out w :err w}))) |
51 | | - (:close w) |
52 | | - (if ok? |
53 | | - (string version "-" (string/trim (ev/read r :all))) |
54 | | - version)))) |
| 29 | +(def- test-version "DEVEL-test") |
55 | 30 |
|
56 | 31 | ## Tests |
57 | 32 |
|
|
83 | 58 | (def [exit-code test-out test-err] |
84 | 59 | (shell-capture ["./tmp/predoc" "-v"] stdin)) |
85 | 60 | (is (== 0 exit-code)) |
86 | | - (is (== (string (expected-version) "\n") test-out)) |
| 61 | + (is (== (string test-version "\n") test-out)) |
87 | 62 | (is (== nil test-err))) |
88 | 63 |
|
89 | 64 | (deftest cli-long-version |
90 | 65 | (def [exit-code test-out test-err] |
91 | 66 | (shell-capture ["./tmp/predoc" "--version"] stdin)) |
92 | 67 | (is (== 0 exit-code)) |
93 | | - (is (== (string (expected-version) "\n") test-out)) |
| 68 | + (is (== (string test-version "\n") test-out)) |
94 | 69 | (is (== nil test-err))) |
95 | 70 |
|
96 | 71 | (deftest cli-good-input |
|
122 | 97 | Title: foobar(1) |
123 | 98 | --- |
124 | 99 | ``) |
125 | | - (def output |
126 | | - `` |
127 | | - error: could not parse date in frontmatter |
128 | | - in parse-date [lib/formats/mdoc.janet] on line 133, column 6 |
129 | | - in render-prologue [lib/formats/mdoc.janet] (tail call) on line 433, column 13 |
130 | | - in render-doc [lib/formats/mdoc.janet] (tail call) on line 569, column 5 |
131 | | - in run [lib/cli.janet] (tail call) on line 130, column 21 |
132 | | - ``) |
| 100 | + (def output "error: could not parse date in frontmatter\n") |
133 | 101 | (def [exit-code test-out test-err] |
134 | 102 | (shell-capture ["./tmp/predoc" "--name" "foobar" "--output" "-" "-"] |
135 | 103 | (lines-to-stream input))) |
136 | 104 | (is (== 1 exit-code)) |
137 | 105 | (is (== nil test-out)) |
138 | | - (is (== (string output "\n") test-err))) |
| 106 | + (is (string/has-prefix? output test-err))) |
139 | 107 |
|
140 | 108 | (defer (rmrf "tmp") |
141 | 109 | (os/mkdir "tmp") |
142 | | - (var move? false) |
143 | | - (unless (= :file (os/stat "./predoc" :mode)) |
144 | | - (set move? true) |
145 | | - (print "building ./tmp/predoc...") |
146 | | - (def info (-> (slurp "info.jdn") parse)) |
147 | | - (def bundle (require "../bundle")) |
| 110 | + (print "building ./tmp/predoc...") |
| 111 | + (def info (-> (slurp "info.jdn") parse)) |
| 112 | + (def executable |
| 113 | + (merge (get-in info [:artifacts :executables 0]) {:name "predoc-test"})) |
| 114 | + (def artifacts (merge (get info :artifacts) {:executables [executable]})) |
| 115 | + (def test-info (merge info {:artifacts artifacts})) |
| 116 | + (def bundle (require "../bundle")) |
| 117 | + (def previous-version (os/getenv "PREDOC_BUILD_VERSION")) |
| 118 | + (defer (os/setenv "PREDOC_BUILD_VERSION" previous-version) |
| 119 | + (os/setenv "PREDOC_BUILD_VERSION" test-version) |
148 | 120 | (with-dyns [:out @"" :err @""] |
149 | 121 | (def build (module/value bundle 'build)) |
150 | | - (build {:info info}))) |
151 | | - (if move? |
152 | | - (os/rename "predoc" "tmp/predoc") |
153 | | - (copy-file "predoc" "tmp/predoc")) |
| 122 | + (build {:info test-info}))) |
| 123 | + (os/rename "predoc-test" "tmp/predoc") |
154 | 124 | (os/chmod "tmp/predoc" 8r755) |
155 | 125 | (run-tests!)) |
0 commit comments