Skip to content

Commit 9bf0650

Browse files
committed
Update links in API document
1 parent 9c87b98 commit 9bf0650

3 files changed

Lines changed: 145 additions & 34 deletions

File tree

api.md

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# testament API
22

3-
43
[==](#), [assert-deep-equal](#assert-deep-equal), [assert-equal](#assert-equal), [assert-equivalent](#assert-equivalent), [assert-expr](#assert-expr), [assert-matches](#assert-matches), [assert-thrown](#assert-thrown), [assert-thrown-message](#assert-thrown-message), [deftest](#deftest), [each-is](#each-is), [exercise!](#exercise), [is](#is), [reset-all!](#reset-all), [reset-tests!](#reset-tests), [review](#review), [run-tests!](#run-tests), [set-on-result-hook](#set-on-result-hook), [set-report-printer](#set-report-printer), [set-results-printer](#set-results-printer)
54

65
## ==
@@ -23,6 +22,7 @@ function.
2322

2423
[1]: lib/testament.janet#L62
2524

25+
2626
## assert-deep-equal
2727

2828
**macro** | [source][2]
@@ -41,7 +41,8 @@ An optional `note` can be included that will be used in any failure result to
4141
identify the assertion. If no `note` is provided, the form
4242
`(deep= expect actual)` is used.
4343

44-
[2]: lib/testament.janet#L460
44+
[2]: lib/testament.janet#L693
45+
4546

4647
## assert-equal
4748

@@ -61,7 +62,8 @@ An optional `note` can be included that will be used in any failure result to
6162
identify the assertion. If no `note` is provided, the form `(= expect actual)`
6263
is used.
6364

64-
[3]: lib/testament.janet#L444
65+
[3]: lib/testament.janet#L677
66+
6567

6668
## assert-equivalent
6769

@@ -84,7 +86,8 @@ An optional `note` can be included that will be used in any failure result to
8486
identify the assertion. If no `note` is provided, the form `(== expect actual)`
8587
is used.
8688

87-
[4]: lib/testament.janet#L476
89+
[4]: lib/testament.janet#L709
90+
8891

8992
## assert-expr
9093

@@ -101,7 +104,8 @@ The `assert-expr` macro provides a mechanism for creating a generic assertion.
101104
An optional `note` can be included that will be used in any failure result to
102105
identify the assertion. If no `note` is provided, the form of `expr` is used.
103106

104-
[5]: lib/testament.janet#L431
107+
[5]: lib/testament.janet#L664
108+
105109

106110
## assert-matches
107111

@@ -120,7 +124,8 @@ An optional `note` can be included that will be used in any failure result to
120124
identify the assertion. If no `note` is provided, the form
121125
`(matches structure actual)` is used.
122126

123-
[6]: lib/testament.janet#L495
127+
[6]: lib/testament.janet#L728
128+
124129

125130
## assert-thrown
126131

@@ -139,7 +144,8 @@ An optional `note` can be included that will be used in any failure result to
139144
identify the assertion. If no `note` is provided, the form `thrown? expr` is
140145
used.
141146

142-
[7]: lib/testament.janet#L510
147+
[7]: lib/testament.janet#L743
148+
143149

144150
## assert-thrown-message
145151

@@ -159,7 +165,8 @@ An optional `note` can be included that will be used in any failure result to
159165
identify the assertion. If no `note` is provided, the form
160166
`thrown? expect expr` is used.
161167

162-
[8]: lib/testament.janet#L526
168+
[8]: lib/testament.janet#L759
169+
163170

164171
## deftest
165172

@@ -196,7 +203,8 @@ test is called is not guaranteed.
196203
If `deftest` is called with no arguments or if the only argument is a symbol,
197204
an arity error is raised.
198205

199-
[9]: lib/testament.janet#L657
206+
[9]: lib/testament.janet#L890
207+
200208

201209
## each-is
202210

@@ -210,7 +218,8 @@ Asserts that each element in `assertions` is true (with an optional `note`)
210218

211219
This effectively calls `is` on each element in `assertions` using the optional note.
212220

213-
[10]: lib/testament.janet#L607
221+
[10]: lib/testament.janet#L840
222+
214223

215224
## exercise!
216225

@@ -232,7 +241,8 @@ tuple.
232241
Please note that, like `run-tests!`, `exercise!` calls `os/exit` when there
233242
are failing tests unless the argument `:no-exit?` is set to `true`.
234243

235-
[11]: lib/testament.janet#L775
244+
[11]: lib/testament.janet#L1008
245+
236246

237247
## is
238248

@@ -266,7 +276,8 @@ asserted expression.
266276
An optional `note` can be included that will be used in any failure result to
267277
identify the assertion.
268278

269-
[12]: lib/testament.janet#L546
279+
[12]: lib/testament.janet#L779
280+
270281

271282
## reset-all!
272283

@@ -278,7 +289,8 @@ identify the assertion.
278289

279290
Resets all reporting variables and settings
280291

281-
[13]: lib/testament.janet#L643
292+
[13]: lib/testament.janet#L876
293+
282294

283295
## reset-tests!
284296

@@ -290,7 +302,8 @@ Resets all reporting variables and settings
290302

291303
Resets all reporting variables
292304

293-
[14]: lib/testament.janet#L629
305+
[14]: lib/testament.janet#L862
306+
294307

295308
## review
296309

@@ -307,7 +320,8 @@ the bindings as public. This is intended for situations where it is not
307320
desirable to make bindings public but the user would still like to be able to
308321
subject the bindings to testing.
309322

310-
[15]: lib/testament.janet#L821
323+
[15]: lib/testament.janet#L1054
324+
311325

312326
## run-tests!
313327

@@ -348,7 +362,8 @@ Finally, if the dynamic binding `:testament/repl?` is set to `true`, this
348362
will also reset the test reports and empty the module/cache to provide a
349363
fresh run with the most up-to-date code.
350364

351-
[16]: lib/testament.janet#L712
365+
[16]: lib/testament.janet#L945
366+
352367

353368
## set-on-result-hook
354369

@@ -380,7 +395,8 @@ The 'value' of the assertion depends on the kind of assertion:
380395
- `:thrown` either `true` or `false`; and
381396
- `:thrown-message` the error specified in the assertion.
382397

383-
[17]: lib/testament.janet#L211
398+
[17]: lib/testament.janet#L444
399+
384400

385401
## set-report-printer
386402

@@ -404,6 +420,7 @@ to `true`.
404420

405421
[18]: lib/testament.janet#L80
406422

423+
407424
## set-results-printer
408425

409426
**function** | [source][19]

bundle.janet

Lines changed: 108 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,109 @@
1+
(def- seps {:windows "\\" :mingw "\\" :cygwin "\\"})
2+
(def- s (get seps (os/which) "/"))
3+
4+
# used for splitting POSIX paths
5+
(def- posix-pathg ~{:main (* (+ :abspath :relpath) (? :sep) -1)
6+
:abspath (* :root (any :relpath))
7+
:relpath (* :part (any (* :sep :part)))
8+
:root (* "/" (constant ""))
9+
:sep (some "/")
10+
:part '(some (* (! :sep) 1))})
11+
12+
# based on code from spork/declare-cc.janet
13+
(defn- add-bat-shim [manifest bin-name &opt chmod-mode]
14+
(def binpath (string (dyn :syspath) s "bin"))
15+
(def bin-dest (string binpath s bin-name))
16+
(assert (= :file (os/stat bin-dest :mode)) "must call bundle/add-bin first")
17+
(def bat-name (string bin-name ".bat"))
18+
(def files (get manifest :files)) # guaranteed to be non-nil
19+
(def dest (string binpath s bat-name))
20+
(when (os/stat dest :mode)
21+
(errorf "collision at %s, file already exists" dest))
22+
(def bat (string "@echo off\r\n"
23+
"goto #_undefined_# 2>NUL || title %COMSPEC% & janet \""
24+
bin-dest
25+
"\" %*"))
26+
(spit dest bat)
27+
(def absdest (os/realpath dest))
28+
(array/push files absdest)
29+
(when chmod-mode
30+
(os/chmod absdest chmod-mode))
31+
(print "add " absdest))
32+
33+
(defn- split-posix-path [path]
34+
(peg/match posix-pathg path))
35+
36+
(defn- add-path [paths dest &opt src]
37+
(def bits (split-posix-path dest))
38+
(assert bits "invalid path")
39+
(def ks @[])
40+
(each b bits
41+
(array/push ks b)
42+
(unless (get-in paths ks)
43+
(put-in paths ks @{})))
44+
(when src
45+
(put-in paths ks (-> (split-posix-path src)
46+
(string/join s)))))
47+
48+
(defn- install-libs [manifest &]
49+
(def to-make @{})
50+
(def libs (get-in manifest [:info :artifacts :libraries] []))
51+
(each lib libs
52+
(def ks @[])
53+
(def prefix (get lib :prefix))
54+
(when prefix (add-path to-make prefix))
55+
(def paths (get lib :paths))
56+
(each p paths
57+
# use POSIX path separator to match info file
58+
(add-path to-make (string (when prefix (string prefix "/")) p) p)))
59+
(defn add-tree [tree path]
60+
(eachp [k v] tree
61+
(if (table? v)
62+
(do
63+
(def new-path (if (empty? path) k (string path s k)))
64+
(bundle/add-directory manifest new-path)
65+
(add-tree v new-path))
66+
(bundle/add manifest v (string path s k)))))
67+
(add-tree to-make ""))
68+
69+
(defn- install-mans [manifest &]
70+
(def mans (get-in manifest [:info :artifacts :manpages] []))
71+
(each m mans
72+
(def bits (split-posix-path m))
73+
(var dir (dyn :syspath))
74+
(each b (array/slice bits 0 -2)
75+
(set dir (string dir s b))
76+
(os/mkdir dir))
77+
(bundle/add-file manifest (string/join bits s))))
78+
79+
(defn- install-scrs [manifest &]
80+
(def scrs (get-in manifest [:info :artifacts :scripts] []))
81+
(each scr scrs
82+
(def path (-> (get scr :path)
83+
(split-posix-path)
84+
(string/join s)))
85+
(bundle/add-bin manifest path)
86+
(when (= "\\" s)
87+
(def bin-name (last (string/split s path)))
88+
(add-bat-shim manifest bin-name))))
89+
90+
(defn- set-version [manifest]
91+
(def bundle-ver (get-in manifest [:info :version]))
92+
(if (not= "DEVEL" bundle-ver)
93+
(put manifest :version bundle-ver)
94+
(do
95+
(def src (get manifest :local-source))
96+
(def [r w] (os/pipe))
97+
(def [ok? res] (protect (os/execute ["git" "-C" src "describe" "--always" "--dirty"] :px {:out w :err w})))
98+
(:close w)
99+
(put manifest
100+
:version
101+
(if ok?
102+
(string bundle-ver "-" (string/trim (ev/read r :all)))
103+
bundle-ver)))))
104+
1105
(defn install [manifest &]
2-
(def seps {:windows "\\" :mingw "\\" :cygwin "\\"})
3-
(def s (get seps (os/which) "/"))
4-
(def manpages (get-in manifest [:info :manpage] []))
5-
(os/mkdir (string (dyn :syspath) s "man"))
6-
(os/mkdir (string (dyn :syspath) s "man" s "man1"))
7-
(each mp manpages
8-
(bundle/add-file manifest mp))
9-
(def prefix (get-in manifest [:info :source :prefix]))
10-
(def srcs (get-in manifest [:info :source :files] []))
11-
(bundle/add-directory manifest prefix)
12-
(each src srcs
13-
(bundle/add manifest src (string prefix s src)))
14-
(def bins (get-in manifest [:info :executable] []))
15-
(each bin bins
16-
(bundle/add-bin manifest bin)))
106+
(install-libs manifest)
107+
(install-mans manifest)
108+
(install-scrs manifest)
109+
(set-version manifest))

info.jdn

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
:url "https://github.com/pyrmont/testament"
77
:repo "git+https://github.com/pyrmont/testament"
88

9-
:source {:prefix "testament"
10-
:files ["lib" "init.janet"]}}
9+
:artifacts {:libraries [{:prefix "testament"
10+
:paths ["lib"
11+
"init.janet"]}]}}

0 commit comments

Comments
 (0)