Back
with-sh-dir (clj)
(source)macro
(with-sh-dir dir & forms)
Sets the directory for use with sh, see sh for details.
Examples
juxt/jig
(ns jig.git
(:require
jig
[clojure.tools.logging :refer :all]
[clojure.java.shell :as sh])
(:import (jig Lifecycle)))
(deftype GitPull [config]
Lifecycle
(init [_ system]
system)
(start [_ system]
system)
(stop [_ system]
;; We pull the latest system on stop.
(infof "Pulling latest git version")
(let [{:keys [exit out err]}
(if-let [dir (:directory config)]
(sh/with-sh-dir dir
(sh/sh "git" "pull"))
(sh/sh "git" "pull"))]
(cond
(pos? exit) (errorf "Git failed with the following (error %d): %s\n%s" exit out err)
(not (empty? err)) (errorf "Git error: %s" err)))
system))
exercism/clojure
(require '[cheshire.core :as json]
'[clojure.java.io :as io]
'[clojure.java.shell :refer [sh with-sh-dir]]
'[clojure.string :as string])
(doseq [problem ((json/parse-string (slurp "config.json")) "problems")]
(with-sh-dir problem
(sh "mkdir" "-p" "src" "test")
(sh "sh" "-c" "mv *_test.clj test")
(sh "sh" "-c" "mv example.clj src"))
(sh "sh" "-c" "gsed -i '/\\(source\\|test\\)-paths/d' */project.clj"))
benedekfazekas/morpheus
(ns thomasa.morpheus.core-test
(:require [thomasa.morpheus.core :as m]
[clojure.edn :as edn]
[clojure.test :as t]
[loom.attr :as attr]
[clojure.java.shell :as sh]))
(t/deftest analysis-test
(let [morph-temp-dir (doto (java.io.File/createTempFile "morpheus" "") (.delete) (.mkdirs))]
(println (format "temp dir: %s" (str morph-temp-dir)))
(sh/with-sh-dir morph-temp-dir
(sh/sh "git" "clone" "--depth" "1" "git@github.com:benedekfazekas/mranderson.git" "--branch" "v0.5.3" "--single-branch"))
(let [mranderson-053-analysis (m/lint-analysis [(format "%s/mranderson/src" (str morph-temp-dir))])]
(t/is (=
#{:namespace-definitions
:namespace-usages
:var-definitions
:var-usages
:keywords}
(set (keys mranderson-053-analysis)))
"analysis should have the sections morpheus wants to work with")
(t/is (= 94 (count (:var-definitions mranderson-053-analysis))) "analysis should contain the right amount of var defs")
(t/is (= 1194 (count (:var-usages mranderson-053-analysis))) "analysis should contain the right amount of var usages"))))
titonbarua/shadow-cljs-gjs-target
(ns shadow-cljs-gjs-target.core-test
(:require [clojure.test :refer :all]
[shadow-cljs-gjs-target.core :refer :all]
[clojure.java.shell :refer [sh with-sh-dir]]
[clojure.string :as str]
[clojure.java.io :as io]))
(deftest ^:headless simple-demo-test
(testing "Simple demo dev-build compilation ..."
(with-sh-dir "examples/simple"
(let [cleanup (fn [] (sh "rm" "-r"
"./simple.js"
"./.shadow-cljs/"
"./jslibs/"
"./.cpcache/"))]
(cleanup)
(let [{:keys [exit out err]}
(sh "clojure" "-m" "shadow.cljs.devtools.cli" "compile" "app")]
(println out)
(println err)
(is (= exit 0)
"Compiler should report success.")
#_(testing "Simple demo release-build compilation ..."
(with-sh-dir "examples/simple"
(let [cleanup (fn [] (sh "rm" "-r" "./simple.js" "./.shadow-cljs/" "./.cpcache/"))]
(cleanup)
(let [{:keys [exit]}
(sh "clojure" "-m" "shadow.cljs.devtools.cli" "release" "app")]
(deftest gtk-offscreen-test
(testing "gtk-offscreen demo dev-build compilation ..."
(with-sh-dir "examples/gtk-offscreen"
(let [cleanup (fn [] (sh "rm" "-r"
"./gtk-offscreen.js"
"./.shadow-cljs/"
"./jslibs/"
"./.cpcache/"
"window.png"))]
(cleanup)
(let [{:keys [exit out err]}
(sh "clojure" "-m" "shadow.cljs.devtools.cli" "compile" "app")]
(println out)
(println err)
(is (= exit 0)
"Compiler should report success.")
frenchy64/fully-satisfies
(ns io.github.frenchy64.fully-satisfies.non-leaky-macros.clojure.java.shell
"Implementations of clojure.java.test macros that don't leak implementation details."
(:require [clojure.java.shell :as sh]))
(defmacro non-leaky-with-sh-dir
"Like clojure.java.shell/with-sh-dir, except body does not leak try/catch syntax."
[dir & forms]
`(sh/with-sh-dir ~dir
(do ~@forms)))
(defmacro with-sh-dir
[& args]
`(non-leaky-with-sh-dir ~@args))