add test
This commit is contained in:
parent
5bc59dc692
commit
48fbd08608
4 changed files with 31 additions and 2 deletions
|
|
@ -1245,6 +1245,11 @@ $ examples/which.clj rg
|
|||
/usr/local/Cellar/ripgrep/11.0.1/bin/rg
|
||||
```
|
||||
|
||||
### pom.xml version
|
||||
|
||||
A script to retrieve the version from a `pom.xml` file. See
|
||||
[examples/pom_version.clj](https://github.com/borkdude/babashka/blob/master/examples/pom_version.clj). Written by [@wilkerlucio](https://github.com/wilkerlucio).
|
||||
|
||||
## Thanks
|
||||
|
||||
- [adgoji](https://www.adgoji.com/) for financial support
|
||||
|
|
|
|||
22
examples/pom_version.clj
Executable file
22
examples/pom_version.clj
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env bb
|
||||
|
||||
(ns pom-version
|
||||
{:author "Wilker Lucio"}
|
||||
(:require [clojure.data.xml :as xml]
|
||||
[clojure.string :as str]))
|
||||
|
||||
(defn tag-name? [tag tname]
|
||||
(some-> tag :tag name #{tname}))
|
||||
|
||||
(defn tag-content-str [tag]
|
||||
(->> tag :content (filter string?) (str/join "")))
|
||||
|
||||
(defn pom-version
|
||||
([] (pom-version "pom.xml"))
|
||||
([path]
|
||||
(->> (xml-seq (xml/parse-str (slurp path)))
|
||||
(filter #(tag-name? % "version"))
|
||||
first
|
||||
tag-content-str)))
|
||||
|
||||
(pom-version)
|
||||
|
|
@ -31,4 +31,5 @@
|
|||
'time (with-meta time* {:sci/macro true})
|
||||
'Throwable->map (copy-core-var Throwable->map)
|
||||
'compare-and-set! (copy-core-var compare-and-set!)
|
||||
'*data-readers* (sci/new-dynamic-var '*data-readers* nil)})
|
||||
'*data-readers* (sci/new-dynamic-var '*data-readers* nil)
|
||||
'xml-seq (copy-core-var xml-seq)})
|
||||
|
|
|
|||
|
|
@ -376,7 +376,8 @@
|
|||
|
||||
(deftest clojure-data-xml-test
|
||||
(is (= "<?xml version=\"1.0\" encoding=\"UTF-8\"?><items><item>1</item><item>2</item></items>"
|
||||
(bb nil "(let [xml (xml/parse-str \"<items><item>1</item><item>2</item></items>\")] (xml/emit-str xml))"))))
|
||||
(bb nil "(let [xml (xml/parse-str \"<items><item>1</item><item>2</item></items>\")] (xml/emit-str xml))")))
|
||||
(is (= "0.0.87-SNAPSHOT" (bb nil "examples/pom_version.clj" (.getPath (io/file "test-resources" "pom.xml"))))))
|
||||
|
||||
(deftest uberscript-test
|
||||
(let [tmp-file (java.io.File/createTempFile "uberscript" ".clj")]
|
||||
|
|
|
|||
Loading…
Reference in a new issue