1
+ (use ../spork/test )
2
+ (import ../spork/pm )
3
+ (import ../spork/pm-config )
4
+ (import ../spork/sh )
5
+ (import ../spork/path )
6
+
7
+ (start-suite )
8
+
9
+ (assert true ) # smoke test
10
+
11
+ # Copy since not exposed in boot.janet
12
+ (defn- bundle-rpath
13
+ [path ]
14
+ (string/replace-all " \\ " " /" (os/realpath path )))
15
+
16
+ (defn randdir
17
+ " Get a random directory name"
18
+ []
19
+ (string (os/cwd ) " /tmp/tmp_dir_" (slice (string (math/random ) " .tmp" ) 2 )))
20
+
21
+ (defn count-match
22
+ " Count number of occurrence of pat in str"
23
+ [pat str ]
24
+ (length (string/find-all pat str )))
25
+
26
+ (defn after?
27
+ " Verify pat2 occurs after pat1 in str"
28
+ [pat2 pat1 str ]
29
+ (let [f1 (string/find pat1 str )
30
+ f2 (string/find pat2 str )]
31
+ (> f2 f1 )))
32
+
33
+ (defn divider [title ]
34
+ (printf " ------------------------------------------\n %s" title ))
35
+
36
+ (defn dump-out [output ]
37
+ (let [out (string/split " \n " (output :out ))
38
+ err (string/split " \n " (output :err ))]
39
+ (when (> (length out ) 0 )
40
+ (each line out
41
+ (printf line )))
42
+ (when (> (length err ) 0 )
43
+ (each line err
44
+ (printf line )))))
45
+
46
+ # Create a temporary directory for our janet tree
47
+ (math/seedrandom (os/cryptorand 16 ))
48
+ (def syspath (randdir ))
49
+ (sh/rm syspath )
50
+ (os/mkdir " tmp" )
51
+ (assert (os/mkdir syspath ))
52
+ (pm-config/read-env-variables root-env )
53
+ (put root-env :build-dir nil ) # jpm test sets this and it messes things up
54
+ (defer (sh/rm " tmp" )
55
+ (put root-env *syspath* (bundle-rpath syspath ))
56
+ (put root-env :binpath (string syspath " /bin" ))
57
+ (put root-env :manpath (string syspath " /man" ))
58
+ (unless (os/getenv " VERBOSE" )
59
+ (setdyn *out* @" " ))
60
+ (assert (empty? (bundle/list )) " initial bundle/list" )
61
+ (assert (empty? (bundle/topolist )) " initial bundle/topolist" )
62
+
63
+ # install spork
64
+ (pm/pm-install " file::." )
65
+ (assert (= 1 (length (bundle/list ))) " bundle/list after install" )
66
+
67
+ # make sure the right janet-pm is found
68
+ (def binpath (path/join (dyn *syspath* ) " bin" ))
69
+ (def janet-pm (path/join binpath (string " janet-pm" (if (= (os/which ) :windows ) " .exe" " " ))))
70
+ (assert (sh/exists? janet-pm ))
71
+
72
+ (os/cd " test-project" )
73
+
74
+ # run janet-pm commands and collect output
75
+
76
+ # check "build"
77
+ (divider " Running janet-pm build" )
78
+ (def build-out (sh/exec-slurp-all janet-pm " build" ))
79
+ (dump-out build-out )
80
+ (assert (= 1 (count-match " ** pre-build" (build-out :out ))))
81
+ (assert (= 1 (count-match " ** post-build" (build-out :out ))))
82
+ (assert (= 0 (count-match " ** pre-install" (build-out :out ))))
83
+
84
+ # check "install"
85
+ (divider " Running janet-pm install" )
86
+ (def install-out (sh/exec-slurp-all janet-pm " install" ))
87
+ (dump-out install-out )
88
+ # verify proper entries only occur once
89
+ (assert (= 1 (count-match " ** pre-build" (install-out :out ))))
90
+ (assert (= 1 (count-match " ** post-build" (install-out :out ))))
91
+ (assert (= 1 (count-match " ** pre-install" (install-out :out ))))
92
+ (assert (= 1 (count-match " ** post-install" (install-out :out ))))
93
+ (assert (= 0 (count-match " ** pre-check" (install-out :out ))))
94
+ (assert (= 0 (count-match " ** post-check" (install-out :out ))))
95
+
96
+ # verify order of entries
97
+ (assert (after? " post-build" " pre-build" (install-out :out )))
98
+ (assert (after? " pre-install" " post-build" (install-out :out )))
99
+ (assert (after? " post-install" " pre-install" (install-out :out )))
100
+
101
+ # check "test"
102
+ (divider " Running janet-pm test" )
103
+ (def test-out (sh/exec-slurp-all janet-pm " test" ))
104
+ (dump-out test-out )
105
+ # verify proper entries only occur once
106
+ (assert (= 1 (count-match " ** pre-build" (test-out :out ))))
107
+ (assert (= 1 (count-match " ** post-build" (test-out :out ))))
108
+ (assert (= 0 (count-match " ** pre-install" (test-out :out ))))
109
+ (assert (= 0 (count-match " ** post-install" (test-out :out ))))
110
+ (assert (= 1 (count-match " ** pre-check" (test-out :out ))))
111
+ (assert (= 1 (count-match " ** post-check" (test-out :out ))))
112
+ (assert (= 1 (count-match " running test" (test-out :out ))))
113
+
114
+ # verify order of entries
115
+ (assert (after? " post-build" " pre-build" (test-out :out )))
116
+ (assert (after? " pre-check" " post-build" (test-out :out )))
117
+ (assert (after? " running test" " pre-check" (test-out :out )))
118
+ (assert (after? " post-check" " running test" (test-out :out )))
119
+
120
+ # check "clean"
121
+ (divider " Running janet-pm clean" )
122
+ (def clean-out (sh/exec-slurp-all janet-pm " clean" ))
123
+ (dump-out clean-out )
124
+ # verify proper entries only occur once
125
+ (assert (= 1 (count-match " ** pre-clean" (clean-out :out ))))
126
+ (assert (= 1 (count-match " removing directory _build/" (clean-out :out ))))
127
+ (assert (= 1 (count-match " ** post-clean" (clean-out :out ))))
128
+ (assert (= 0 (count-match " ** pre-build" (clean-out :out ))))
129
+ (assert (= 0 (count-match " ** post-build" (clean-out :out ))))
130
+ (assert (= 0 (count-match " ** pre-install" (clean-out :out ))))
131
+ (assert (= 0 (count-match " ** post-install" (clean-out :out ))))
132
+ (assert (= 0 (count-match " ** pre-check" (clean-out :out ))))
133
+ (assert (= 0 (count-match " ** post-check" (clean-out :out ))))
134
+
135
+ # verify order of entries
136
+ (assert (after? " removing directory" " pre-clean" (clean-out :out )))
137
+ (assert (after? " post-clean" " removing directory" (clean-out :out )))
138
+
139
+ # check "clean-all"
140
+ (divider " Running janet-pm clean-all" )
141
+ (def clean-all-out (sh/exec-slurp-all janet-pm " clean-all" ))
142
+ (dump-out clean-all-out )
143
+ # verify proper entries only occur once
144
+ (assert (= 1 (count-match " ** pre-clean" (clean-all-out :out ))))
145
+ (assert (= 1 (count-match " removing directory _build" (clean-all-out :out ))))
146
+ (assert (= 1 (count-match " ** post-clean" (clean-all-out :out ))))
147
+ (assert (= 0 (count-match " ** pre-build" (clean-all-out :out ))))
148
+ (assert (= 0 (count-match " ** post-build" (clean-all-out :out ))))
149
+ (assert (= 0 (count-match " ** pre-install" (clean-all-out :out ))))
150
+ (assert (= 0 (count-match " ** post-install" (clean-all-out :out ))))
151
+ (assert (= 0 (count-match " ** pre-check" (clean-all-out :out ))))
152
+ (assert (= 0 (count-match " ** post-check" (clean-all-out :out ))))
153
+
154
+ # verify order of entries
155
+ (assert (after? " removing directory" " pre-clean" (clean-all-out :out )))
156
+ (assert (after? " post-clean" " removing directory" (clean-all-out :out ))))
157
+
158
+ # reset *out* so we can see # tests passed even if VERBOSE is not defined
159
+ (setdyn *out* nil )
160
+
161
+ (end-suite )
0 commit comments