From: daniel watson Date: Thu, 5 May 2016 03:16:10 +0000 (-0700) Subject: add pre-commit staging testing X-Git-Url: http://challenge-bot.com/repos?p=flibbertigibbet;a=commitdiff_plain;h=fa24711ecb31e12e224f0bbb57894b803e72fc94 add pre-commit staging testing --- diff --git a/.gitignore b/.gitignore index c53038e..3343893 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ pom.xml.asc /.nrepl-port .hgignore .hg/ +/.config/ diff --git a/makefile b/makefile new file mode 100644 index 0000000..bc6d93c --- /dev/null +++ b/makefile @@ -0,0 +1,29 @@ +# tl;dr AGPLv3+ +# copyright info at bottom + +all:test + +test: + @./test.bash + +test-staged: + @./test-staged.bash + +# flibbertigibbet is a lein new flibbertigibbet project-name +# Copyright (C) 2016 daniel watson + +# This file is part of flibbertigibbet. + +# flibbertigibbet is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# flibbertigibbet is distributed in the hope that it +# will be useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Affero Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with flibbertigibbet. If not, see +# . diff --git a/test-staged.bash b/test-staged.bash new file mode 100755 index 0000000..2dcdd5f --- /dev/null +++ b/test-staged.bash @@ -0,0 +1,59 @@ +#! /usr/bin/env bash +# tl;dr AGPLv3+ +# copyright info at bottom + +set -o nounset +set -o errexit + +GILT_HOOKUP_DEBUG="${GILT_HOOKUP_DEBUG:-}" + +if (( GILT_HOOKUP_DEBUG )); then + set -x + echo "in $0" + pwd +fi + +# create a temp directory to hold just the staged content +# mktemp is used twice here, the first works on gnu, +# the second works on mac +stage_dir=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'` + +# remove the temp staging directory when sigterm, sigint (ctrl-c), +# and when the script exits normally +# the exit status of the script will not be affected by this trap +# when it traps the SIGEXIT signal +# if we're debugging, then leave the testing directory around +# for inspection +if (( ! GILT_HOOKUP_DEBUG )); then + trap 'rm -rf "$stage_dir"' SIGTERM SIGINT EXIT +fi + +# checkout all staged files into temporary staging directory +git checkout-index --prefix="${stage_dir}/" --all \ + && sync + +if (( GILT_HOOKUP_DEBUG )); then + tree "$stage_dir" +fi + +# run make in temporary staging directory +make --directory="$stage_dir" + +# flibbertigibbet is a lein new flibbertigibbet project-name +# Copyright (C) 2016 daniel watson + +# This file is part of flibbertigibbet. + +# flibbertigibbet is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# flibbertigibbet is distributed in the hope that it +# will be useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Affero Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with flibbertigibbet. If not, see +# . diff --git a/test.bash b/test.bash new file mode 100755 index 0000000..e65e993 --- /dev/null +++ b/test.bash @@ -0,0 +1,32 @@ +#! /usr/bin/env bash +# tl;dr AGPLv3+ +# copyright info at bottom + +set -o nounset +set -o errexit + +GILT_HOOKUP_DEBUG="${GILT_HOOKUP_DEBUG:-}" + +if (( GILT_HOOKUP_DEBUG )); then + set -x + echo "in $0" +fi + +# flibbertigibbet is a lein new flibbertigibbet project-name +# Copyright (C) 2016 daniel watson + +# This file is part of flibbertigibbet. + +# flibbertigibbet is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# flibbertigibbet is distributed in the hope that it +# will be useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Affero Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with flibbertigibbet. If not, see +# . diff --git a/test/leiningen/new/flibbertigibbet_test.clj b/test/leiningen/new/flibbertigibbet_test.clj new file mode 100644 index 0000000..8bb6a95 --- /dev/null +++ b/test/leiningen/new/flibbertigibbet_test.clj @@ -0,0 +1,23 @@ +(ns leiningen.new.flibbertigibbet-test + (:require [clojure.test :refer :all] + [leiningen.new.flibbertigibbet :refer :all])) + +(defn safe-delete [file-path] + (if (.exists (clojure.java.io/file file-path)) + (try + (clojure.java.io/delete-file file-path) + (catch Exception e (str "exception: " (.getMessage e)))) + false)) + +(defn delete-directory [directory] + (let [contents (file-seq (clojure.java.io/file directory)) + delete-files (filter #(.isFile %) contents)] + (doseq [file delete-files] + (safe-delete (.getPath file))) + (safe-delete directory))) + +(deftest a-test + (testing "flibbertigibbet should advertise itself, so i know it works" + (is (= "Generating fresh 'lein new' flibbertigibbet project: projecta\n" + (with-out-str (flibbertigibbet "projecta")))) + (delete-directory "./projecta")))