From a47bf8ba13440c9691bf002a5bf687175d9c0937 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 18 Mar 2018 16:05:30 +0100 Subject: Add TAP test structure Copied and modified from: https://github.com/teddywing/git-hook-pre-commit-python-javascript-syntax-linter/blob/efa1909/t/001-setup.t https://github.com/teddywing/git-hook-pre-commit-python-javascript-syntax-linter/blob/f6bb0d3/t/999-teardown.t --- Makefile | 4 ++++ t/001-setup.t | 21 +++++++++++++++++++++ t/999-teardown.t | 14 ++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 Makefile create mode 100644 t/001-setup.t create mode 100644 t/999-teardown.t diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2cab678 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +.PHONY: test + +test: + prove -v diff --git a/t/001-setup.t b/t/001-setup.t new file mode 100644 index 0000000..0e591c4 --- /dev/null +++ b/t/001-setup.t @@ -0,0 +1,21 @@ +#!/usr/bin/env perl -w + +use strict; + +use Test::More; + +system('git init t-git-repo'); +ok !$?; + +chdir 't-git-repo' or die $!; + +system('echo tmp > tmp.txt'); +ok !$?; + +system('git add tmp.txt'); +ok !$?; + +system('git commit -m "Commit"'); +ok !$?; + +done_testing; diff --git a/t/999-teardown.t b/t/999-teardown.t new file mode 100644 index 0000000..e7e8ab2 --- /dev/null +++ b/t/999-teardown.t @@ -0,0 +1,14 @@ +#!/usr/bin/env perl -w + +use strict; + +use Test::More; + +if (!-d 't-git-repo') { + plan skip_all => 'Testing stage already cleaned.'; +} + +system('rm -rf t-git-repo'); +ok !$?; + +done_testing; -- cgit v1.2.3 From 4132e288ba6af49cf726d71785ec1f2ff9f39270 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 18 Mar 2018 16:22:07 +0100 Subject: git-branch-list: Add `clear` command A new sub-command that clears the entire branch list. This makes it easy to remove everything when all the branches in the list are stale (e.g. everything's been merged already). --- git-branch-list | 7 ++++++ t/100-clear-clears-all-branches-from-list.t | 36 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 t/100-clear-clears-all-branches-from-list.t diff --git a/git-branch-list b/git-branch-list index 1e8593c..1468bfe 100755 --- a/git-branch-list +++ b/git-branch-list @@ -64,6 +64,10 @@ function drop_branch () { rm "${DATABASE}.bak" } +function clear_branches () { + : > "$DATABASE" +} + function list_branches () { nl "$DATABASE" } @@ -129,6 +133,9 @@ case "$command" in drop) drop_branch "$2" ;; + clear) + clear_branches + ;; "") list_branches diff --git a/t/100-clear-clears-all-branches-from-list.t b/t/100-clear-clears-all-branches-from-list.t new file mode 100644 index 0000000..952d68a --- /dev/null +++ b/t/100-clear-clears-all-branches-from-list.t @@ -0,0 +1,36 @@ +#!/usr/bin/env perl -w + +use strict; + +use Test::More; + +use File::Spec; + +my $BIN = File::Spec->rel2abs('git-branch-list'); + +chdir 't-git-repo' or die $!; + +system('git branch first'); +ok !$?; + +system("$BIN save first"); +ok !$?; + +system('git branch second'); +ok !$?; + +system("$BIN save second"); +ok !$?; + +system("$BIN clear"); +ok !$?; + +my $branch_list = qx($BIN); +is $branch_list, ''; + + +# Teardown +system('git branch -d first second'); + + +done_testing; -- cgit v1.2.3