Merge branch 'master' into init-at-build-time

This commit is contained in:
Michiel Borkent 2021-06-30 12:06:34 +02:00
commit f792c98784
14 changed files with 132 additions and 48 deletions

View file

@ -4,8 +4,13 @@ For a list of breaking changes, check [here](#breaking-changes).
## Unreleased
Babashka proper:
- Passing form on Windows with question mark breaks evaluation [#889](https://github.com/babashka/babashka/issues/889)
- `(read-line)` is buggy in REPL [#899](https://github.com/babashka/babashka/issues/899)
- Add `java.io.FileInputStream`. This fixes compatibility with [replikativ/hasch](https://github.com/replikativ/hasch).
Sci: minor perf improvements.
## 0.4.6

View file

@ -298,6 +298,9 @@ handling of SIGINT and SIGPIPE. This can be done by setting
## Articles, podcasts and videos
- [Integrating Babashka into Bazel](https://timjaeger.io/20210627-integrating-babashka-with-bazel.html) by Tim Jäger
- [Talk](https://youtu.be/Yjeh57eE9rg): Babashka: a native Clojure interpreter for scripting — The 2021 Graal Workshop at CGO
- [Blog](https://savo.rocks/posts/playing-new-music-on-old-car-stereo-with-clojure-and-babashka/): Playing New Music On Old Car Stereo With Clojure And Babashka
- [Homoiconicity and feature flags](https://martinklepsch.org/posts/homoiconicity-and-feature-flags.html) by Martin Klepsch
- [Clojure like its PHP](https://eccentric-j.com/blog/clojure-like-its-php.html) by Jay Zawrotny (eccentric-j)
- [Deploy babashka script to AWS Lambda](https://www.jocas.lt/blog/post/babashka-aws-lambda/) by Dainius Jocas.

View file

@ -5,15 +5,34 @@ you have anything to add. Also see
[#babashka](https://twitter.com/hashtag/babashka?src=hashtag_click&f=live) on
Twitter.
## 2021-06
- New babashka 0.4.4 - 0.4.5 released.
- Share your babashka creations on the [Show and tell](https://github.com/babashka/babashka/discussions/categories/show-and-tell) forum on Github.
- [Integrating Babashka into Bazel](https://timjaeger.io/20210627-integrating-babashka-with-bazel.html) by Tim Jäger
- [Babashka + scittle guestbook example](https://github.com/kloimhardt/babashka-scittle-guestbook)
- [Slingshot works with babashka](https://twitter.com/borkdude/status/1402547783295504387)
- [Spire gets a babashka pod](https://twitter.com/epic_castle/status/1402212817533431808)
- [Text to speech AWS example](https://twitter.com/FieryCodDev/status/1401843357555511301) with scittle and babashka.
- [Game of Life](https://gist.github.com/mmzsource/655b9dcfe56eed8a045022837186ed84)
- [ob-babashka](https://gist.github.com/adam-james-v/f4d2b75a70b095d14a351a1eff96b4b0): Emacs org-babel functions for babashka.
- [Normalize auto-resolved keywords](https://github.com/babashka/babashka/tree/master/examples#normalize-keywordsclj)
- [Create PostgreSQL backups](https://twitter.com/stelstuff/status/1400559261025980418) using babashka.
- [Change flutter SDK](https://gist.github.com/ampersanda/aac70cc0644df12199ea32988f3c4d73) using babashka.
## 2021-05
- Babashka 0.3.6-0.4.0 release. Highlights:
- Babashka 0.3.7 - 0.4.3 released. Highlights:
- New [task runner feature](https://book.babashka.org/#tasks).
- Add [Selmer](https://github.com/yogthos/Selmer) to built-in libraries.
- Add compatibility with [jasentaa](https://github.com/rm-hull/jasentaa).
- New [website](https://babashka.org).
- [Talk](https://youtu.be/Yjeh57eE9rg): Babashka: a native Clojure interpreter for scripting — The 2021 Graal Workshop at CGO
- [Blog](https://savo.rocks/posts/playing-new-music-on-old-car-stereo-with-clojure-and-babashka/): Playing New Music On Old Car Stereo With Clojure And Babashka
- [Homoiconicity and feature flags](https://martinklepsch.org/posts/homoiconicity-and-feature-flags.html) by Martin Klepsch.
- [Manage your macOS setup](https://github.com/cldwalker/osx-setup) using babashka.
- [Localizing a Ghost theme](https://martinklepsch.org/posts/localizing-a-ghost-theme.html) by Martin Klepsch.
- [Babashka SQL pods 0.0.8](https://twitter.com/borkdude/status/1396136828479188997) including a MySQL pod
## 2021-04

View file

@ -25,7 +25,7 @@
- [Invoke vim inside a script](#invoke-vim-inside-a-script)
- [Portal](#portal)
- [Image viewer](#image-viewer)
- [File server](#file-server)
- [HTTP server](#http-server)
- [Torrent viewer](#torrent-viewer)
- [cprop.clj](#cpropclj)
- [fzf](#fzf)
@ -372,14 +372,15 @@ $ examples/image-viewer.clj
See [image-viewer.clj](image-viewer.clj).
## File server
## HTTP Server
Opens browser window and lets user navigate through filesystem.
Opens browser window and lets user navigate through filesystem, similar to
`python3 -m http.server`.
Example usage:
``` shell
$ examples/file-server.clj
$ examples/http-server.clj
```
See [file-server.clj](file-server.clj).

View file

@ -3,7 +3,7 @@
;; Source: https://gist.github.com/holyjak/36c6284c047ffb7573e8a34399de27d8
;; Based on https://github.com/babashka/babashka/blob/master/examples/image_viewer.clj
(ns file-server
(ns http-server
(:require [babashka.fs :as fs]
[clojure.java.browse :as browse]
[clojure.string :as str]

View file

@ -14,7 +14,8 @@
;; :java-source-paths ["sci/reflector/src-java"]
:java-source-paths ["src-java"]
:resource-paths ["resources" "sci/resources"]
:test-selectors {:windows (complement :skip-windows)}
:test-selectors {:default (complement :windows-only)
:windows (complement :skip-windows)}
:dependencies [[org.clojure/clojure "1.11.0-alpha1"]
[borkdude/edamame "0.0.11"]
[borkdude/graal.locking "0.0.2"]

2
sci

@ -1 +1 @@
Subproject commit 8f08012b8ec945ff859062e6b96877b21223f0df
Subproject commit 98042fc613e01adf637cb927ccfe78b183084eaf

View file

@ -34,9 +34,8 @@ set BABASHKA_CLASSPATH=test-resources/babashka/src_for_classpath_test/env
echo "running tests part 4"
call lein test :only babashka.classpath-test/classpath-env-test || exit /B 1
echo "not running pod tests on windows (yet)"
REM set BABASHKA_POD_TEST=true
REM call lein test :only babashka.pod-test || exit /B 1
set BABASHKA_POD_TEST=true
call lein test :only babashka.pod-test || exit /B 1
set BABASHKA_SOCKET_REPL_TEST=true
call lein test :only babashka.impl.socket-repl-test || exit /B 1

View file

@ -128,10 +128,12 @@
(if (contains? cli-args "--run-as-pod")
(do (debug "running pod with cli args" cli-args)
(run-pod cli-args))
(let [native? (contains? cli-args "--native")]
(pods/load-pod (if native?
(into ["./bb" "test-resources/pod.clj" "--run-as-pod"] cli-args)
(into ["lein" "bb" "test-resources/pod.clj" "--run-as-pod"] cli-args)))
(let [native? (contains? cli-args "--native")
windows? (contains? cli-args "--windows")]
(pods/load-pod (cond
native? (into ["./bb" "test-resources/pod.clj" "--run-as-pod"] cli-args)
windows? (into ["cmd" "/c" "lein" "bb" "test-resources/pod.clj" "--run-as-pod"] cli-args)
:else (into ["lein" "bb" "test-resources/pod.clj" "--run-as-pod"] cli-args)))
(require '[pod.test-pod])
(if (contains? cli-args "--json")
(do

View file

@ -244,21 +244,23 @@
*server* server]
(babashka.tasks/run 'server)))}}
(is (= '([8 :foo] [8 :bar] [11 :foo] [11 :bar] [15 :foo] [15 :bar])
(bb "run" "--prn" "run-all"))))))
(deftest ^:skip-windows unix-task-test
(bb "run" "--prn" "run-all")))))
(let [tmp-dir (fs/create-temp-dir)
out (str (fs/file tmp-dir "out.txt"))]
out (str (fs/file tmp-dir "out.txt"))
ls-cmd (if main/windows? "cmd /c dir" "ls")
expected-output (if main/windows? "File Not Found" "foobar")]
(testing "shell test with :continue"
(test-utils/with-config {:tasks {'foo (list 'shell {:out out
:err out
:continue true}
"ls foobar")}}
(str ls-cmd " foobar"))}}
(bb "foo")
(is (str/includes? (slurp out)
"foobar"))))
(fs/delete out))
expected-output))))
(fs/delete out)))
(deftest ^:skip-windows unix-task-test
(testing "shell pipe test"
(test-utils/with-config '{:tasks {a (-> (shell {:out :string}
"echo hello")
@ -267,6 +269,19 @@
(let [s (bb "run" "--prn" "a")]
(is (= "hello\n" s))))))
(deftest ^:windows-only win-task-test
(when main/windows?
(testing "shell pipe test"
; this task prints the contents of deps.edn
(test-utils/with-config '{:tasks {a (->> (shell {:out :string}
"cmd /c echo deps.edn")
:out
clojure.string/trim-newline
(shell {:out :string} "cmd /c type")
:out)}}
(let [s (bb "run" "--prn" "a")]
(is (str/includes? s "paths")))))))
(deftest list-tasks-test
(test-utils/with-config {}
(let [res (test-utils/bb nil "tasks")]

View file

@ -1,7 +1,9 @@
(ns babashka.impl.clojure.java.shell-test
(:require [clojure.test :as t :refer [deftest is testing]]
(:require [babashka.main :as main]
[babashka.test-utils :as test-utils]
[clojure.string :as str]))
[clojure.string :as str]
[clojure.test :as t :refer [deftest is testing]]))
(deftest ^:skip-windows with-sh-env-test
(is (= "\"BAR\""
@ -15,3 +17,17 @@
(shell/sh \"ls\"))
:out)"))
"icon.svg")))
(deftest ^:windows-only win-with-sh-env-test
(when main/windows?
(is (= "\"BAR\""
(str/trim (test-utils/bb nil "
(-> (shell/with-sh-env {:FOO \"BAR\"}
(shell/sh \"cmd\" \"/c\" \"echo %FOO%\"))
:out
str/trim)"))))
(is (str/includes? (str/trim (test-utils/bb nil "
(-> (shell/with-sh-dir \"logo\"
(shell/sh \"cmd\" \"/c\" \"dir\"))
:out)"))
"icon.svg"))))

View file

@ -200,6 +200,7 @@
(is (true? (bb nil "(.exists (io/file \"README.md\"))")))
(is (true? (bb nil "(.canWrite (io/file \"README.md\"))"))))
; skipped because the windows shell doesn't seem to deal well with infinite things
(deftest ^:skip-windows pipe-test
(when (and test-utils/native?
(not main/windows?))
@ -208,15 +209,21 @@
head -n10"))
out (str/split-lines out)
out (map edn/read-string out)]
(is (= (take 10 (map #(* % %) (range))) out))))
(when (and test-utils/native?
(not main/windows?))
(is (= (take 10 (map #(* % %) (range))) out)))
(let [out (:out (sh "bash" "-c" "./bb -O '(repeat \"dude\")' |
./bb --stream '(str *input* \"rino\")' |
./bb -I '(take 3 *input*)'"))
out (edn/read-string out)]
(is (= '("duderino" "duderino" "duderino") out)))))
(deftest ^:windows-only win-pipe-test
(when (and test-utils/native? main/windows?)
(let [out (:out (sh "cmd" "/c" ".\\bb -O \"(repeat 50 \\\"dude\\\")\" |"
".\\bb --stream \"(str *input* \\\"rino\\\")\" |"
".\\bb -I \"(take 3 *input*)\""))
out (edn/read-string out)]
(is (= '("duderino" "duderino" "duderino") out)))))
(deftest ^:skip-windows lazy-text-in-test
(when test-utils/native?
(let [out (:out (sh "bash" "-c" "yes | ./bb -i '(take 2 *input*)'"))
@ -255,15 +262,11 @@
(is (every? number? parsed))
(is (= process-count (count parsed)))))))
(deftest ^:skip-windows create-temp-file-test
(let [temp-dir-path (System/getProperty "java.io.tmpdir")]
(is (= true
(bb nil (format "(let [tdir (io/file \"%s\")
tfile
(File/createTempFile \"ctf\" \"tmp\" tdir)]
(deftest create-temp-file-test
(is (= true
(bb nil "(let [tfile (File/createTempFile \"ctf\" \"tmp\")]
(.deleteOnExit tfile) ; for cleanup
(.exists tfile))"
temp-dir-path))))))
(.exists tfile))"))))
(deftest wait-for-port-test
(let [server (test-utils/start-server! 1777)]
@ -475,6 +478,11 @@
(prn "output:" v)
(is v))))
(deftest win-file-reader-test
(let [v (bb nil "(slurp (io/reader (java.io.FileReader. \"test-resources/babashka/empty.clj\")))")]
(prn "output:" v)
(is (empty? v))))
(deftest ^:skip-windows download-and-extract-test
;; Disabled because Github throttles bandwidth and this makes for a very slow test.
;; TODO: refactor into individual unit tests
@ -659,6 +667,12 @@ true")))
(bb nil "-e" "(.get (.command (.info (java.lang.ProcessHandle/current))))")
"bb"))))
(deftest ^:windows-only win-process-handler-info-test
(when (and test-utils/native? main/windows?)
(is (str/ends-with?
(bb nil "-e" "(.get (.command (.info (java.lang.ProcessHandle/current))))")
"bb.exe"))))
(deftest interop-concurrency-test
(is (= ["true" 3] (last (bb nil "-e"
"

View file

@ -1,23 +1,29 @@
(ns babashka.pod-test
(:require [babashka.test-utils :as tu]
(:require [babashka.main :as main]
[babashka.test-utils :as tu]
[clojure.edn :as edn]
[clojure.test :as t :refer [deftest is]]))
(deftest pod-test
(if (= "true" (System/getenv "BABASHKA_POD_TEST"))
(let [native? tu/native?
windows? main/windows?
sw (java.io.StringWriter.)
res (apply tu/bb {:err sw}
(cond-> ["-f" "test-resources/pod.clj"]
native?
(conj "--native")))
(conj "--native")
windows?
(conj "--windows")))
err (str sw)]
(is (= "6\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\"Illegal arguments / {:args (1 2 3)}\"\n(\"hello\" \"print\" \"this\" \"debugging\" \"message\")\ntrue\n" res))
(when-not tu/native?
(is (= "(\"hello\" \"print\" \"this\" \"error\")\n" err)))
(is (= "(\"hello\" \"print\" \"this\" \"error\")\n" (tu/normalize err))))
(is (= {:a 1 :b 2}
(edn/read-string
(apply tu/bb nil (cond-> ["-f" "test-resources/pod.clj" "--json"]
native?
(conj "--native")))))))
(conj "--native")
windows?
(conj "--windows")))))))
(println "Skipping pod test because BABASHKA_POD_TEST isn't set to true.")))

View file

@ -12,7 +12,7 @@
(enumeration-seq
(.entries jar-file))))))
(deftest ^:skip-windows uberjar-test
(deftest uberjar-test
(testing "uberjar with --main"
(let [tmp-file (java.io.File/createTempFile "uber" ".jar")
path (.getPath tmp-file)]
@ -45,13 +45,16 @@
(is (= "(\"42\")\n" (tu/bb nil "--jar" path "-m" "my.main-main" "42")))
(is (= "(\"42\")\n" (tu/bb nil "--classpath" path "-m" "my.main-main" "42")))
(is (= "(\"42\")\n" (tu/bb nil path "42"))))))
(testing "throw on empty classpath"
(let [tmp-file (java.io.File/createTempFile "uber" ".jar")
path (.getPath tmp-file)]
(.deleteOnExit tmp-file)
(is (thrown-with-msg?
Exception #"classpath"
(tu/bb nil "uberjar" path "-m" "my.main-main")))))
; this test fails the windows native test in CI
(when-not main/windows?
(testing "throw on empty classpath"
(let [tmp-file (java.io.File/createTempFile "uber" ".jar")
path (.getPath tmp-file)]
(.deleteOnExit tmp-file)
(is (thrown-with-msg?
Exception #"classpath"
(tu/bb nil "uberjar" path "-m" "my.main-main"))))))
(testing "ignore empty entries on classpath"
(let [tmp-file (java.io.File/createTempFile "uber" ".jar")
path (.getPath tmp-file)