Skip to content

Commit

Permalink
babashka support
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored and dustingetz committed Jul 14, 2023
1 parent efec5fb commit 4718049
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/tests_babashka.yml
@@ -0,0 +1,23 @@
name: Babashka
on: [push, pull_request]
jobs:
babashka:
runs-on: [ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Prepare java
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Install clojure tools
uses: DeLaGuardo/setup-clojure@10.1
with:
cli: 1.10.1.727
bb: latest

- name: Run tests
run: bb test:bb

4 changes: 4 additions & 0 deletions bb.edn
@@ -0,0 +1,4 @@
{:paths ["bb" "src"]
:tasks {test:bb {:extra-paths ["test"]
:extra-deps {nubank/matcher-combinators {:mvn/version "3.5.1"}}
:task (exec 'runner/run-tests)}}}
19 changes: 19 additions & 0 deletions bb/runner.clj
@@ -0,0 +1,19 @@
(ns runner
(:require
[clojure.test :as test]
[hyperfiddle.rcf :as rcf]))

(defn run-tests [_]
(alter-var-root (var rcf/*generate-tests*) (constantly true))
(let [test-nses '[hyperfiddle.rcf-test
hyperfiddle.rcf.analyzer-test
;; needs missionary, doesn't work due to missing reactive streams Java lib:
#_hyperfiddle.rcf.unify-test
;; needs missionary:
#_hyperfiddle.rcf.example-test
]]
(apply require test-nses)
(let [{:keys [fail error]}
(apply test/run-tests test-nses)]
(when (and fail error (pos? (+ fail error)))
(throw (ex-info "Tests failed" {:babasha/exit 1}))))))
9 changes: 6 additions & 3 deletions src/hyperfiddle/rcf/analyzer.clj
Expand Up @@ -425,6 +425,8 @@
[m f]
(reduce-kv (fn [m k v] (assoc m k (f v))) {} (or m {})))

(defmacro if-bb [then else] (if (System/getProperty "babashka.version") then else))

(defn create-var
"Creates a Var for sym and returns it.
The Var gets interned in the env namespace."
Expand All @@ -433,9 +435,10 @@
(if (some? v)
(cond
(class? v) v
(and (var? v) (= ns (ns-name (.ns ^clojure.lang.Var v)))) (do (when-some [m (meta sym)]
(.setMeta v (update-vals m unquote')))
v)
(and (var? v) (= ns (ns-name (if-bb (:ns (meta v)) (.ns ^clojure.lang.Var v)))))
(do (when-some [m (meta sym)]
(if-bb (alter-meta! v (constantly (update-vals m unquote')))
(.setMeta v (update-vals m unquote')))) v)
:else (throw (ex-info (str "(def " sym " ...) resolved to an existing mapping of an unexpected type.")
{:sym sym
:ns ns
Expand Down

0 comments on commit 4718049

Please sign in to comment.