Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Oct 24, 2023
1 parent 6797707 commit 1e9b1d9
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
19 changes: 17 additions & 2 deletions bb/tasks.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[babashka.fs :as fs]
[babashka.process :refer [shell]]
[cheshire.core :as json]
[node-repl-tests]))
[node-repl-tests]
[clojure.string :as str]))

(def test-config
'{:compiler-options {:load-tests true}
Expand Down Expand Up @@ -44,10 +45,24 @@
(bump-core-vars)
(shell "npx shadow-cljs --aliases :dev --config-merge .work/config-merge.edn watch squint"))

(defn test-project [_]
(let [dir "test-project"]
(fs/delete-tree (fs/path dir "lib"))
(shell {:dir dir} "npx squint compile")
(let [output (:out (shell {:dir dir :out :string} "node lib/main.mjs"))]
(println output)
(assert (str/includes? output "macros2/debug 10"))
(assert (str/includes? output "macros2/debug 6"))
(assert (str/includes? output "macros/debug 10",))
(assert (str/includes? output "macros/debug 6")))))

(defn test-squint []
(fs/create-dirs ".work")
(spit ".work/config-merge.edn" (shadow-extra-test-config))
(bump-core-vars)
(shell "npx shadow-cljs --config-merge .work/config-merge.edn compile squint")
(shell "node lib/squint_tests.js")
(node-repl-tests/run-tests {}))
(node-repl-tests/run-tests {})
(test-project {}))


3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"squint-cljs": "."
},
"dependencies": {
"chokidar": "^3.5.3"
"chokidar": "^3.5.3",
"glob": "^10.3.10"
}
}
12 changes: 11 additions & 1 deletion src/squint/internal/cli.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require
["fs" :as fs]
["path" :as path]
["glob" :as glob]
[babashka.cli :as cli]
[shadow.esm :as esm]
[squint.compiler :as cc]
Expand All @@ -21,10 +22,19 @@
ext' (path/extname resolved)]
(str "./" (str/replace resolved (re-pattern (str ext' "$")) ext)))))

(defn glob-cljs-files [dir]
(glob/globSync (str dir "/**/*.{cljs,cljc}")))

(defn files-from-paths [paths]
(mapcat glob-cljs-files paths))

(defn compile-files
[opts files]
(let [cfg @utils/!cfg
opts (merge cfg opts)]
opts (merge cfg opts)
files (if (empty? files)
(files-from-paths (:paths cfg))
files)]
;; shouldn't need this if :coerce worked in babashka.cli
(when-let [out-dir (:output-dir opts)]
(when-not (string? out-dir)
Expand Down
2 changes: 1 addition & 1 deletion test-project/src/macros.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns macros)

(defmacro debug [_kwd body]
[::debug body])
`(println ::debug ~body))
2 changes: 1 addition & 1 deletion test-project/src/macros2.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns macros2)

(defmacro debug [_kwd body]
[::debug body])
`(println ::debug ~body))
6 changes: 3 additions & 3 deletions test-project/src/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(:require [other-ns]))

(defn foo []
(m/debug :foo (+ 1 2 3 4)))
(m/debug :foo (+ 1 2 3)))

(prn (foo))
(prn (debug :foo (+ 1 2 3 4)))
(foo)
(debug :foo (+ 1 2 3 4))
4 changes: 2 additions & 2 deletions test-project/src/other_ns.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns other-ns
(:require-macros [macros2 :as m :refer [debug]]))

(prn (debug :foo (+ 1 2 3)))
(prn (m/debug :foo (+ 1 2 3)))
(debug :foo (+ 1 2 3 4))
(m/debug :foo (+ 1 2 3))

0 comments on commit 1e9b1d9

Please sign in to comment.