|
33 | 33 | (defn divider [title]
|
34 | 34 | (printf "------------------------------------------\n%s" title))
|
35 | 35 |
|
| 36 | +(defn dump-file [filename] |
| 37 | + (let [contents (slurp filename)] |
| 38 | + (printf "---------- %s -------------" filename) |
| 39 | + (var count 0) |
| 40 | + (loop [line :in (string/split "\n" contents)] |
| 41 | + (set count (inc count)) |
| 42 | + (printf "%5d %s" count line)) |
| 43 | + (print "----------------------------"))) |
| 44 | + |
36 | 45 | (defn dump-out [output]
|
37 | 46 | (let [out (string/split "\n" (output :out))
|
38 | 47 | err (string/split "\n" (output :err))]
|
|
45 | 54 |
|
46 | 55 | (def bat (if (= (os/which) :windows) ".bat" ""))
|
47 | 56 |
|
48 |
| -(defn- test-binscript [filename syscount printcount] |
49 |
| - (assert (sh/exists? filename)) |
50 |
| - (let [contents (slurp filename)] |
51 |
| - (printf "---------- %s -------------" filename) |
52 |
| - (loop [line :in (string/split "\n" contents)] |
53 |
| - (print line)) |
54 |
| - (print "----------------------------") |
55 |
| - (assert (= syscount (length (string/find-all "put root-env :install-time-syspath" contents)))) |
56 |
| - (assert (= printcount (length (string/find-all "print" contents))))) |
57 |
| - # and finally make sure the script actually runs |
58 |
| - (assert (= "hello" (sh/exec-slurp (string filename bat))))) |
59 |
| - |
60 | 57 | # Create a temporary directory for our janet tree
|
61 | 58 | (math/seedrandom (os/cryptorand 16))
|
62 | 59 | (def syspath (randdir))
|
|
84 | 81 | (def binpath (path/join (dyn *syspath*) "bin"))
|
85 | 82 | (def janet-pm (path/join binpath (string "janet-pm")))
|
86 | 83 | (assert (sh/exists? janet-pm))
|
87 |
| - (assert (= 2 (length (string/find-all "put root-env :install-time-syspath" (slurp janet-pm))))) |
88 |
| - |
89 |
| - (def janet-format (path/join binpath (string "janet-format"))) |
90 |
| - (assert (sh/exists? janet-format)) |
91 |
| - (assert (= 2 (length (string/find-all "put root-env :install-time-syspath" (slurp janet-format))))) |
92 |
| - |
93 |
| - (def janet-netrepl (path/join binpath (string "janet-netrepl"))) |
94 |
| - (assert (sh/exists? janet-netrepl)) |
95 |
| - (assert (= 2 (length (string/find-all "put root-env :install-time-syspath" (slurp janet-netrepl))))) |
| 84 | + (dump-out (sh/exec-slurp-all janet-pm "show-config")) |
| 85 | + (assert (= 1 (length (string/find-all "put root-env :install-time-syspath" (slurp janet-pm))))) |
96 | 86 |
|
97 | 87 | # check sub commands work, even without defining pre-/post-
|
98 | 88 |
|
|
131 | 121 | (assert (after? "pre-install" "post-build" (install-out :out)))
|
132 | 122 | (assert (after? "post-install" "pre-install" (install-out :out)))
|
133 | 123 |
|
134 |
| - # now we look at the binscripts installed from the test-project |
135 |
| - # bin-no-main should only have one instance of the hardcoded syspath |
136 |
| - (def bin-no-main (path/join binpath (string "bin-no-main"))) |
137 |
| - (test-binscript bin-no-main 1 1) |
138 |
| - |
139 |
| - # bin-with-main should have 2 instances of hardcoded path |
| 124 | + # check that syspath is correctly set inside a main in a binscript |
140 | 125 | (def bin-with-main (path/join binpath (string "bin-with-main")))
|
141 |
| - (test-binscript bin-with-main 2 1) |
142 |
| - |
143 |
| - # bin-with-oneline-main could be tricky |
144 |
| - (def bin-with-oneline-main (path/join binpath (string "bin-with-oneline-main"))) |
145 |
| - (test-binscript bin-with-oneline-main 2 1) |
146 |
| - |
147 |
| - # bin-no-hardcode should have zero instances of hardcoded paths |
148 |
| - (def bin-no-hardcode (path/join binpath (string "bin-no-hardcode"))) |
149 |
| - (test-binscript bin-no-hardcode 0 1) |
| 126 | + (def bin-out (sh/exec-slurp-all (string bin-with-main bat))) |
| 127 | + (dump-out bin-out) |
| 128 | + (assert (string/find (dyn *syspath*) (bin-out :out))) |
150 | 129 |
|
151 | 130 | # check "test"
|
152 | 131 | (divider "Running janet-pm test")
|
|
0 commit comments