Skip to content

Commit 520868d

Browse files
pyrmontcodex
andcommitted
Make executable version tests independent of Git state
Executable tests now build a fresh, separately named binary with a deterministic version. Existing binaries and changes to the checked-out revision can no longer make the expected version stale. The standalone bundler honours PREDOC_BUILD_VERSION so this path needs only Janet and the checked-in build code, without making Jeep a runtime or test dependency. The error test still checks the user-facing message while allowing source positions in the following stack trace to move. Co-Authored-By: Codex GPT 5.6 Sol <codex@openai.com>
1 parent 956767e commit 520868d

2 files changed

Lines changed: 34 additions & 62 deletions

File tree

bundle/init.janet

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@
44
(def- s (get seps (os/which) "/"))
55

66
(defn- build-version [manifest]
7-
(def version (get-in manifest [:info :version]))
8-
(if (not= "DEVEL" version)
9-
version
10-
(do
11-
(def root (get manifest :local-source (os/cwd)))
12-
(def [r w] (os/pipe))
13-
(def [ok? _result]
14-
(protect
15-
(os/execute ["git" "-C" root "describe" "--always" "--dirty"]
16-
:px
17-
{:out w :err w})))
18-
(:close w)
19-
(if ok?
20-
(string version "-" (string/trim (ev/read r :all)))
21-
version))))
7+
(or (os/getenv "PREDOC_BUILD_VERSION")
8+
(do
9+
(def version (get-in manifest [:info :version]))
10+
(if (not= "DEVEL" version)
11+
version
12+
(do
13+
(def root (get manifest :local-source (os/cwd)))
14+
(def [r w] (os/pipe))
15+
(def [ok? _result]
16+
(protect
17+
(os/execute ["git" "-C" root "describe" "--always" "--dirty"]
18+
:px
19+
{:out w :err w})))
20+
(:close w)
21+
(if ok?
22+
(string version "-" (string/trim (ev/read r :all)))
23+
version))))))
2224

2325
(defn build [manifest &]
2426
(def exes (get-in manifest [:info :artifacts :executables] []))

test/executable.janet

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22

33
## Helpers
44

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-
155
(defn- lines-to-stream [lines]
166
(def [r w] (os/pipe))
177
(:write w lines)
@@ -36,22 +26,7 @@
3626
(:wait x)
3727
[(get x :return-code) o e]))
3828

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")
5530

5631
## Tests
5732

@@ -83,14 +58,14 @@
8358
(def [exit-code test-out test-err]
8459
(shell-capture ["./tmp/predoc" "-v"] stdin))
8560
(is (== 0 exit-code))
86-
(is (== (string (expected-version) "\n") test-out))
61+
(is (== (string test-version "\n") test-out))
8762
(is (== nil test-err)))
8863

8964
(deftest cli-long-version
9065
(def [exit-code test-out test-err]
9166
(shell-capture ["./tmp/predoc" "--version"] stdin))
9267
(is (== 0 exit-code))
93-
(is (== (string (expected-version) "\n") test-out))
68+
(is (== (string test-version "\n") test-out))
9469
(is (== nil test-err)))
9570

9671
(deftest cli-good-input
@@ -122,34 +97,29 @@
12297
Title: foobar(1)
12398
---
12499
``)
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")
133101
(def [exit-code test-out test-err]
134102
(shell-capture ["./tmp/predoc" "--name" "foobar" "--output" "-" "-"]
135103
(lines-to-stream input)))
136104
(is (== 1 exit-code))
137105
(is (== nil test-out))
138-
(is (== (string output "\n") test-err)))
106+
(is (string/has-prefix? output test-err)))
139107

140108
(defer (rmrf "tmp")
141109
(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)
148120
(with-dyns [:out @"" :err @""]
149121
(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")
154124
(os/chmod "tmp/predoc" 8r755)
155125
(run-tests!))

0 commit comments

Comments
 (0)