Skip to content

Commit 748b098

Browse files
authored
test: include full coverage for windows (#122)
Instead of launching os specific commands we now launch the os-agnostic wee dummy `test/wd.clj` script via babashka. It is designed to satisfy the needs of tests. Examples of types of changes to launched processes: - echo hello -> bb script/wd.clj :out hello - ls -> bb script/wd.clj :ls . - grep somestring -> bb script/wd.clj :grep somestring - clojure -e some-expr -> bb script/wd.clj :out boo :err bah :exit 1 Replaced most uses of `cat` with `bb script/wd.clj :upper`, I felt that transforming the input offered more proof that the process was run successfully. Because our wee dummy script allows us to define explicit output and behaviour, tests assertions are now also often more explicit. Took care to keep the args syntax the same as the original test. (i.e. args as string vs vector of strings vs vector of symbols). CI downloads babashka deps prior to test run. This avoids deps download messages to stderr interfering with the test. A `bb --version` is sufficient. Removed Windows specific tests, tests are now OS agnostic: - windows-invoke-git-with-space-test -> process-space-in-cmd-test - windows-executable-resolver-test -> tested throughout - windows-pprint-test -> pprint-test - windows-pre-start-fn-test -> pre-start-fn-test Understood that tests can be launched from babashka or babashka/process. When tests are run from babashka for the jvm, and bb does not exist, we skip and pass tests that require bb with a warning. These same tests will be run with natively with bb in a subsequent pass, so we are not reducing babashka test coverage. Updated process-dir-option-test: - No longer skipping a test assertion when run under babashka. - Deleted a redundant assertion. Observations when requesting an empty :env noted in README: - Windows always includes `SystemRoot` - macOS always includes `__CF_USER_TEXT_ENCODING` GitHub Actions changes (could be considered out of scope): - I set fail-fast to false for the matrix, I found it helpful to all jobs run even after one job had failed. - I adjusted deps caching to include ~/.deps.clj, I found this helpful in validating my explorations in what deps I needed to pre-download. - Noticed bb.edn was missing from deps cache key so added it in. Made some other very minor changes to code/comments for clarity. Closes #116
1 parent 84919a6 commit 748b098

File tree

6 files changed

+422
-295
lines changed

6 files changed

+422
-295
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
name: Install Babashka
3030
command: |
3131
sudo bash < <(curl -s https://raw.githubusercontent.com/babashka/babashka/master/install)
32+
bb --version
3233
- run:
3334
name: Run JVM tests
3435
command: |
@@ -58,6 +59,7 @@ jobs:
5859
name: Install Babashka
5960
command: |
6061
sudo bash < <(curl -s https://raw.githubusercontent.com/babashka/babashka/master/install)
62+
bb --version
6163
- run:
6264
name: Run JVM tests
6365
command: |

.github/workflows/ci.yml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on: [push, pull_request]
55
jobs:
66
test:
77
strategy:
8+
fail-fast: false
89
matrix:
910
java-version: ["8", "11", "17"]
1011
os: [ubuntu-latest, macOS-latest, windows-latest]
@@ -24,28 +25,24 @@ jobs:
2425
- name: "Restore Cache"
2526
uses: "actions/cache@v3"
2627
with:
27-
path: "~/.m2/repository"
28-
key: "${{ runner.os }}-deps-${{ hashFiles('deps.edn') }}"
29-
restore-keys: "${{ runner.os }}-deps-"
28+
path: |
29+
~/.m2/repository
30+
~/.gitlibs
31+
~/.deps.clj
32+
key: "${{ runner.os }}-deps-${{ hashFiles('deps.edn','bb.edn') }}"
3033

3134
- name: Setup Clojure
3235
uses: DeLaGuardo/[email protected]
3336
with:
3437
cli: 1.10.3.1040
3538
bb: 'latest'
3639

37-
- name: Run tests not Windows
38-
if: ${{ matrix.os != 'windows-latest' }}
39-
run: |
40-
clojure -M:clj-1.9:test -e windows
41-
clojure -M:clj-1.10:test -e windows
42-
clojure -M:clj-1.11:test -e windows
43-
shell: bash
40+
- name: Download bb deps
41+
run:
42+
bb --version
4443

45-
- name: Run tests on Windows
46-
if: ${{ matrix.os == 'windows-latest' }}
44+
- name: Run tests
4745
run: |
48-
clojure -M:clj-1.9:test -i windows
49-
clojure -M:clj-1.10:test -i windows
50-
clojure -M:clj-1.11:test -i windows
51-
shell: powershell
46+
clojure -M:clj-1.9:test
47+
clojure -M:clj-1.10:test
48+
clojure -M:clj-1.11:test

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ The `:env` option replaces your entire environment with the provided map. To add
390390
For example, `"PATH"` will not update the value of `"Path"` on Windows.
391391
Here's an [example of a babashka task](https://github.com/babashka/fs/blob/3b8010d1a0db166771ac7f47573ea09ed45abe33/bb.edn#L10-L11) that understands this nuance.
392392

393+
> **:env TIP**: An OS might have default environment variables it always includes.
394+
For example, as of this writing, Windows always includes `SystemRoot` and macOS always includes `__CF_USER_TEXT_ENCODING`.
395+
393396
## Pipelines
394397

395398
The `pipeline` function returns a

script/test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22

3-
clojure -M:test -e windows @$
3+
clojure -M:test @$

script/wd.clj

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
;; wd - wee dummy - an os-agnostic bb script launched by our unit tests
2+
(require '[clojure.java.io :as io]
3+
'[clojure.string :as str])
4+
5+
;; usage
6+
;; :out <somestring> - dump <somestring> to stdout
7+
;; :err <somestring> - dump <somestring> to stderr
8+
;; :ls <somefile> - dir of <somefile> to stdout
9+
;; :env - dump env to stdout
10+
;; :grep <somestring> - returns all lines from stdin matching <somestring>
11+
;; :upper - read and emit lines from stdin, but converted to uppercase
12+
;; :exit <someval> - exits with <someval>
13+
14+
;; the naivest of cmd line parsing
15+
(doseq [[cmd val] (partition-all 2 1 *command-line-args*)]
16+
(case cmd
17+
":out" (println val)
18+
":err" (binding [*out* *err*] (println val))
19+
":ls" (pr (->> val io/file (.listFiles) (map str) sort))
20+
":env" (pr (->> (System/getenv) (into {})))
21+
":grep" (doseq [l (->> *in* io/reader line-seq (filter #(str/includes? % val)))]
22+
(println l))
23+
":upper" (doseq [l (->> *in* io/reader line-seq)]
24+
(println (str/upper-case l)))
25+
":sleep" (Thread/sleep (parse-long val))
26+
":exit" (System/exit (parse-long val))
27+
nil))

0 commit comments

Comments
 (0)