Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ jobs:
key: cljdeps-${{ env.CACHE_VERSION }}-${{ hashFiles('project.clj') }}-${{ hashFiles('deps.edn') }}-${{ hashFiles('bb.edn') }}
restore-keys: cljdeps-${{ env.CACHE_VERSION }}-

- name: Prepare dotnet
uses: xt0rted/[email protected]

- name: Install ClojureCLR
run: |
dotnet tool install --global Clojure.Main --version 1.12.2
dotnet tool install --global Clojure.Cljr --version 0.1.0-alpha6

- name: Prepare node
uses: actions/setup-node@v4
with:
Expand All @@ -61,5 +69,8 @@ jobs:
- name: Run Clojure tests
run: lein test

- name: Run ClojureCLR Tests
run: cljr -X:test

- name: Run babashka tests
run: bb test-bb
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ Once tests are compiled they can be ran with:
node target/js/node-tests.js
```

## Running the ClojureCLR tests

### Pre-requisites
- [dotnet](https://dotnet.microsoft.com/en-us/download)
- `ClojureCLR`: `dotnet tool install --global Clojure.Main --version 1.12.2`
- `cljr`: `dotnet tool install --global Clojure.Cljr --version 0.1.0-alpha6`

```bash
cljr -X:test
```

### Automated test running during development

If you want to autorun the tests during development run the following:
Expand Down
58 changes: 30 additions & 28 deletions test/clojure/core_test/merge.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,36 @@
{:b "b"}))))

(testing "vectors in position 2+ are treated as map-entries, per `conj`"
(is (thrown? #?(:cljs :default, :clj java.lang.IllegalArgumentException, :clr Exception)
(merge {} [])))
(is (thrown? #?(:cljs :default, :clj java.lang.IllegalArgumentException, :clr Exception)
(merge {} [:foo])))
#?(:cljs (is (thrown? js/Error (merge {} [])))
:clj (is (thrown? java.lang.IllegalArgumentException (merge {} [])))
:default (is (thrown? Exception (merge {} []))))
#?(:cljs (is (thrown? js/Error (merge {} [:foo])))
:clj (is (thrown? java.lang.IllegalArgumentException (merge {} [:foo])))
:default (is (thrown? Exception (merge {} [:foo]))))
(is (= {:foo "foo"} (merge {} [:foo "foo"])))
(is (= {"x" 1} (merge {} ["x" 1])))
(is (= {'x 10, 'y 10} (merge {'x 10} ['y 10])))
(testing "In CLJS (unlike other dialects) vectors with >2 arguments are treated as map-entries (where the latter values are ignored)"
#?(:cljs (is (= {:foo :bar} (merge {} [:foo :bar :baz]))),
:clj (is (thrown? java.lang.IllegalArgumentException (merge {} [:foo :bar :baz]))),
:clr (is (thrown? Exception (merge {} [:foo :bar :baz])))))
:clj (is (thrown? java.lang.IllegalArgumentException (merge {} [:foo :bar :baz]))),
:clr (is (thrown? Exception (merge {} [:foo :bar :baz])))))

(is (= {:foo "foo", :bar "bar"} (merge {} [:foo "foo"] [:bar "bar"])))
(is (= {'x 10, 'y 10, 'z 10} (merge {'x 10} ['y 10] ['z 10])))
(testing "In CLJS (unlike other dialects) vectors with >2 arguments are treated as map-entries (where the latter values are ignored)"
#?(:cljs (is (= {:foo :bar} (merge {} [:foo :bar :baz :bar]))),
:clj (is (thrown? java.lang.IllegalArgumentException (merge {} [:foo :bar :baz :bar]))),
:clr (is (thrown? Exception (merge {} [:foo :bar :baz :bar]))))))
:clj (is (thrown? java.lang.IllegalArgumentException (merge {} [:foo :bar :baz :bar]))),
:clr (is (thrown? Exception (merge {} [:foo :bar :baz :bar]))))))

(testing "atomic values in position 2+ throw"
(is (thrown? #?(:cljs :default, :clj Exception, :clr Exception)
(merge {} 1)))
(is (thrown? #?(:cljs :default, :clj Exception, :clr Exception)
(merge {} 1 2)))
(is (thrown? #?(:cljs :default, :clj Exception, :clr Exception)
(merge {} :foo)))
(is (thrown? #?(:cljs :default, :clj Exception, :clr Exception)
(merge {} "str"))))
#?@(:cljs [(is (thrown? js/Error (merge {} 1)))
(is (thrown? js/Error (merge {} 1 2)))
(is (thrown? js/Error (merge {} :foo)))
(is (thrown? js/Error (merge {} "str")))]
:default [(is (thrown? Exception (merge {} 1)))
(is (thrown? Exception (merge {} 1 2)))
(is (thrown? Exception (merge {} :foo)))
(is (thrown? Exception (merge {} "str")))]))

(testing "undefined `merge` behavior on non-maps"
;; Behavior for non-map input is undefined. We intentionally do not test
Expand All @@ -83,15 +85,15 @@
(is (any? (merge (first {:a "a"}) {:b "b"} {:c "c"})))
(is (= [:foo] (merge [:foo])))
(is (= :foo (merge :foo)))
(is (thrown? #?(:cljs :default, :clj Exception, :clr Exception)
(merge :foo :bar)))
(is (thrown? #?(:cljs :default, :clj Exception, :clr Exception)
(merge 100 :foo)))
(is (thrown? #?(:cljs :default, :clj Exception, :clr Exception)
(merge "str" :foo)))
(is (thrown? #?(:cljs :default, :clj Exception, :clr Exception)
(merge nil (range))))
(is (thrown? #?(:cljs :default, :clj Exception, :clr Exception)
(merge {} '(1 2))))
(is (thrown? #?(:cljs :default, :clj Exception, :clr Exception)
(merge {} 1 2)))))))
#?@(:cljs [(is (thrown? js/Error (merge :foo :bar)))
(is (thrown? js/Error (merge 100 :foo)))
(is (thrown? js/Error (merge "str" :foo)))
(is (thrown? js/Error (merge nil (range))))
(is (thrown? js/Error (merge {} '(1 2))))
(is (thrown? js/Error (merge {} 1 2)))]
:default [(is (thrown? Exception (merge :foo :bar)))
(is (thrown? Exception (merge 100 :foo)))
(is (thrown? Exception (merge "str" :foo)))
(is (thrown? Exception (merge nil (range))))
(is (thrown? Exception (merge {} '(1 2))))
(is (thrown? Exception (merge {} 1 2)))])))))
46 changes: 23 additions & 23 deletions test/clojure/core_test/val.cljc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns clojure.core-test.val
(:require [clojure.test :as t :refer [deftest testing is are]]
(:require [clojure.test :as t :refer [deftest testing is]]
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))

(when-var-exists val
Expand All @@ -9,29 +9,29 @@
(is (= :v (val (first {:k :v, :one :two}))))
;; Note: the following may be built on shaky ground, per Rich:
;; https://groups.google.com/g/clojure/c/FVcrbHJpCW4/m/Fh7NsX_Yb7sJ
(is (= 'v (val #?(:cljs (cljs.core/MapEntry. 'k 'v nil)
:clj (clojure.lang.MapEntry/create 'k 'v)))))
(is (= 'v (val #?(:cljs (cljs.core/MapEntry. 'k 'v nil)
:default (clojure.lang.MapEntry/create 'k 'v)))))
(is (= :b (val (first (sorted-map :a :b)))))
(is (= :b (val (first (hash-map :a :b)))))
(is (= :b (val (first (array-map :a :b))))))
(testing "`val` throws on lots of things"
(is (thrown? #?(:cljs :default, :clj Exception, :cljr Exception)
(val nil)))
(is (thrown? #?(:cljs :default, :clj Exception, :cljr Exception)
(val 0)))
(is (thrown? #?(:cljs :default, :clj Exception, :cljr Exception)
(val '())))
(is (thrown? #?(:cljs :default, :clj Exception, :cljr Exception)
(val '(1 2))))
(is (thrown? #?(:cljs :default, :clj Exception, :cljr Exception)
(val {})))
(is (thrown? #?(:cljs :default, :clj Exception, :cljr Exception)
(val {1 2})))
(is (thrown? #?(:cljs :default, :clj Exception, :cljr Exception)
(val [])))
(is (thrown? #?(:cljs :default, :clj Exception, :cljr Exception)
(val [1 2])))
(is (thrown? #?(:cljs :default, :clj Exception, :cljr Exception)
(val #{})))
(is (thrown? #?(:cljs :default, :clj Exception, :cljr Exception)
(val #{1 2}))))))
#?@(:cljs [(is (thrown? js/Error (val nil)))
(is (thrown? js/Error (val 0)))
(is (thrown? js/Error (val '())))
(is (thrown? js/Error (val '(1 2))))
(is (thrown? js/Error (val {})))
(is (thrown? js/Error (val {1 2})))
(is (thrown? js/Error (val [])))
(is (thrown? js/Error (val [1 2])))
(is (thrown? js/Error (val #{})))
(is (thrown? js/Error (val #{1 2})))]
:default [(is (thrown? Exception (val nil)))
(is (thrown? Exception (val 0)))
(is (thrown? Exception (val '())))
(is (thrown? Exception (val '(1 2))))
(is (thrown? Exception (val {})))
(is (thrown? Exception (val {1 2})))
(is (thrown? Exception (val [])))
(is (thrown? Exception (val [1 2])))
(is (thrown? Exception (val #{})))
(is (thrown? Exception (val #{1 2})))]))))