Skip to content

Commit

Permalink
Test fake-git by calling it as a library
Browse files Browse the repository at this point in the history
Instead of as a script
  • Loading branch information
mjmeintjes committed Jun 12, 2024
1 parent e7f3ffa commit e39c2e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
8 changes: 6 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
:paths ["src"]
:aliases
{:main {:main-opts ["-m" "core"]}
:test {:extra-paths ["test"]
:test {:extra-paths ["test" "pkgs"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.86.1355"}
nubank/matcher-combinators {:mvn/version "3.8.8"}}}}}
nubank/matcher-combinators {:mvn/version "3.8.8"}

;; for fake-git tests
babashka/process {:mvn/version "0.5.22"}
cheshire/cheshire {:mvn/version "5.13.0"}}}}}
23 changes: 12 additions & 11 deletions test/integration/fake_git_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
(:require
[clojure.test :refer [deftest is use-fixtures]]
[babashka.fs :as fs]
[babashka.process :as ps]
[cljnix.test-helpers :as h]
[cljnix.nix :as nix]
[matcher-combinators.test]
[clojure.java.shell :as sh]
[clojure.string :as str])
)
[fake-git :as fake-git]))

(defn- run-fake-git [project-dir cmd]
(sh/sh
"bash" "-c"
(str "nix run .#fake-git -- --git-dir " project-dir " " cmd)))
(fake-git/main*
(concat
["--git-dir"
project-dir]

(ps/tokenize cmd))))

(defn- fake-git-test [revs cmd expected get-result]
(fs/with-temp-dir [project-dir {:prefix "gitlibs"}]
Expand All @@ -35,7 +36,7 @@
"tag --sort=v:refname"
["v0.0.1"
"v0.0.2"]
#(-> % :out str/split-lines)))
#(-> % :out)))

(deftest fake-git-rev-parse-tag-test
(fake-git-test
Expand All @@ -45,7 +46,7 @@
:tag "v0.0.2"}]
"rev-parse v0.0.1^{commit}"
["rev1"]
#(-> % :out str/split-lines)))
#(-> % :out)))

(deftest fake-git-rev-parse-short-sha-test
(fake-git-test
Expand All @@ -55,7 +56,7 @@
:tag "v0.0.2"}]
"rev-parse rev2^{commit}"
["rev2abc"]
#(-> % :out str/split-lines)))
#(-> % :out)))

(deftest fake-git-rev-parse-full-sha-test
(fake-git-test
Expand All @@ -65,7 +66,7 @@
:tag "v0.0.2"}]
"rev-parse rev2abc^{commit}"
["rev2abc"]
#(-> % :out str/split-lines)))
#(-> % :out)))

(deftest fake-git-is-ancestor-test
(fake-git-test
Expand Down

0 comments on commit e39c2e2

Please sign in to comment.