From f9d44e5e693003172fdd91790ee78a6d583235c5 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 4 Feb 2017 20:23:36 -0600 Subject: [PATCH 001/151] migrate prove tests to bats The Perl scripts were only running shell commands anyway; this seemed a more natural fit. Since bash does not capture trailing newlines, there is a change to the "vcsh status" check from 300-add.t to ensure the empty line is/isn't printed according to the terseness setting. --- Makefile | 6 ++-- bats/environment.bash | 24 +++++++++++++++ bats/prove.bats | 68 +++++++++++++++++++++++++++++++++++++++++++ t/000-tear-env.t | 17 ----------- t/001-setup-env.t | 19 ------------ t/100-init.t | 55 ---------------------------------- t/300-add.t | 39 ------------------------- t/950-delete.t | 19 ------------ t/999-tear-env.t | 17 ----------- 9 files changed, 96 insertions(+), 168 deletions(-) create mode 100644 bats/environment.bash create mode 100644 bats/prove.bats delete mode 100644 t/000-tear-env.t delete mode 100644 t/001-setup-env.t delete mode 100644 t/100-init.t delete mode 100644 t/300-add.t delete mode 100644 t/950-delete.t delete mode 100644 t/999-tear-env.t diff --git a/Makefile b/Makefile index b9154e7f..34ee1a82 100644 --- a/Makefile +++ b/Makefile @@ -44,8 +44,10 @@ purge: uninstall rmdir -p --ignore-fail-on-non-empty $(DESTDIR)$(ZSHDIR) test: - @if which git > /dev/null; then : ; else echo "'git' not found, exiting..." ; exit 1; fi - @if which prove > /dev/null; then prove; else echo "'prove' not found; not running tests"; fi + @if ! which git > /dev/null; then echo "'git' not found, exiting..." ; exit 1; fi + @if ! which bats > /dev/null; then echo "'bats' not found; not running tests"; exit 1; fi + [ -d "vcsh_testrepo.git" ] || git clone --mirror https://github.com/djpohly/vcsh_testrepo.git + TESTREPO=$(PWD)/vcsh_testrepo.git TESTREPONAME=vcsh_testrepo bats ./bats moo: @which cowsay >/dev/null 2>&1 && cowsay "I hope you're happy now..." diff --git a/bats/environment.bash b/bats/environment.bash new file mode 100644 index 00000000..7f83fe2d --- /dev/null +++ b/bats/environment.bash @@ -0,0 +1,24 @@ +setup() { + VCSH="$BATS_TEST_DIRNAME/../vcsh" + export LC_ALL=C + + # Test repository. For faster tests, you can create a local mirror and + # use that instead. + : ${TESTREPO:='https://github.com/djpohly/vcsh_testrepo.git'} + : ${TESTREPONAME:='vcsh_testrepo'} + TESTM1=master + TESTM2=master2 + TESTBR1=branch1 + TESTBR2=branch2 + TESTBRX=conflict + + BATS_TESTDIR=$(mktemp -d -p "$BATS_TMPDIR") + export HOME=$BATS_TESTDIR + export XDG_CONFIG_HOME=$HOME/.config + cd +} + +teardown() { + cd / + rm -rf "$BATS_TESTDIR" +} diff --git a/bats/prove.bats b/bats/prove.bats new file mode 100644 index 00000000..5332b23e --- /dev/null +++ b/bats/prove.bats @@ -0,0 +1,68 @@ +load environment + +@test "100-init.t" { + run "$VCSH" status + [ "$status" -eq 0 ] + [ "$output" = "" ] + + run "$VCSH" init test1 + [ "$status" -eq 0 ] + [ "$output" = "Initialized empty shared Git repository in $HOME/.config/vcsh/repo.d/test1.git/" ] + + run "$VCSH" status + echo "'$output'" + [ "$status" -eq 0 ] + [ "$output" = 'test1:' ] + + cd "$HOME/.config/vcsh/repo.d/test1.git/" + test -f 'HEAD' + test -f 'config' + test -f 'description' + test -d 'hooks' + test -d 'info' + test -d 'objects' + test -d 'refs' + + test -f 'hooks/applypatch-msg.sample' + test -f 'hooks/commit-msg.sample' + test -f 'hooks/post-update.sample' + test -f 'hooks/pre-applypatch.sample' + test -f 'hooks/pre-commit.sample' + test -f 'hooks/pre-push.sample' + test -f 'hooks/pre-rebase.sample' + test -f 'hooks/prepare-commit-msg.sample' + test -f 'hooks/update.sample' + + test -f 'info/exclude' + + test -d 'objects/info' + test -d 'objects/pack' + + test -d 'refs/heads' + test -d 'refs/tags' +} + +@test "300-add.t" { + "$VCSH" init test1 + "$VCSH" init test2 + + touch 'a' + "$VCSH" test2 add 'a' + + run "$VCSH" status + [ "$status" -eq 0 ] + [ "$output" = $'test1:\n\ntest2:\nA a' ] + + run "$VCSH" status --terse + [ "$status" -eq 0 ] + [ "$output" = $'test2:\nA a' ] +} + +@test "950-delete.t" { + "$VCSH" init test1 + echo 'Yes, do as I say' | run "$VCSH" delete test1 + + run "$VCSH" status + [ "$status" -eq 0 ] + [ "$output" = '' ] +} diff --git a/t/000-tear-env.t b/t/000-tear-env.t deleted file mode 100644 index 6cb384f1..00000000 --- a/t/000-tear-env.t +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use Shell::Command; -use Test::Most; - -chdir 't' or die $!; - -if (!-d 'etc') { - plan skip_all => 'No need to tear down previous env.'; -} - -ok rm_rf 'etc'; - -done_testing; diff --git a/t/001-setup-env.t b/t/001-setup-env.t deleted file mode 100644 index fb59f058..00000000 --- a/t/001-setup-env.t +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use Test::Most; - -system ("mkdir -p t/etc"); -ok !$?; - -system ("mkdir -p t/etc/.vcsh_home"); -ok !$?; - -chdir 't/etc/' or die $!; - -system ("ln -s '../../vcsh'"); -ok !$?; - -done_testing; diff --git a/t/100-init.t b/t/100-init.t deleted file mode 100644 index 74facc02..00000000 --- a/t/100-init.t +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/perl - -BEGIN { $ENV{LC_ALL} = 'C' } - -use strict; -use warnings; - -use Cwd 'abs_path'; -use Test::Most; - -chdir 't/etc/' or die $!; - -$ENV{'HOME'} = abs_path ('.vcsh_home'); - -my $output = `./vcsh status`; - -ok $output eq "", 'No repos set up yet.'; - -$output = `./vcsh init test1`; - -ok $output eq "Initialized empty shared Git repository in " . $ENV{'HOME'} . "/.config/vcsh/repo.d/test1.git/\n"; - -$output = `./vcsh status`; - -ok $output eq "test1:\n\n", 'Our new repo is there'; - -chdir $ENV{"HOME"} . '/.config/vcsh/repo.d/test1.git/' or die $!; - -ok -f 'HEAD'; -ok -f 'config'; -ok -f 'description'; -ok -d 'hooks'; -ok -d 'info'; -ok -d 'objects'; -ok -d 'refs'; - -ok -f 'hooks/applypatch-msg.sample'; -ok -f 'hooks/commit-msg.sample'; -ok -f 'hooks/post-update.sample'; -ok -f 'hooks/pre-applypatch.sample'; -ok -f 'hooks/pre-commit.sample'; -ok -f 'hooks/pre-push.sample'; -ok -f 'hooks/pre-rebase.sample'; -ok -f 'hooks/prepare-commit-msg.sample'; -ok -f 'hooks/update.sample'; - -ok -f 'info/exclude'; - -ok -d 'objects/info'; -ok -d 'objects/pack'; - -ok -d 'refs/heads'; -ok -d 'refs/tags'; - -done_testing; diff --git a/t/300-add.t b/t/300-add.t deleted file mode 100644 index 4acd0a2c..00000000 --- a/t/300-add.t +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use Cwd 'abs_path'; - -use Shell::Command; -use Test::Most; - -chdir 't/etc/' or die $!; - -$ENV{'HOME'} = abs_path ('.vcsh_home'); - -chdir '.vcsh_home' or die $!; - -eval { - touch 'a'; -}; - -die $@ if $@; - -system (".././vcsh test1 add 'a'"); - -my $output = `.././vcsh status`; - -ok $output eq "test1: -A a - -", 'Adding a file works'; - -$output = `.././vcsh status --terse`; - -ok $output eq "test1: -A a -", 'Terse output works'; - -done_testing; - diff --git a/t/950-delete.t b/t/950-delete.t deleted file mode 100644 index cd078714..00000000 --- a/t/950-delete.t +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use Cwd 'abs_path'; -use Test::Most; - -chdir 't/etc/' or die $!; - -$ENV{'HOME'} = abs_path ('.vcsh_home'); - -system ("echo 'Yes, do as I say' | ./vcsh delete test1"); - -my $output = `./vcsh status`; - -ok $output eq "", 'No repos set up anymore.'; - -done_testing; diff --git a/t/999-tear-env.t b/t/999-tear-env.t deleted file mode 100644 index afe261a8..00000000 --- a/t/999-tear-env.t +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use Shell::Command; -use Test::Most; - -chdir 't' or die $!; - -if (!-d 'etc') { - plan skip_all => 'No need to tear previous env.'; -} - -ok rm_rf 'etc'; - -done_testing; From 413646d6ba0226946a2ddafc80c01d09bf3b9d85 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 4 Feb 2017 20:53:41 -0600 Subject: [PATCH 002/151] Bats tests for help command --- bats/help.bats | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 bats/help.bats diff --git a/bats/help.bats b/bats/help.bats new file mode 100644 index 00000000..bb183a7f --- /dev/null +++ b/bats/help.bats @@ -0,0 +1,55 @@ +load environment + +@test "Help command succeeds" { + "$VCSH" help +} +@test "Help command writes to stderr and not stdout" { + "$VCSH" help 2>&1 1>/dev/null | + grep -q '' + ! "$VCSH" help 2>/dev/null | + grep -q '' +} +@test "Help command prints usage on first line" { + run "$VCSH" help + [[ "$output" = 'usage: '* ]] +} + +@test "Help command can be abbreviated (hel, he)" { + run "$VCSH" help + local good=$output + + run "$VCSH" hel + [ "$status" -eq 0 ] + [ "$output" = "$good" ] + + run "$VCSH" he + [ "$status" -eq 0 ] + [ "$output" = "$good" ] +} + +# Help should explain each command. (Note: adjust the help_check function if +# the format of help output changes.) +help_check() { + "$VCSH" help 2>&1 | + grep -q "^ $1\\b" +} + +@test "Help text includes clone command" { help_check clone; } +@test "Help text includes commit command" { help_check commit; } +@test "Help text includes delete command" { help_check delete; } +@test "Help text includes enter command" { help_check enter; } +@test "Help text includes foreach command" { help_check foreach; } +@test "Help text includes help command" { help_check help; } +@test "Help text includes init command" { help_check init; } +@test "Help text includes list command" { help_check list; } +@test "Help text includes list-tracked command" { help_check list-tracked; } +@test "Help text includes list-untracked command" { help_check list-untracked; } +@test "Help text includes pull command" { help_check pull; } +@test "Help text includes push command" { help_check push; } +@test "Help text includes rename command" { help_check rename; } +@test "Help text includes run command" { help_check run; } +@test "Help text includes status command" { help_check status; } +@test "Help text includes upgrade command" { help_check upgrade; } +@test "Help text includes version command" { help_check version; } +@test "Help text includes which command" { help_check which; } +@test "Help text includes write-gitignore command" { help_check write-gitignore; } From bb2fa3a64312661bf38e3c42e083e8846b857d06 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 4 Feb 2017 21:28:55 -0600 Subject: [PATCH 003/151] add tests for version command --- bats/version.bats | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 bats/version.bats diff --git a/bats/version.bats b/bats/version.bats new file mode 100644 index 00000000..2473aeaf --- /dev/null +++ b/bats/version.bats @@ -0,0 +1,11 @@ +load environment + +@test "Version command succeeds" { + "$VCSH" version +} + +@test "Version command prints vcsh and git versions" { + run "$VCSH" version + [[ "${lines[0]}" = 'vcsh '[0-9]* ]] + [[ "${lines[1]}" = 'git version '[0-9]* ]] +} From 575718516fa769271a2db88bec31adc9ef5ed478 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 5 Feb 2017 00:11:01 -0600 Subject: [PATCH 004/151] add tests for list command --- bats/environment.bash | 4 ++ bats/list.bats | 149 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 bats/list.bats diff --git a/bats/environment.bash b/bats/environment.bash index 7f83fe2d..164ecc23 100644 --- a/bats/environment.bash +++ b/bats/environment.bash @@ -19,6 +19,10 @@ setup() { } teardown() { + # Don't saw off the branch you're sitting on cd / + + # Make sure removal will succeed even if we have altered permissions + chmod -R a+rwx "$BATS_TESTDIR" rm -rf "$BATS_TESTDIR" } diff --git a/bats/list.bats b/bats/list.bats new file mode 100644 index 00000000..39ad8768 --- /dev/null +++ b/bats/list.bats @@ -0,0 +1,149 @@ +load environment + +@test "List command succeeds" { + "$VCSH" list +} + +@test "List command creates default support directories" { + "$VCSH" list + test -d .config + test -d .config/vcsh + test -d .config/vcsh/repo.d + test -d .gitignore.d +} + +@test "List command creates \$VCSH_REPO_D" { + VCSH_REPO_D="$PWD/foo/bar" "$VCSH" list + test -d foo + test -d foo/bar + test -d .gitignore.d +} + +@test "List command creates .gitignore.d in \$VCSH_BASE" { + VCSH_BASE="$PWD/foo/bar" "$VCSH" list + test -d .config + test -d .config/vcsh + test -d .config/vcsh/repo.d + test -d foo + test -d foo/bar + test -d foo/bar/.gitignore.d +} + +@test "List command creates .gitignore.d with VCSH_GITIGNORE=recursive" { + VCSH_GITIGNORE=recursive "$VCSH" list + test -d .config + test -d .config/vcsh + test -d .config/vcsh/repo.d + test -d .gitignore.d +} + +@test "List command does not create .gitignore.d with VCSH_GITIGNORE=none" { + VCSH_GITIGNORE=none "$VCSH" list + test -d .config + test -d .config/vcsh + test -d .config/vcsh/repo.d + ! test -d .gitignore.d +} + +@test "List command gives correct output for no repos" { + run "$VCSH" list + [ "$output" = '' ] +} + +@test "List command gives correct output for empty repo directory" { + # XXX should vcsh fail if this is not a Git repository? + mkdir -p .config/vcsh/repo.d/foo.git + run "$VCSH" list + [ "$output" = $'foo' ] +} + +@test "List command gives correct output for non-bare repo" { + # XXX should vcsh fail if this is not a bare repository? + mkdir -p .config/vcsh/repo.d + git init .config/vcsh/repo.d/foo.git + run "$VCSH" list + [ "$output" = $'foo' ] +} + +@test "List command gives correct output for one repo (git init)" { + mkdir -p .config/vcsh/repo.d + git init --bare .config/vcsh/repo.d/foo.git + run "$VCSH" list + [ "$output" = $'foo' ] +} + +@test "List command gives correct output for one repo (vcsh init)" { + "$VCSH" init foo + run "$VCSH" list + [ "$output" = $'foo' ] +} + +@test "List command gives correct output for three repos (git init)" { + # XXX should this fail if these are not bare repositories? + mkdir -p .config/vcsh/repo.d + git init --bare .config/vcsh/repo.d/foo.git + git init --bare .config/vcsh/repo.d/bar.git + git init --bare .config/vcsh/repo.d/baz.git + run "$VCSH" list + [ "$output" = $'bar\nbaz\nfoo' ] +} + +@test "List command gives correct output for three repos (vcsh init)" { + # XXX should this fail if these are not bare repositories? + mkdir -p .config/vcsh/repo.d + "$VCSH" init foo + "$VCSH" init bar + "$VCSH" init baz + run "$VCSH" list + [ "$output" = $'bar\nbaz\nfoo' ] +} + +@test "List command only lists directories" { + mkdir -p .config/vcsh/repo.d + touch .config/vcsh/repo.d/foo.git + mkfifo .config/vcsh/repo.d/bar.git + + run "$VCSH" list + [ "$output" = '' ] + + "$VCSH" init baz + run "$VCSH" list + [ "$output" = 'baz' ] +} + +@test "List command only lists directories ending in '.git'" { + mkdir -p .config/vcsh/repo.d + git init --bare .config/vcsh/repo.d/foo + git init --bare .config/vcsh/repo.d/bar + git init --bare .config/vcsh/repo.d/baz.git + + run "$VCSH" list + [ "$output" = 'baz' ] +} + +@test "List command does not list unreadable repos" { + "$VCSH" init foo + + run "$VCSH" list + [ "$output" = 'foo' ] + + chmod a-r .config/vcsh/repo.d/foo.git + run "$VCSH" list + [ "$output" = '' ] +} + +@test "List command respects \$VCSH_REPO_D (git init)" { + mkdir -p foo/bar + git init --bare foo/bar/hello.git + + VCSH_REPO_D="$PWD/foo/bar" run "$VCSH" list + [ "$output" = 'hello' ] +} + +@test "List command respects \$VCSH_REPO_D (vcsh init)" { + mkdir -p foo/bar + VCSH_REPO_D="$PWD/foo/bar" "$VCSH" init hello + + VCSH_REPO_D="$PWD/foo/bar" run "$VCSH" list + [ "$output" = 'hello' ] +} From 7167d7e0ec0792db075f244bdbafe3db17426675 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 5 Feb 2017 00:15:33 -0600 Subject: [PATCH 005/151] update command list from vcsh source --- bats/help.bats | 1 + 1 file changed, 1 insertion(+) diff --git a/bats/help.bats b/bats/help.bats index bb183a7f..37228058 100644 --- a/bats/help.bats +++ b/bats/help.bats @@ -43,6 +43,7 @@ help_check() { @test "Help text includes init command" { help_check init; } @test "Help text includes list command" { help_check list; } @test "Help text includes list-tracked command" { help_check list-tracked; } +@test "Help text includes list-tracked-by command" { help_check list-tracked-by; } @test "Help text includes list-untracked command" { help_check list-untracked; } @test "Help text includes pull command" { help_check pull; } @test "Help text includes push command" { help_check push; } From 90a549f1b70305894c6c70c08a9cd38853f53950 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 5 Feb 2017 16:22:45 -0600 Subject: [PATCH 006/151] getting started on init tests --- bats/environment.bash | 34 +++++++++++++++++++++ bats/init.bats | 71 +++++++++++++++++++++++++++++++++++++++++++ bats/prove.bats | 27 ---------------- 3 files changed, 105 insertions(+), 27 deletions(-) create mode 100644 bats/init.bats diff --git a/bats/environment.bash b/bats/environment.bash index 164ecc23..6f272096 100644 --- a/bats/environment.bash +++ b/bats/environment.bash @@ -12,6 +12,9 @@ setup() { TESTBR2=branch2 TESTBRX=conflict + # Other things used in tests + GITVERSION=$(git version) + BATS_TESTDIR=$(mktemp -d -p "$BATS_TMPDIR") export HOME=$BATS_TESTDIR export XDG_CONFIG_HOME=$HOME/.config @@ -26,3 +29,34 @@ teardown() { chmod -R a+rwx "$BATS_TESTDIR" rm -rf "$BATS_TESTDIR" } + +is_git_repo() { + test -d "$1" + + cd "$1" + test -f HEAD + test -f config + test -f description + test -d hooks + test -d info + test -d objects + test -d refs + + test -f hooks/applypatch-msg.sample + test -f hooks/commit-msg.sample + test -f hooks/post-update.sample + test -f hooks/pre-applypatch.sample + test -f hooks/pre-commit.sample + test -f hooks/pre-push.sample + test -f hooks/pre-rebase.sample + test -f hooks/prepare-commit-msg.sample + test -f hooks/update.sample + + test -f info/exclude + + test -d objects/info + test -d objects/pack + + test -d refs/heads + test -d refs/tags +} diff --git a/bats/init.bats b/bats/init.bats new file mode 100644 index 00000000..d03ac37c --- /dev/null +++ b/bats/init.bats @@ -0,0 +1,71 @@ +load environment + +@test "Init command succeeds" { + "$VCSH" init foo +} + +@test "Debug output for init command includes git version" { + "$VCSH" -d init foo | grep -F "$GITVERSION" +} + +@test "Init command takes exactly one parameter" { + ! "$VCSH" init + ! "$VCSH" init foo bar + "$VCSH" init baz +} + +@test "Init command creates default support directories" { + "$VCSH" init foo + test -d .config + test -d .config/vcsh + test -d .config/vcsh/repo.d + test -d .gitignore.d +} + +@test "Init command creates correct Git repository" { + "$VCSH" init test1 + + cd "$HOME" + test -d .config + test -d .config/vcsh + test -d .config/vcsh/repo.d + test -d .config/vcsh/repo.d/test1.git + + is_git_repo "$HOME/.config/vcsh/repo.d/test1.git" +} + +@test "Init command creates \$VCSH_REPO_D" { + VCSH_REPO_D="$PWD/foo/bar" "$VCSH" init foo + test -d foo + test -d foo/bar + test -d .gitignore.d +} + +@test "Init command creates .gitignore.d with VCSH_GITIGNORE=exact" { + VCSH_GITIGNORE=exact "$VCSH" init foo + test -d .gitignore.d +} + +@test "Init command creates .gitignore.d with VCSH_GITIGNORE=recursive" { + VCSH_GITIGNORE=recursive "$VCSH" init foo + test -d .gitignore.d +} + +@test "Init command does not create .gitignore.d with VCSH_GITIGNORE=none" { + VCSH_GITIGNORE=none "$VCSH" init foo + ! test -d .gitignore.d +} + +@test "Init command fails with invalid VCSH_GITIGNORE" { + ! VCSH_GITIGNORE=nonsense "$VCSH" init foo +} + +@test "Init command creates .gitignore.d in \$VCSH_BASE" { + VCSH_BASE="$PWD/foo/bar" "$VCSH" init foo + test -d .config + test -d .config/vcsh + test -d .config/vcsh/repo.d + test -d foo + test -d foo/bar + test -d foo/bar/.gitignore.d +} diff --git a/bats/prove.bats b/bats/prove.bats index 5332b23e..1450b3fe 100644 --- a/bats/prove.bats +++ b/bats/prove.bats @@ -13,33 +13,6 @@ load environment echo "'$output'" [ "$status" -eq 0 ] [ "$output" = 'test1:' ] - - cd "$HOME/.config/vcsh/repo.d/test1.git/" - test -f 'HEAD' - test -f 'config' - test -f 'description' - test -d 'hooks' - test -d 'info' - test -d 'objects' - test -d 'refs' - - test -f 'hooks/applypatch-msg.sample' - test -f 'hooks/commit-msg.sample' - test -f 'hooks/post-update.sample' - test -f 'hooks/pre-applypatch.sample' - test -f 'hooks/pre-commit.sample' - test -f 'hooks/pre-push.sample' - test -f 'hooks/pre-rebase.sample' - test -f 'hooks/prepare-commit-msg.sample' - test -f 'hooks/update.sample' - - test -f 'info/exclude' - - test -d 'objects/info' - test -d 'objects/pack' - - test -d 'refs/heads' - test -d 'refs/tags' } @test "300-add.t" { From 45b7975cee69000719fe44b0645a471a325d2897 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 5 Feb 2017 16:38:30 -0600 Subject: [PATCH 007/151] use git-rev-parse --resolve-git-dir What do you know, Git does this for us. --- bats/environment.bash | 31 ------------------------------- bats/init.bats | 2 +- 2 files changed, 1 insertion(+), 32 deletions(-) diff --git a/bats/environment.bash b/bats/environment.bash index 6f272096..c40cf1f5 100644 --- a/bats/environment.bash +++ b/bats/environment.bash @@ -29,34 +29,3 @@ teardown() { chmod -R a+rwx "$BATS_TESTDIR" rm -rf "$BATS_TESTDIR" } - -is_git_repo() { - test -d "$1" - - cd "$1" - test -f HEAD - test -f config - test -f description - test -d hooks - test -d info - test -d objects - test -d refs - - test -f hooks/applypatch-msg.sample - test -f hooks/commit-msg.sample - test -f hooks/post-update.sample - test -f hooks/pre-applypatch.sample - test -f hooks/pre-commit.sample - test -f hooks/pre-push.sample - test -f hooks/pre-rebase.sample - test -f hooks/prepare-commit-msg.sample - test -f hooks/update.sample - - test -f info/exclude - - test -d objects/info - test -d objects/pack - - test -d refs/heads - test -d refs/tags -} diff --git a/bats/init.bats b/bats/init.bats index d03ac37c..a6008a88 100644 --- a/bats/init.bats +++ b/bats/init.bats @@ -31,7 +31,7 @@ load environment test -d .config/vcsh/repo.d test -d .config/vcsh/repo.d/test1.git - is_git_repo "$HOME/.config/vcsh/repo.d/test1.git" + git rev-parse --resolve-git-dir "$HOME/.config/vcsh/repo.d/test1.git" } @test "Init command creates \$VCSH_REPO_D" { From 217659075de2b60e0703038b61c13f926675ee3f Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 7 Feb 2017 17:55:05 -0600 Subject: [PATCH 008/151] skip failing doc test --- bats/help.bats | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bats/help.bats b/bats/help.bats index 37228058..6d24c6bb 100644 --- a/bats/help.bats +++ b/bats/help.bats @@ -43,7 +43,11 @@ help_check() { @test "Help text includes init command" { help_check init; } @test "Help text includes list command" { help_check list; } @test "Help text includes list-tracked command" { help_check list-tracked; } -@test "Help text includes list-tracked-by command" { help_check list-tracked-by; } +@test "Help text includes list-tracked-by command" { + skip + # FIXME + help_check list-tracked-by; +} @test "Help text includes list-untracked command" { help_check list-untracked; } @test "Help text includes pull command" { help_check pull; } @test "Help text includes push command" { help_check push; } From 49749a1a8bbb18c3145ab9b5d00c1ce338a9c479 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 7 Feb 2017 17:55:59 -0600 Subject: [PATCH 009/151] better unit tests for list and part of init --- bats/environment.bash | 21 ++++- bats/init.bats | 170 ++++++++++++++++++++++++++++++++-------- bats/list.bats | 175 +++++++++++++++--------------------------- 3 files changed, 218 insertions(+), 148 deletions(-) diff --git a/bats/environment.bash b/bats/environment.bash index c40cf1f5..7f4c2cf4 100644 --- a/bats/environment.bash +++ b/bats/environment.bash @@ -2,6 +2,15 @@ setup() { VCSH="$BATS_TEST_DIRNAME/../vcsh" export LC_ALL=C + # Ensure behavior/output isn't affected by outside variables + # (We'll have to assume things like PWD and PATH are sane) + export VCSH_DEBUG= + PS4='+ ' + + # XXX Currently the /etc/vcsh/config file can affect testcases. + # Perhaps it should be ignored if one exists in $XDG_CONFIG_HOME or was + # specified with -c? + # Test repository. For faster tests, you can create a local mirror and # use that instead. : ${TESTREPO:='https://github.com/djpohly/vcsh_testrepo.git'} @@ -15,9 +24,14 @@ setup() { # Other things used in tests GITVERSION=$(git version) + # Clear out environment variables that affect VCSH behavior + unset VCSH_OPTION_CONFIG VCSH_REPO_D VCSH_HOOK_D VCSH_OVERLAY_D + unset VCSH_BASE VCSH_GITIGNORE VCSH_GITATTRIBUTES VCSH_WORKTREE + unset XDG_CONFIG_HOME + + # Make a directory for testing and make it $HOME BATS_TESTDIR=$(mktemp -d -p "$BATS_TMPDIR") export HOME=$BATS_TESTDIR - export XDG_CONFIG_HOME=$HOME/.config cd } @@ -29,3 +43,8 @@ teardown() { chmod -R a+rwx "$BATS_TESTDIR" rm -rf "$BATS_TESTDIR" } + +num_gitrepos() { + # Prints the number of apparent Git repositories below $1 + find "$1" -mindepth 1 -type d -name '*.git' | wc -l +} diff --git a/bats/init.bats b/bats/init.bats index a6008a88..0259f074 100644 --- a/bats/init.bats +++ b/bats/init.bats @@ -4,62 +4,127 @@ load environment "$VCSH" init foo } -@test "Debug output for init command includes git version" { - "$VCSH" -d init foo | grep -F "$GITVERSION" -} - @test "Init command takes exactly one parameter" { ! "$VCSH" init ! "$VCSH" init foo bar "$VCSH" init baz } -@test "Init command creates default support directories" { - "$VCSH" init foo - test -d .config - test -d .config/vcsh - test -d .config/vcsh/repo.d - test -d .gitignore.d +@test "Init command fails if repository already exists" { + "$VCSH" init exists + ! "$VCSH" init exists } -@test "Init command creates correct Git repository" { - "$VCSH" init test1 +@test "Init command respects alternate \$VCSH_REPO_D" { + VCSH_REPO_D="$PWD/foo" "$VCSH" init samename + VCSH_REPO_D="$PWD/bar" "$VCSH" init samename +} - cd "$HOME" - test -d .config - test -d .config/vcsh - test -d .config/vcsh/repo.d - test -d .config/vcsh/repo.d/test1.git +@test "Init command respects alternate \$XDG_CONFIG_HOME" { + XDG_CONFIG_HOME="$PWD/foo" "$VCSH" init samename + XDG_CONFIG_HOME="$PWD/bar" "$VCSH" init samename +} - git rev-parse --resolve-git-dir "$HOME/.config/vcsh/repo.d/test1.git" +@test "Init command respects alternate \$HOME" { + HOME="$PWD/foo" "$VCSH" init samename + HOME="$PWD/bar" "$VCSH" init samename } -@test "Init command creates \$VCSH_REPO_D" { - VCSH_REPO_D="$PWD/foo/bar" "$VCSH" init foo - test -d foo - test -d foo/bar - test -d .gitignore.d +@test "Debug output includes git version" { + "$VCSH" -d init foo |& grep -q 'git version [0-9]' + "$VCSH" -d list |& grep -q 'git version [0-9]' + # XXX add more? +} + +@test "Init command can be abbreviated 'ini'/'in'" { + "$VCSH" ini test1 + "$VCSH" in test2 + + run "$VCSH" list + [ "$status" -eq 0 ] + [ "$output" = $'test1\ntest2' ] +} + +@test "\$VCSH_REPO_D overrides \$XDG_CONFIG_HOME and \$HOME for init" { + HOME="$PWD/foo" "$VCSH" init samename1 + XDG_CONFIG_HOME="$PWD/bar" "$VCSH" init samename2 + + HOME="$PWD/foo" XDG_CONFIG_HOME="$PWD/bar" VCSH_REPO_D="$PWD/baz" "$VCSH" init samename1 + HOME="$PWD/foo" XDG_CONFIG_HOME="$PWD/bar" VCSH_REPO_D="$PWD/baz" "$VCSH" init samename2 } -@test "Init command creates .gitignore.d with VCSH_GITIGNORE=exact" { - VCSH_GITIGNORE=exact "$VCSH" init foo - test -d .gitignore.d +@test "\$XDG_CONFIG_HOME overrides \$HOME for init" { + HOME="$PWD/foo" "$VCSH" init samename + HOME="$PWD/foo" XDG_CONFIG_HOME="$PWD/bar" "$VCSH" init samename } -@test "Init command creates .gitignore.d with VCSH_GITIGNORE=recursive" { - VCSH_GITIGNORE=recursive "$VCSH" init foo - test -d .gitignore.d +@test "Init command marks repository with vcsh.vcsh=true" { + # Too internal to implementation? If another command verifies + # vcsh.vcsh, use that instead of git config. + + "$VCSH" init test1 + + run "$VCSH" run test1 git config vcsh.vcsh + [ "$status" -eq 0 ] + [ "$output" = "true" ] } -@test "Init command does not create .gitignore.d with VCSH_GITIGNORE=none" { - VCSH_GITIGNORE=none "$VCSH" init foo - ! test -d .gitignore.d +@test "Files created by init are not readable by other users" { + # verifies commit e220a61 + "$VCSH" init foo + run find "$PWD" -type f -perm /g+rwx,o+rwx + [ "$output" = '' ] } -@test "Init command fails with invalid VCSH_GITIGNORE" { +@test "Init command adds matching gitignore.d files" { + mkdir -p .gitattributes.d .gitignore.d + touch .gitattributes.d/test1 .gitignore.d/test1 + + VCSH_GITIGNORE=exact "$VCSH" init test1 + "$VCSH" status test1 | grep -Fqx 'A .gitignore.d/test1' +} + +@test "Init command creates new Git repository" { + run num_gitrepos "$PWD" + [ "$output" = '0' ] + + for i in $(seq 5); do + "$VCSH" init "test$i" + run num_gitrepos "$PWD" + [ "$output" = "$i" ] + done +} + +@test "VCSH_GITIGNORE variable is validated" { + ! VCSH_GITIGNORE=x "$VCSH" init foo ! VCSH_GITIGNORE=nonsense "$VCSH" init foo + ! VCSH_GITIGNORE=fhqwhgads "$VCSH" init foo +} + +@test "Init command sets core.excludesfile with VCSH_GITIGNORE=exact" { + # XXX test instead by making sure files are actually excluded, not by + # reading config option + VCSH_GITIGNORE=exact "$VCSH" init test1 + run "$VCSH" run test1 git config core.excludesfile + [ "$output" = ".gitignore.d/test1" ] +} + +@test "Init command sets core.excludesfile with VCSH_GITIGNORE=recursive" { + # XXX test instead by making sure files are actually excluded, not by + # reading config option + VCSH_GITIGNORE=recursive "$VCSH" init test1 + run "$VCSH" run test1 git config core.excludesfile + [ "$output" = ".gitignore.d/test1" ] } +@test "Init command does not set core.excludesfile with VCSH_GITIGNORE=none" { + VCSH_GITIGNORE=none "$VCSH" init test1 + run "$VCSH" run test1 git config core.excludesfile + [ "$status" -ne 0 ] +} + +# ----- good above here ----- + @test "Init command creates .gitignore.d in \$VCSH_BASE" { VCSH_BASE="$PWD/foo/bar" "$VCSH" init foo test -d .config @@ -69,3 +134,42 @@ load environment test -d foo/bar test -d foo/bar/.gitignore.d } + +@test "Init command fails if \$VCSH_REPO_D cannot be created" { + mkdir ro + chmod a-w ro + ! VCSH_REPO_D="$PWD/ro/repo.d" "$VCSH" init foo +} + +@test "Init command fails if .gitignore.d cannot be created" { + mkdir ro + chmod a-w ro + ! VCSH_REPO_D="$PWD/bar" VCSH_BASE="$PWD/ro" \ + VCSH_GITIGNORE=exact VCSH_GITATTRIBUTES=none \ + "$VCSH" init foo +} + +@test "Init command fails if .gitattributes.d cannot be created" { + mkdir ro + chmod a-w ro + ! VCSH_REPO_D="$PWD/bar" VCSH_BASE="$PWD/ro" \ + VCSH_GITIGNORE=none VCSH_GITATTRIBUTES=yes \ + "$VCSH" init foo +} + +@test "Init command fails if \$VCSH_BASE cannot be created" { + mkdir ro + chmod a-w ro + ! VCSH_BASE="$PWD/ro/base" "$VCSH" init test1 +} + +@test "Init command fails if \$VCSH_BASE cannot be entered" { + mkdir noentry + chmod a-x noentry + ! VCSH_BASE="$PWD/noentry" "$VCSH" init test1 +} + +@test "Init command does not set core.attributesfile with VCSH_GITATTRIBUTES=none" { + VCSH_GITATTRIBUTES=none "$VCSH" init test1 + ! GIT_DIR="$HOME/.config/vcsh/repo.d/test1.git" git config core.attributesfile +} diff --git a/bats/list.bats b/bats/list.bats index 39ad8768..cd027e66 100644 --- a/bats/list.bats +++ b/bats/list.bats @@ -1,149 +1,96 @@ load environment -@test "List command succeeds" { - "$VCSH" list -} - -@test "List command creates default support directories" { - "$VCSH" list - test -d .config - test -d .config/vcsh - test -d .config/vcsh/repo.d - test -d .gitignore.d -} - -@test "List command creates \$VCSH_REPO_D" { - VCSH_REPO_D="$PWD/foo/bar" "$VCSH" list - test -d foo - test -d foo/bar - test -d .gitignore.d -} - -@test "List command creates .gitignore.d in \$VCSH_BASE" { - VCSH_BASE="$PWD/foo/bar" "$VCSH" list - test -d .config - test -d .config/vcsh - test -d .config/vcsh/repo.d - test -d foo - test -d foo/bar - test -d foo/bar/.gitignore.d -} - -@test "List command creates .gitignore.d with VCSH_GITIGNORE=recursive" { - VCSH_GITIGNORE=recursive "$VCSH" list - test -d .config - test -d .config/vcsh - test -d .config/vcsh/repo.d - test -d .gitignore.d -} - -@test "List command does not create .gitignore.d with VCSH_GITIGNORE=none" { - VCSH_GITIGNORE=none "$VCSH" list - test -d .config - test -d .config/vcsh - test -d .config/vcsh/repo.d - ! test -d .gitignore.d -} - -@test "List command gives correct output for no repos" { +@test "List command correct for no repositories" { run "$VCSH" list + [ "$status" -eq 0 ] [ "$output" = '' ] } -@test "List command gives correct output for empty repo directory" { - # XXX should vcsh fail if this is not a Git repository? - mkdir -p .config/vcsh/repo.d/foo.git - run "$VCSH" list - [ "$output" = $'foo' ] -} - -@test "List command gives correct output for non-bare repo" { - # XXX should vcsh fail if this is not a bare repository? - mkdir -p .config/vcsh/repo.d - git init .config/vcsh/repo.d/foo.git - run "$VCSH" list - [ "$output" = $'foo' ] -} - -@test "List command gives correct output for one repo (git init)" { - mkdir -p .config/vcsh/repo.d - git init --bare .config/vcsh/repo.d/foo.git +@test "List command displays inited repository" { + "$VCSH" init test1 run "$VCSH" list - [ "$output" = $'foo' ] + [ "$status" -eq 0 ] + [ "$output" = 'test1' ] } -@test "List command gives correct output for one repo (vcsh init)" { - "$VCSH" init foo +@test "List command displays cloned repository" { + "$VCSH" clone "$TESTREPO" test1 run "$VCSH" list - [ "$output" = $'foo' ] -} - -@test "List command gives correct output for three repos (git init)" { - # XXX should this fail if these are not bare repositories? - mkdir -p .config/vcsh/repo.d - git init --bare .config/vcsh/repo.d/foo.git - git init --bare .config/vcsh/repo.d/bar.git - git init --bare .config/vcsh/repo.d/baz.git - run "$VCSH" list - [ "$output" = $'bar\nbaz\nfoo' ] + [ "$status" -eq 0 ] + [ "$output" = 'test1' ] } -@test "List command gives correct output for three repos (vcsh init)" { - # XXX should this fail if these are not bare repositories? - mkdir -p .config/vcsh/repo.d +@test "List command displays multiple repositories" { "$VCSH" init foo "$VCSH" init bar "$VCSH" init baz run "$VCSH" list + [ "$status" -eq 0 ] [ "$output" = $'bar\nbaz\nfoo' ] } -@test "List command only lists directories" { - mkdir -p .config/vcsh/repo.d - touch .config/vcsh/repo.d/foo.git - mkfifo .config/vcsh/repo.d/bar.git +@test "List command respects \$VCSH_REPO_D" { + VCSH_REPO_D="$PWD/foo" "$VCSH" init test1 + VCSH_REPO_D="$PWD/bar" "$VCSH" init test2 - run "$VCSH" list - [ "$output" = '' ] + VCSH_REPO_D="$PWD/foo" run "$VCSH" list + [ "$status" -eq 0 ] + [ "$output" = 'test1' ] - "$VCSH" init baz - run "$VCSH" list - [ "$output" = 'baz' ] + VCSH_REPO_D="$PWD/bar" run "$VCSH" list + [ "$status" -eq 0 ] + [ "$output" = 'test2' ] } -@test "List command only lists directories ending in '.git'" { - mkdir -p .config/vcsh/repo.d - git init --bare .config/vcsh/repo.d/foo - git init --bare .config/vcsh/repo.d/bar - git init --bare .config/vcsh/repo.d/baz.git +@test "List command respects \$XDG_CONFIG_HOME" { + XDG_CONFIG_HOME="$PWD/foo" "$VCSH" init test1 + XDG_CONFIG_HOME="$PWD/bar" "$VCSH" init test2 - run "$VCSH" list - [ "$output" = 'baz' ] + XDG_CONFIG_HOME="$PWD/foo" run "$VCSH" list + [ "$status" -eq 0 ] + [ "$output" = 'test1' ] + + XDG_CONFIG_HOME="$PWD/bar" run "$VCSH" list + [ "$status" -eq 0 ] + [ "$output" = 'test2' ] } -@test "List command does not list unreadable repos" { - "$VCSH" init foo +@test "List command respects \$HOME" { + HOME="$PWD/foo" "$VCSH" init test1 + HOME="$PWD/bar" "$VCSH" init test2 - run "$VCSH" list - [ "$output" = 'foo' ] + HOME="$PWD/foo" run "$VCSH" list + [ "$status" -eq 0 ] + [ "$output" = 'test1' ] - chmod a-r .config/vcsh/repo.d/foo.git - run "$VCSH" list - [ "$output" = '' ] + HOME="$PWD/bar" run "$VCSH" list + [ "$status" -eq 0 ] + [ "$output" = 'test2' ] +} + +@test "List command prioritizes \$XDG_CONFIG_HOME over \$HOME" { + HOME="$PWD/foo" "$VCSH" init correct + HOME="$PWD/bar" "$VCSH" init wrong + + HOME="$PWD/bar" XDG_CONFIG_HOME="$PWD/foo/.config" run "$VCSH" list + [ "$status" -eq 0 ] + [ "$output" = 'correct' ] } -@test "List command respects \$VCSH_REPO_D (git init)" { - mkdir -p foo/bar - git init --bare foo/bar/hello.git +@test "List command prioritizes \$VCSH_REPO_D over \$HOME" { + HOME="$PWD/foo" "$VCSH" init correct + HOME="$PWD/bar" "$VCSH" init wrong - VCSH_REPO_D="$PWD/foo/bar" run "$VCSH" list - [ "$output" = 'hello' ] + HOME="$PWD/bar" VCSH_REPO_D="$PWD/foo/.config/vcsh/repo.d" run "$VCSH" list + [ "$status" -eq 0 ] + [ "$output" = 'correct' ] } -@test "List command respects \$VCSH_REPO_D (vcsh init)" { - mkdir -p foo/bar - VCSH_REPO_D="$PWD/foo/bar" "$VCSH" init hello +@test "List command prioritizes \$VCSH_REPO_D over \$XDG_CONFIG_HOME" { + XDG_CONFIG_HOME="$PWD/foo" "$VCSH" init correct + XDG_CONFIG_HOME="$PWD/bar" "$VCSH" init wrong - VCSH_REPO_D="$PWD/foo/bar" run "$VCSH" list - [ "$output" = 'hello' ] + XDG_CONFIG_HOME="$PWD/bar" VCSH_REPO_D="$PWD/foo/vcsh/repo.d" run "$VCSH" list + [ "$status" -eq 0 ] + [ "$output" = 'correct' ] } From a6e5a2adba9ba95be0c268466819f7b0e1ba1cde Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 7 Feb 2017 17:57:03 -0600 Subject: [PATCH 010/151] clone local test repo as its own rule --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 34ee1a82..4e7b556c 100644 --- a/Makefile +++ b/Makefile @@ -43,10 +43,12 @@ purge: uninstall rmdir -p --ignore-fail-on-non-empty $(DESTDIR)$(DOCDIR) rmdir -p --ignore-fail-on-non-empty $(DESTDIR)$(ZSHDIR) -test: +vcsh_testrepo.git: + git clone --mirror https://github.com/djpohly/vcsh_testrepo.git + +test: | vcsh_testrepo.git @if ! which git > /dev/null; then echo "'git' not found, exiting..." ; exit 1; fi @if ! which bats > /dev/null; then echo "'bats' not found; not running tests"; exit 1; fi - [ -d "vcsh_testrepo.git" ] || git clone --mirror https://github.com/djpohly/vcsh_testrepo.git TESTREPO=$(PWD)/vcsh_testrepo.git TESTREPONAME=vcsh_testrepo bats ./bats moo: From 13d129e628d8b7c85f9ff5c9db747a8332e37760 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 7 Feb 2017 18:19:14 -0600 Subject: [PATCH 011/151] updated init tests --- bats/debug.bats | 7 ++++++ bats/init.bats | 66 +++++++++---------------------------------------- 2 files changed, 18 insertions(+), 55 deletions(-) create mode 100644 bats/debug.bats diff --git a/bats/debug.bats b/bats/debug.bats new file mode 100644 index 00000000..a81f1c8a --- /dev/null +++ b/bats/debug.bats @@ -0,0 +1,7 @@ +load environment + +@test "Debug output includes git version" { + "$VCSH" -d init foo |& grep -q 'git version [0-9]' + "$VCSH" -d list |& grep -q 'git version [0-9]' + # XXX add more? +} diff --git a/bats/init.bats b/bats/init.bats index 0259f074..aacb03a4 100644 --- a/bats/init.bats +++ b/bats/init.bats @@ -30,10 +30,10 @@ load environment HOME="$PWD/bar" "$VCSH" init samename } -@test "Debug output includes git version" { - "$VCSH" -d init foo |& grep -q 'git version [0-9]' - "$VCSH" -d list |& grep -q 'git version [0-9]' - # XXX add more? +@test "Init command fails if directories cannot be created" { + mkdir ro + chmod a-w ro + ! HOME="$PWD/ro" "$VCSH" init foo } @test "Init command can be abbreviated 'ini'/'in'" { @@ -105,71 +105,27 @@ load environment # XXX test instead by making sure files are actually excluded, not by # reading config option VCSH_GITIGNORE=exact "$VCSH" init test1 - run "$VCSH" run test1 git config core.excludesfile - [ "$output" = ".gitignore.d/test1" ] + "$VCSH" run test1 git config core.excludesfile } @test "Init command sets core.excludesfile with VCSH_GITIGNORE=recursive" { # XXX test instead by making sure files are actually excluded, not by # reading config option VCSH_GITIGNORE=recursive "$VCSH" init test1 - run "$VCSH" run test1 git config core.excludesfile - [ "$output" = ".gitignore.d/test1" ] + "$VCSH" run test1 git config core.excludesfile } @test "Init command does not set core.excludesfile with VCSH_GITIGNORE=none" { VCSH_GITIGNORE=none "$VCSH" init test1 - run "$VCSH" run test1 git config core.excludesfile - [ "$status" -ne 0 ] -} - -# ----- good above here ----- - -@test "Init command creates .gitignore.d in \$VCSH_BASE" { - VCSH_BASE="$PWD/foo/bar" "$VCSH" init foo - test -d .config - test -d .config/vcsh - test -d .config/vcsh/repo.d - test -d foo - test -d foo/bar - test -d foo/bar/.gitignore.d -} - -@test "Init command fails if \$VCSH_REPO_D cannot be created" { - mkdir ro - chmod a-w ro - ! VCSH_REPO_D="$PWD/ro/repo.d" "$VCSH" init foo -} - -@test "Init command fails if .gitignore.d cannot be created" { - mkdir ro - chmod a-w ro - ! VCSH_REPO_D="$PWD/bar" VCSH_BASE="$PWD/ro" \ - VCSH_GITIGNORE=exact VCSH_GITATTRIBUTES=none \ - "$VCSH" init foo -} - -@test "Init command fails if .gitattributes.d cannot be created" { - mkdir ro - chmod a-w ro - ! VCSH_REPO_D="$PWD/bar" VCSH_BASE="$PWD/ro" \ - VCSH_GITIGNORE=none VCSH_GITATTRIBUTES=yes \ - "$VCSH" init foo -} - -@test "Init command fails if \$VCSH_BASE cannot be created" { - mkdir ro - chmod a-w ro - ! VCSH_BASE="$PWD/ro/base" "$VCSH" init test1 + ! "$VCSH" run test1 git config core.excludesfile } -@test "Init command fails if \$VCSH_BASE cannot be entered" { - mkdir noentry - chmod a-x noentry - ! VCSH_BASE="$PWD/noentry" "$VCSH" init test1 +@test "Init command sets core.attributesfile with VCSH_GITATTRIBUTES!=none" { + VCSH_GITATTRIBUTES=whatever "$VCSH" init test1 + "$VCSH" run test1 git config core.attributesfile } @test "Init command does not set core.attributesfile with VCSH_GITATTRIBUTES=none" { VCSH_GITATTRIBUTES=none "$VCSH" init test1 - ! GIT_DIR="$HOME/.config/vcsh/repo.d/test1.git" git config core.attributesfile + ! "$VCSH" run test1 git config core.attributesfile } From 6aa774f7de1e753b128d3680237b5eb4f6435044 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 7 Feb 2017 19:50:43 -0600 Subject: [PATCH 012/151] add some clone tests --- bats/clone.bats | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 bats/clone.bats diff --git a/bats/clone.bats b/bats/clone.bats new file mode 100644 index 00000000..d67e846f --- /dev/null +++ b/bats/clone.bats @@ -0,0 +1,86 @@ +load environment + +@test "Clone requires a remote" { + run "$VCSH" clone + [ "$status" -eq 1 ] +} + +@test "Clone uses existing repo name by default" { + "$VCSH" clone "$TESTREPO" + run "$VCSH" list + [ "$status" -eq 0 ] + [ "$output" = "$TESTREPONAME" ] +} + +@test "Clone honors specified repo name" { + "$VCSH" clone "$TESTREPO" foo + run "$VCSH" list + [ "$status" -eq 0 ] + [ "$output" = "foo" ] +} + +@test "Clone uses given remote HEAD by default" { + "$VCSH" clone "$TESTREPO" + run git ls-remote "$TESTREPO" HEAD + correct=${output::40} + + run "$VCSH" run "$TESTREPONAME" git rev-parse HEAD + [ "$status" -eq 0 ] + [ "$output" = "$correct" ] +} + +@test "Clone honors -b option before remote" { + "$VCSH" clone -b "$TESTBR1" "$TESTREPO" + run git ls-remote "$TESTREPO" "$TESTBR1" + correct=${output::40} + + run "$VCSH" run "$TESTREPONAME" git rev-parse "$TESTBR1" + [ "$status" -eq 0 ] + [ "$output" = "$correct" ] +} + +@test "Clone honors -b option before remote and repo name" { + "$VCSH" clone -b "$TESTBR1" "$TESTREPO" foo + run git ls-remote "$TESTREPO" "$TESTBR1" + correct=${output::40} + + run "$VCSH" run foo git rev-parse "$TESTBR1" + [ "$status" -eq 0 ] + [ "$output" = "$correct" ] +} + +@test "Clone honors -b option after remote" { + "$VCSH" clone "$TESTREPO" -b "$TESTBR1" + run git ls-remote "$TESTREPO" "$TESTBR1" + correct=${output::40} + + run "$VCSH" run "$TESTREPONAME" git rev-parse "$TESTBR1" + [ "$status" -eq 0 ] + [ "$output" = "$correct" ] +} + +@test "Clone honors -b option between remote and repo name" { + "$VCSH" clone "$TESTREPO" -b "$TESTBR1" foo + run git ls-remote "$TESTREPO" "$TESTBR1" + correct=${output::40} + + run "$VCSH" run foo git rev-parse "$TESTBR1" + [ "$status" -eq 0 ] + [ "$output" = "$correct" ] +} + +@test "Clone honors -b option after repo name" { + "$VCSH" clone "$TESTREPO" foo -b "$TESTBR1" + run git ls-remote "$TESTREPO" "$TESTBR1" + correct=${output::40} + + run "$VCSH" run foo git rev-parse "$TESTBR1" + [ "$status" -eq 0 ] + [ "$output" = "$correct" ] +} + +@test "Clone -b option clones only one branch" { + "$VCSH" clone -b "$TESTBR1" "$TESTREPO" + run "$VCSH" run "$TESTREPONAME" git branch + [ "${#lines[@]}" -eq 1 ] +} From f1d20a44813dd0de8b02dfa7d60816b03ece880b Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 7 Feb 2017 21:08:54 -0600 Subject: [PATCH 013/151] switch "$VCSH" to $VCSH Let us hope there are no spaces in the user's path, because this will allows us to set VCSH="bash vcsh", VCSH="dash vcsh", etc. --- bats/clone.bats | 39 +++++++++++----------- bats/debug.bats | 4 +-- bats/help.bats | 16 ++++----- bats/init.bats | 82 +++++++++++++++++++++++------------------------ bats/list.bats | 60 +++++++++++++++++----------------- bats/prove.bats | 22 ++++++------- bats/version.bats | 4 +-- 7 files changed, 114 insertions(+), 113 deletions(-) diff --git a/bats/clone.bats b/bats/clone.bats index d67e846f..8be18c16 100644 --- a/bats/clone.bats +++ b/bats/clone.bats @@ -1,86 +1,87 @@ load environment @test "Clone requires a remote" { - run "$VCSH" clone + run $VCSH clone [ "$status" -eq 1 ] } @test "Clone uses existing repo name by default" { - "$VCSH" clone "$TESTREPO" - run "$VCSH" list + $VCSH clone "$TESTREPO" + $VCSH list + run $VCSH list [ "$status" -eq 0 ] [ "$output" = "$TESTREPONAME" ] } @test "Clone honors specified repo name" { - "$VCSH" clone "$TESTREPO" foo - run "$VCSH" list + $VCSH clone "$TESTREPO" foo + run $VCSH list [ "$status" -eq 0 ] [ "$output" = "foo" ] } @test "Clone uses given remote HEAD by default" { - "$VCSH" clone "$TESTREPO" + $VCSH clone "$TESTREPO" run git ls-remote "$TESTREPO" HEAD correct=${output::40} - run "$VCSH" run "$TESTREPONAME" git rev-parse HEAD + run $VCSH run "$TESTREPONAME" git rev-parse HEAD [ "$status" -eq 0 ] [ "$output" = "$correct" ] } @test "Clone honors -b option before remote" { - "$VCSH" clone -b "$TESTBR1" "$TESTREPO" + $VCSH clone -b "$TESTBR1" "$TESTREPO" run git ls-remote "$TESTREPO" "$TESTBR1" correct=${output::40} - run "$VCSH" run "$TESTREPONAME" git rev-parse "$TESTBR1" + run $VCSH run "$TESTREPONAME" git rev-parse "$TESTBR1" [ "$status" -eq 0 ] [ "$output" = "$correct" ] } @test "Clone honors -b option before remote and repo name" { - "$VCSH" clone -b "$TESTBR1" "$TESTREPO" foo + $VCSH clone -b "$TESTBR1" "$TESTREPO" foo run git ls-remote "$TESTREPO" "$TESTBR1" correct=${output::40} - run "$VCSH" run foo git rev-parse "$TESTBR1" + run $VCSH run foo git rev-parse "$TESTBR1" [ "$status" -eq 0 ] [ "$output" = "$correct" ] } @test "Clone honors -b option after remote" { - "$VCSH" clone "$TESTREPO" -b "$TESTBR1" + $VCSH clone "$TESTREPO" -b "$TESTBR1" run git ls-remote "$TESTREPO" "$TESTBR1" correct=${output::40} - run "$VCSH" run "$TESTREPONAME" git rev-parse "$TESTBR1" + run $VCSH run "$TESTREPONAME" git rev-parse "$TESTBR1" [ "$status" -eq 0 ] [ "$output" = "$correct" ] } @test "Clone honors -b option between remote and repo name" { - "$VCSH" clone "$TESTREPO" -b "$TESTBR1" foo + $VCSH clone "$TESTREPO" -b "$TESTBR1" foo run git ls-remote "$TESTREPO" "$TESTBR1" correct=${output::40} - run "$VCSH" run foo git rev-parse "$TESTBR1" + run $VCSH run foo git rev-parse "$TESTBR1" [ "$status" -eq 0 ] [ "$output" = "$correct" ] } @test "Clone honors -b option after repo name" { - "$VCSH" clone "$TESTREPO" foo -b "$TESTBR1" + $VCSH clone "$TESTREPO" foo -b "$TESTBR1" run git ls-remote "$TESTREPO" "$TESTBR1" correct=${output::40} - run "$VCSH" run foo git rev-parse "$TESTBR1" + run $VCSH run foo git rev-parse "$TESTBR1" [ "$status" -eq 0 ] [ "$output" = "$correct" ] } @test "Clone -b option clones only one branch" { - "$VCSH" clone -b "$TESTBR1" "$TESTREPO" - run "$VCSH" run "$TESTREPONAME" git branch + $VCSH clone -b "$TESTBR1" "$TESTREPO" + run $VCSH run "$TESTREPONAME" git branch [ "${#lines[@]}" -eq 1 ] } diff --git a/bats/debug.bats b/bats/debug.bats index a81f1c8a..58a3990d 100644 --- a/bats/debug.bats +++ b/bats/debug.bats @@ -1,7 +1,7 @@ load environment @test "Debug output includes git version" { - "$VCSH" -d init foo |& grep -q 'git version [0-9]' - "$VCSH" -d list |& grep -q 'git version [0-9]' + $VCSH -d init foo |& grep -q 'git version [0-9]' + $VCSH -d list |& grep -q 'git version [0-9]' # XXX add more? } diff --git a/bats/help.bats b/bats/help.bats index 6d24c6bb..9026339f 100644 --- a/bats/help.bats +++ b/bats/help.bats @@ -1,28 +1,28 @@ load environment @test "Help command succeeds" { - "$VCSH" help + $VCSH help } @test "Help command writes to stderr and not stdout" { - "$VCSH" help 2>&1 1>/dev/null | + $VCSH help 2>&1 1>/dev/null | grep -q '' - ! "$VCSH" help 2>/dev/null | + ! $VCSH help 2>/dev/null | grep -q '' } @test "Help command prints usage on first line" { - run "$VCSH" help + run $VCSH help [[ "$output" = 'usage: '* ]] } @test "Help command can be abbreviated (hel, he)" { - run "$VCSH" help + run $VCSH help local good=$output - run "$VCSH" hel + run $VCSH hel [ "$status" -eq 0 ] [ "$output" = "$good" ] - run "$VCSH" he + run $VCSH he [ "$status" -eq 0 ] [ "$output" = "$good" ] } @@ -30,7 +30,7 @@ load environment # Help should explain each command. (Note: adjust the help_check function if # the format of help output changes.) help_check() { - "$VCSH" help 2>&1 | + $VCSH help 2>&1 | grep -q "^ $1\\b" } diff --git a/bats/init.bats b/bats/init.bats index aacb03a4..4e01b1ce 100644 --- a/bats/init.bats +++ b/bats/init.bats @@ -1,77 +1,77 @@ load environment @test "Init command succeeds" { - "$VCSH" init foo + $VCSH init foo } @test "Init command takes exactly one parameter" { - ! "$VCSH" init - ! "$VCSH" init foo bar - "$VCSH" init baz + ! $VCSH init + ! $VCSH init foo bar + $VCSH init baz } @test "Init command fails if repository already exists" { - "$VCSH" init exists - ! "$VCSH" init exists + $VCSH init exists + ! $VCSH init exists } @test "Init command respects alternate \$VCSH_REPO_D" { - VCSH_REPO_D="$PWD/foo" "$VCSH" init samename - VCSH_REPO_D="$PWD/bar" "$VCSH" init samename + VCSH_REPO_D="$PWD/foo" $VCSH init samename + VCSH_REPO_D="$PWD/bar" $VCSH init samename } @test "Init command respects alternate \$XDG_CONFIG_HOME" { - XDG_CONFIG_HOME="$PWD/foo" "$VCSH" init samename - XDG_CONFIG_HOME="$PWD/bar" "$VCSH" init samename + XDG_CONFIG_HOME="$PWD/foo" $VCSH init samename + XDG_CONFIG_HOME="$PWD/bar" $VCSH init samename } @test "Init command respects alternate \$HOME" { - HOME="$PWD/foo" "$VCSH" init samename - HOME="$PWD/bar" "$VCSH" init samename + HOME="$PWD/foo" $VCSH init samename + HOME="$PWD/bar" $VCSH init samename } @test "Init command fails if directories cannot be created" { mkdir ro chmod a-w ro - ! HOME="$PWD/ro" "$VCSH" init foo + ! HOME="$PWD/ro" $VCSH init foo } @test "Init command can be abbreviated 'ini'/'in'" { - "$VCSH" ini test1 - "$VCSH" in test2 + $VCSH ini test1 + $VCSH in test2 - run "$VCSH" list + run $VCSH list [ "$status" -eq 0 ] [ "$output" = $'test1\ntest2' ] } @test "\$VCSH_REPO_D overrides \$XDG_CONFIG_HOME and \$HOME for init" { - HOME="$PWD/foo" "$VCSH" init samename1 - XDG_CONFIG_HOME="$PWD/bar" "$VCSH" init samename2 + HOME="$PWD/foo" $VCSH init samename1 + XDG_CONFIG_HOME="$PWD/bar" $VCSH init samename2 - HOME="$PWD/foo" XDG_CONFIG_HOME="$PWD/bar" VCSH_REPO_D="$PWD/baz" "$VCSH" init samename1 - HOME="$PWD/foo" XDG_CONFIG_HOME="$PWD/bar" VCSH_REPO_D="$PWD/baz" "$VCSH" init samename2 + HOME="$PWD/foo" XDG_CONFIG_HOME="$PWD/bar" VCSH_REPO_D="$PWD/baz" $VCSH init samename1 + HOME="$PWD/foo" XDG_CONFIG_HOME="$PWD/bar" VCSH_REPO_D="$PWD/baz" $VCSH init samename2 } @test "\$XDG_CONFIG_HOME overrides \$HOME for init" { - HOME="$PWD/foo" "$VCSH" init samename - HOME="$PWD/foo" XDG_CONFIG_HOME="$PWD/bar" "$VCSH" init samename + HOME="$PWD/foo" $VCSH init samename + HOME="$PWD/foo" XDG_CONFIG_HOME="$PWD/bar" $VCSH init samename } @test "Init command marks repository with vcsh.vcsh=true" { # Too internal to implementation? If another command verifies # vcsh.vcsh, use that instead of git config. - "$VCSH" init test1 + $VCSH init test1 - run "$VCSH" run test1 git config vcsh.vcsh + run $VCSH run test1 git config vcsh.vcsh [ "$status" -eq 0 ] [ "$output" = "true" ] } @test "Files created by init are not readable by other users" { # verifies commit e220a61 - "$VCSH" init foo + $VCSH init foo run find "$PWD" -type f -perm /g+rwx,o+rwx [ "$output" = '' ] } @@ -80,8 +80,8 @@ load environment mkdir -p .gitattributes.d .gitignore.d touch .gitattributes.d/test1 .gitignore.d/test1 - VCSH_GITIGNORE=exact "$VCSH" init test1 - "$VCSH" status test1 | grep -Fqx 'A .gitignore.d/test1' + VCSH_GITIGNORE=exact $VCSH init test1 + $VCSH status test1 | grep -Fqx 'A .gitignore.d/test1' } @test "Init command creates new Git repository" { @@ -89,43 +89,43 @@ load environment [ "$output" = '0' ] for i in $(seq 5); do - "$VCSH" init "test$i" + $VCSH init "test$i" run num_gitrepos "$PWD" [ "$output" = "$i" ] done } @test "VCSH_GITIGNORE variable is validated" { - ! VCSH_GITIGNORE=x "$VCSH" init foo - ! VCSH_GITIGNORE=nonsense "$VCSH" init foo - ! VCSH_GITIGNORE=fhqwhgads "$VCSH" init foo + ! VCSH_GITIGNORE=x $VCSH init foo + ! VCSH_GITIGNORE=nonsense $VCSH init foo + ! VCSH_GITIGNORE=fhqwhgads $VCSH init foo } @test "Init command sets core.excludesfile with VCSH_GITIGNORE=exact" { # XXX test instead by making sure files are actually excluded, not by # reading config option - VCSH_GITIGNORE=exact "$VCSH" init test1 - "$VCSH" run test1 git config core.excludesfile + VCSH_GITIGNORE=exact $VCSH init test1 + $VCSH run test1 git config core.excludesfile } @test "Init command sets core.excludesfile with VCSH_GITIGNORE=recursive" { # XXX test instead by making sure files are actually excluded, not by # reading config option - VCSH_GITIGNORE=recursive "$VCSH" init test1 - "$VCSH" run test1 git config core.excludesfile + VCSH_GITIGNORE=recursive $VCSH init test1 + $VCSH run test1 git config core.excludesfile } @test "Init command does not set core.excludesfile with VCSH_GITIGNORE=none" { - VCSH_GITIGNORE=none "$VCSH" init test1 - ! "$VCSH" run test1 git config core.excludesfile + VCSH_GITIGNORE=none $VCSH init test1 + ! $VCSH run test1 git config core.excludesfile } @test "Init command sets core.attributesfile with VCSH_GITATTRIBUTES!=none" { - VCSH_GITATTRIBUTES=whatever "$VCSH" init test1 - "$VCSH" run test1 git config core.attributesfile + VCSH_GITATTRIBUTES=whatever $VCSH init test1 + $VCSH run test1 git config core.attributesfile } @test "Init command does not set core.attributesfile with VCSH_GITATTRIBUTES=none" { - VCSH_GITATTRIBUTES=none "$VCSH" init test1 - ! "$VCSH" run test1 git config core.attributesfile + VCSH_GITATTRIBUTES=none $VCSH init test1 + ! $VCSH run test1 git config core.attributesfile } diff --git a/bats/list.bats b/bats/list.bats index cd027e66..c583cf56 100644 --- a/bats/list.bats +++ b/bats/list.bats @@ -1,96 +1,96 @@ load environment @test "List command correct for no repositories" { - run "$VCSH" list + run $VCSH list [ "$status" -eq 0 ] [ "$output" = '' ] } @test "List command displays inited repository" { - "$VCSH" init test1 - run "$VCSH" list + $VCSH init test1 + run $VCSH list [ "$status" -eq 0 ] [ "$output" = 'test1' ] } @test "List command displays cloned repository" { - "$VCSH" clone "$TESTREPO" test1 - run "$VCSH" list + $VCSH clone "$TESTREPO" test1 + run $VCSH list [ "$status" -eq 0 ] [ "$output" = 'test1' ] } @test "List command displays multiple repositories" { - "$VCSH" init foo - "$VCSH" init bar - "$VCSH" init baz - run "$VCSH" list + $VCSH init foo + $VCSH init bar + $VCSH init baz + run $VCSH list [ "$status" -eq 0 ] [ "$output" = $'bar\nbaz\nfoo' ] } @test "List command respects \$VCSH_REPO_D" { - VCSH_REPO_D="$PWD/foo" "$VCSH" init test1 - VCSH_REPO_D="$PWD/bar" "$VCSH" init test2 + VCSH_REPO_D="$PWD/foo" $VCSH init test1 + VCSH_REPO_D="$PWD/bar" $VCSH init test2 - VCSH_REPO_D="$PWD/foo" run "$VCSH" list + VCSH_REPO_D="$PWD/foo" run $VCSH list [ "$status" -eq 0 ] [ "$output" = 'test1' ] - VCSH_REPO_D="$PWD/bar" run "$VCSH" list + VCSH_REPO_D="$PWD/bar" run $VCSH list [ "$status" -eq 0 ] [ "$output" = 'test2' ] } @test "List command respects \$XDG_CONFIG_HOME" { - XDG_CONFIG_HOME="$PWD/foo" "$VCSH" init test1 - XDG_CONFIG_HOME="$PWD/bar" "$VCSH" init test2 + XDG_CONFIG_HOME="$PWD/foo" $VCSH init test1 + XDG_CONFIG_HOME="$PWD/bar" $VCSH init test2 - XDG_CONFIG_HOME="$PWD/foo" run "$VCSH" list + XDG_CONFIG_HOME="$PWD/foo" run $VCSH list [ "$status" -eq 0 ] [ "$output" = 'test1' ] - XDG_CONFIG_HOME="$PWD/bar" run "$VCSH" list + XDG_CONFIG_HOME="$PWD/bar" run $VCSH list [ "$status" -eq 0 ] [ "$output" = 'test2' ] } @test "List command respects \$HOME" { - HOME="$PWD/foo" "$VCSH" init test1 - HOME="$PWD/bar" "$VCSH" init test2 + HOME="$PWD/foo" $VCSH init test1 + HOME="$PWD/bar" $VCSH init test2 - HOME="$PWD/foo" run "$VCSH" list + HOME="$PWD/foo" run $VCSH list [ "$status" -eq 0 ] [ "$output" = 'test1' ] - HOME="$PWD/bar" run "$VCSH" list + HOME="$PWD/bar" run $VCSH list [ "$status" -eq 0 ] [ "$output" = 'test2' ] } @test "List command prioritizes \$XDG_CONFIG_HOME over \$HOME" { - HOME="$PWD/foo" "$VCSH" init correct - HOME="$PWD/bar" "$VCSH" init wrong + HOME="$PWD/foo" $VCSH init correct + HOME="$PWD/bar" $VCSH init wrong - HOME="$PWD/bar" XDG_CONFIG_HOME="$PWD/foo/.config" run "$VCSH" list + HOME="$PWD/bar" XDG_CONFIG_HOME="$PWD/foo/.config" run $VCSH list [ "$status" -eq 0 ] [ "$output" = 'correct' ] } @test "List command prioritizes \$VCSH_REPO_D over \$HOME" { - HOME="$PWD/foo" "$VCSH" init correct - HOME="$PWD/bar" "$VCSH" init wrong + HOME="$PWD/foo" $VCSH init correct + HOME="$PWD/bar" $VCSH init wrong - HOME="$PWD/bar" VCSH_REPO_D="$PWD/foo/.config/vcsh/repo.d" run "$VCSH" list + HOME="$PWD/bar" VCSH_REPO_D="$PWD/foo/.config/vcsh/repo.d" run $VCSH list [ "$status" -eq 0 ] [ "$output" = 'correct' ] } @test "List command prioritizes \$VCSH_REPO_D over \$XDG_CONFIG_HOME" { - XDG_CONFIG_HOME="$PWD/foo" "$VCSH" init correct - XDG_CONFIG_HOME="$PWD/bar" "$VCSH" init wrong + XDG_CONFIG_HOME="$PWD/foo" $VCSH init correct + XDG_CONFIG_HOME="$PWD/bar" $VCSH init wrong - XDG_CONFIG_HOME="$PWD/bar" VCSH_REPO_D="$PWD/foo/vcsh/repo.d" run "$VCSH" list + XDG_CONFIG_HOME="$PWD/bar" VCSH_REPO_D="$PWD/foo/vcsh/repo.d" run $VCSH list [ "$status" -eq 0 ] [ "$output" = 'correct' ] } diff --git a/bats/prove.bats b/bats/prove.bats index 1450b3fe..6b344a95 100644 --- a/bats/prove.bats +++ b/bats/prove.bats @@ -1,41 +1,41 @@ load environment @test "100-init.t" { - run "$VCSH" status + run $VCSH status [ "$status" -eq 0 ] [ "$output" = "" ] - run "$VCSH" init test1 + run $VCSH init test1 [ "$status" -eq 0 ] [ "$output" = "Initialized empty shared Git repository in $HOME/.config/vcsh/repo.d/test1.git/" ] - run "$VCSH" status + run $VCSH status echo "'$output'" [ "$status" -eq 0 ] [ "$output" = 'test1:' ] } @test "300-add.t" { - "$VCSH" init test1 - "$VCSH" init test2 + $VCSH init test1 + $VCSH init test2 touch 'a' - "$VCSH" test2 add 'a' + $VCSH test2 add 'a' - run "$VCSH" status + run $VCSH status [ "$status" -eq 0 ] [ "$output" = $'test1:\n\ntest2:\nA a' ] - run "$VCSH" status --terse + run $VCSH status --terse [ "$status" -eq 0 ] [ "$output" = $'test2:\nA a' ] } @test "950-delete.t" { - "$VCSH" init test1 - echo 'Yes, do as I say' | run "$VCSH" delete test1 + $VCSH init test1 + echo 'Yes, do as I say' | run $VCSH delete test1 - run "$VCSH" status + run $VCSH status [ "$status" -eq 0 ] [ "$output" = '' ] } diff --git a/bats/version.bats b/bats/version.bats index 2473aeaf..7350880c 100644 --- a/bats/version.bats +++ b/bats/version.bats @@ -1,11 +1,11 @@ load environment @test "Version command succeeds" { - "$VCSH" version + $VCSH version } @test "Version command prints vcsh and git versions" { - run "$VCSH" version + run $VCSH version [[ "${lines[0]}" = 'vcsh '[0-9]* ]] [[ "${lines[1]}" = 'git version '[0-9]* ]] } From d4fa0c6a9d7528b5285f7689ab441dbf289a9687 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 7 Feb 2017 21:10:22 -0600 Subject: [PATCH 014/151] probably just paranoia, add export anyway --- bats/environment.bash | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/bats/environment.bash b/bats/environment.bash index 7f4c2cf4..1269610e 100644 --- a/bats/environment.bash +++ b/bats/environment.bash @@ -1,12 +1,7 @@ setup() { - VCSH="$BATS_TEST_DIRNAME/../vcsh" + export VCSH="$BATS_TEST_DIRNAME/../vcsh" export LC_ALL=C - # Ensure behavior/output isn't affected by outside variables - # (We'll have to assume things like PWD and PATH are sane) - export VCSH_DEBUG= - PS4='+ ' - # XXX Currently the /etc/vcsh/config file can affect testcases. # Perhaps it should be ignored if one exists in $XDG_CONFIG_HOME or was # specified with -c? @@ -15,14 +10,15 @@ setup() { # use that instead. : ${TESTREPO:='https://github.com/djpohly/vcsh_testrepo.git'} : ${TESTREPONAME:='vcsh_testrepo'} - TESTM1=master - TESTM2=master2 - TESTBR1=branch1 - TESTBR2=branch2 - TESTBRX=conflict + export TESTREPO TESTREPONAME + export TESTM1=master + export TESTM2=master2 + export TESTBR1=branch1 + export TESTBR2=branch2 + export TESTBRX=conflict # Other things used in tests - GITVERSION=$(git version) + export GITVERSION=$(git version) # Clear out environment variables that affect VCSH behavior unset VCSH_OPTION_CONFIG VCSH_REPO_D VCSH_HOOK_D VCSH_OVERLAY_D @@ -30,7 +26,7 @@ setup() { unset XDG_CONFIG_HOME # Make a directory for testing and make it $HOME - BATS_TESTDIR=$(mktemp -d -p "$BATS_TMPDIR") + export BATS_TESTDIR=$(mktemp -d -p "$BATS_TMPDIR") export HOME=$BATS_TESTDIR cd } From 60fb540c5c8762f7962cf6710dfa24023ca7aa5d Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 7 Feb 2017 21:32:22 -0600 Subject: [PATCH 015/151] add rename tests --- bats/rename.bats | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 bats/rename.bats diff --git a/bats/rename.bats b/bats/rename.bats new file mode 100644 index 00000000..2274c504 --- /dev/null +++ b/bats/rename.bats @@ -0,0 +1,26 @@ +load environment + +@test "Rename works on empty repository" { + $VCSH init foo + $VCSH rename foo bar + + run $VCSH list + [ "$status" -eq 0 ] + [ "$output" = 'bar' ] +} + +@test "Rename requires two arguments" { + ! $VCSH rename + ! $VCSH rename foo +} + +@test "Repository to be renamed must exist" { + ! $VCSH rename foo bar +} + +@test "Target of rename must not already exist" { + $VCSH init foo + $VCSH init bar + + ! $VCSH rename foo bar +} From c893ff4eddd5daea7c33133c1c7e509639979e89 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 7 Feb 2017 22:11:12 -0600 Subject: [PATCH 016/151] add some status tests --- bats/status.bats | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 bats/status.bats diff --git a/bats/status.bats b/bats/status.bats new file mode 100644 index 00000000..dd771de0 --- /dev/null +++ b/bats/status.bats @@ -0,0 +1,54 @@ +load environment + +@test "Status command correct for no repos" { + run $VCSH status + [ "$status" -eq 0 ] + [ "$output" = '' ] +} + +@test "Status command correct for empty repo" { + $VCSH init foo + + run $VCSH status + [ "$status" -eq 0 ] + [ "$output" = 'foo:' ] +} + +@test "Status command correct for multiple empty repos" { + $VCSH init foo + $VCSH init bar + + run $VCSH status + [ "$status" -eq 0 ] + [ "$output" = $'bar:\n\nfoo:' ] +} + +@test "Terse status correct for empty repo" { + $VCSH init foo + + run $VCSH status --terse + [ "$status" -eq 0 ] + [ "$output" = '' ] +} + +@test "Terse status correct for multiple empty repos" { + $VCSH init foo + $VCSH init bar + + run $VCSH status --terse + [ "$status" -eq 0 ] + [ "$output" = '' ] +} + +@test "Status colored when output to tty" { + # Requires socat to create a pseudo-tty + which socat || skip + + $VCSH init foo + touch a + $VCSH run foo git add a + $VCSH run foo git config --local color.status.added green + + run socat -u exec:"$VCSH status foo",pty,rawer stdio + [ "$output" = $'\e[32mA\e[m a' ] +} From 37e32ba385e314f08976cb1e3e35c41e27f88278 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 19 Feb 2017 00:42:29 -0600 Subject: [PATCH 017/151] add init toplevel test --- bats/init.bats | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bats/init.bats b/bats/init.bats index 4e01b1ce..f2971e90 100644 --- a/bats/init.bats +++ b/bats/init.bats @@ -15,6 +15,17 @@ load environment ! $VCSH init exists } +@test "Init creates repositories with same toplevel" { + $VCSH init foo + $VCSH init bar + + run $VCSH run foo git rev-parse --show-toplevel + toplevel="$output" + + run $VCSH run bar git rev-parse --show-toplevel + [ "$output" = "$toplevel" ] +} + @test "Init command respects alternate \$VCSH_REPO_D" { VCSH_REPO_D="$PWD/foo" $VCSH init samename VCSH_REPO_D="$PWD/bar" $VCSH init samename From 8289bd171cfd6a34edffcbeef92bafb7b4bf040e Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 23 Feb 2017 01:07:27 -0600 Subject: [PATCH 018/151] make bats tests executable themselves This will simplify use with a harness like prove. --- bats/clone.bats | 2 ++ bats/debug.bats | 2 ++ bats/help.bats | 2 ++ bats/init.bats | 2 ++ bats/list.bats | 2 ++ bats/prove.bats | 2 ++ bats/rename.bats | 2 ++ bats/status.bats | 2 ++ bats/version.bats | 2 ++ 9 files changed, 18 insertions(+) mode change 100644 => 100755 bats/clone.bats mode change 100644 => 100755 bats/debug.bats mode change 100644 => 100755 bats/help.bats mode change 100644 => 100755 bats/init.bats mode change 100644 => 100755 bats/list.bats mode change 100644 => 100755 bats/prove.bats mode change 100644 => 100755 bats/rename.bats mode change 100644 => 100755 bats/status.bats mode change 100644 => 100755 bats/version.bats diff --git a/bats/clone.bats b/bats/clone.bats old mode 100644 new mode 100755 index 8be18c16..cc40dc41 --- a/bats/clone.bats +++ b/bats/clone.bats @@ -1,3 +1,5 @@ +#!/usr/bin/env bats + load environment @test "Clone requires a remote" { diff --git a/bats/debug.bats b/bats/debug.bats old mode 100644 new mode 100755 index 58a3990d..8d6aea95 --- a/bats/debug.bats +++ b/bats/debug.bats @@ -1,3 +1,5 @@ +#!/usr/bin/env bats + load environment @test "Debug output includes git version" { diff --git a/bats/help.bats b/bats/help.bats old mode 100644 new mode 100755 index 9026339f..5fe113b8 --- a/bats/help.bats +++ b/bats/help.bats @@ -1,3 +1,5 @@ +#!/usr/bin/env bats + load environment @test "Help command succeeds" { diff --git a/bats/init.bats b/bats/init.bats old mode 100644 new mode 100755 index 4e01b1ce..fd28b0f3 --- a/bats/init.bats +++ b/bats/init.bats @@ -1,3 +1,5 @@ +#!/usr/bin/env bats + load environment @test "Init command succeeds" { diff --git a/bats/list.bats b/bats/list.bats old mode 100644 new mode 100755 index c583cf56..2337e483 --- a/bats/list.bats +++ b/bats/list.bats @@ -1,3 +1,5 @@ +#!/usr/bin/env bats + load environment @test "List command correct for no repositories" { diff --git a/bats/prove.bats b/bats/prove.bats old mode 100644 new mode 100755 index 6b344a95..81d908a4 --- a/bats/prove.bats +++ b/bats/prove.bats @@ -1,3 +1,5 @@ +#!/usr/bin/env bats + load environment @test "100-init.t" { diff --git a/bats/rename.bats b/bats/rename.bats old mode 100644 new mode 100755 index 2274c504..a371eb78 --- a/bats/rename.bats +++ b/bats/rename.bats @@ -1,3 +1,5 @@ +#!/usr/bin/env bats + load environment @test "Rename works on empty repository" { diff --git a/bats/status.bats b/bats/status.bats old mode 100644 new mode 100755 index dd771de0..6ac2d532 --- a/bats/status.bats +++ b/bats/status.bats @@ -1,3 +1,5 @@ +#!/usr/bin/env bats + load environment @test "Status command correct for no repos" { diff --git a/bats/version.bats b/bats/version.bats old mode 100644 new mode 100755 index 7350880c..1146eaa1 --- a/bats/version.bats +++ b/bats/version.bats @@ -1,3 +1,5 @@ +#!/usr/bin/env bats + load environment @test "Version command succeeds" { From 2cb9fd2ea13700b14c597dcc8658422ddd11e9e7 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 24 Feb 2017 17:58:53 -0600 Subject: [PATCH 019/151] use prove for parallel testing --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4e7b556c..9a4059df 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,10 @@ vcsh_testrepo.git: test: | vcsh_testrepo.git @if ! which git > /dev/null; then echo "'git' not found, exiting..." ; exit 1; fi @if ! which bats > /dev/null; then echo "'bats' not found; not running tests"; exit 1; fi - TESTREPO=$(PWD)/vcsh_testrepo.git TESTREPONAME=vcsh_testrepo bats ./bats + TESTREPO=$(PWD)/vcsh_testrepo.git TESTREPONAME=vcsh_testrepo prove $(filter -j%,$(MAKEFLAGS)) --timer -e bats bats/*.bats + +test-%: bats/%.bats | vcsh_testrepo.git + TESTREPO=$(PWD)/vcsh_testrepo.git TESTREPONAME=vcsh_testrepo bats $< moo: @which cowsay >/dev/null 2>&1 && cowsay "I hope you're happy now..." From 87a5df01fd611424c159e417f33323878d8e4379 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 08:17:19 -0600 Subject: [PATCH 020/151] check for prove again --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 9a4059df..a1b438e3 100644 --- a/Makefile +++ b/Makefile @@ -47,8 +47,9 @@ vcsh_testrepo.git: git clone --mirror https://github.com/djpohly/vcsh_testrepo.git test: | vcsh_testrepo.git - @if ! which git > /dev/null; then echo "'git' not found, exiting..." ; exit 1; fi - @if ! which bats > /dev/null; then echo "'bats' not found; not running tests"; exit 1; fi + @if ! which git > /dev/null; then echo "'git' not found, exiting..." ; exit 1; fi + @if ! which prove > /dev/null; then echo "'prove' not found; not running tests"; exit 1; fi + @if ! which bats > /dev/null; then echo "'bats' not found; not running tests" ; exit 1; fi TESTREPO=$(PWD)/vcsh_testrepo.git TESTREPONAME=vcsh_testrepo prove $(filter -j%,$(MAKEFLAGS)) --timer -e bats bats/*.bats test-%: bats/%.bats | vcsh_testrepo.git From 39b0a4bce402fccc6bc6eb18a6a1046bc8f53b31 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 08:21:28 -0600 Subject: [PATCH 021/151] move tests back to default t/*.t Still works with bats. --- Makefile | 4 ++-- bats/clone.bats => t/clone.t | 0 bats/debug.bats => t/debug.t | 0 {bats => t}/environment.bash | 0 bats/help.bats => t/help.t | 0 bats/init.bats => t/init.t | 0 bats/list.bats => t/list.t | 0 bats/prove.bats => t/prove.t | 0 bats/rename.bats => t/rename.t | 0 bats/status.bats => t/status.t | 0 bats/version.bats => t/version.t | 0 11 files changed, 2 insertions(+), 2 deletions(-) rename bats/clone.bats => t/clone.t (100%) rename bats/debug.bats => t/debug.t (100%) rename {bats => t}/environment.bash (100%) rename bats/help.bats => t/help.t (100%) rename bats/init.bats => t/init.t (100%) rename bats/list.bats => t/list.t (100%) rename bats/prove.bats => t/prove.t (100%) rename bats/rename.bats => t/rename.t (100%) rename bats/status.bats => t/status.t (100%) rename bats/version.bats => t/version.t (100%) diff --git a/Makefile b/Makefile index a1b438e3..dfeb17e4 100644 --- a/Makefile +++ b/Makefile @@ -50,9 +50,9 @@ test: | vcsh_testrepo.git @if ! which git > /dev/null; then echo "'git' not found, exiting..." ; exit 1; fi @if ! which prove > /dev/null; then echo "'prove' not found; not running tests"; exit 1; fi @if ! which bats > /dev/null; then echo "'bats' not found; not running tests" ; exit 1; fi - TESTREPO=$(PWD)/vcsh_testrepo.git TESTREPONAME=vcsh_testrepo prove $(filter -j%,$(MAKEFLAGS)) --timer -e bats bats/*.bats + TESTREPO=$(PWD)/vcsh_testrepo.git TESTREPONAME=vcsh_testrepo prove $(filter -j%,$(MAKEFLAGS)) --timer -e bats -test-%: bats/%.bats | vcsh_testrepo.git +test-%: t/%.t | vcsh_testrepo.git TESTREPO=$(PWD)/vcsh_testrepo.git TESTREPONAME=vcsh_testrepo bats $< moo: diff --git a/bats/clone.bats b/t/clone.t similarity index 100% rename from bats/clone.bats rename to t/clone.t diff --git a/bats/debug.bats b/t/debug.t similarity index 100% rename from bats/debug.bats rename to t/debug.t diff --git a/bats/environment.bash b/t/environment.bash similarity index 100% rename from bats/environment.bash rename to t/environment.bash diff --git a/bats/help.bats b/t/help.t similarity index 100% rename from bats/help.bats rename to t/help.t diff --git a/bats/init.bats b/t/init.t similarity index 100% rename from bats/init.bats rename to t/init.t diff --git a/bats/list.bats b/t/list.t similarity index 100% rename from bats/list.bats rename to t/list.t diff --git a/bats/prove.bats b/t/prove.t similarity index 100% rename from bats/prove.bats rename to t/prove.t diff --git a/bats/rename.bats b/t/rename.t similarity index 100% rename from bats/rename.bats rename to t/rename.t diff --git a/bats/status.bats b/t/status.t similarity index 100% rename from bats/status.bats rename to t/status.t diff --git a/bats/version.bats b/t/version.t similarity index 100% rename from bats/version.bats rename to t/version.t From 65ea97ef032f47b3c57f731593860c9f6fdab413 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 08:56:40 -0600 Subject: [PATCH 022/151] for now, skip tests that fail on existing bugs --- t/help.t | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/help.t b/t/help.t index 5fe113b8..892446d5 100755 --- a/t/help.t +++ b/t/help.t @@ -3,6 +3,7 @@ load environment @test "Help command succeeds" { + skip "BUG: help command fails" $VCSH help } @test "Help command writes to stderr and not stdout" { @@ -17,6 +18,7 @@ load environment } @test "Help command can be abbreviated (hel, he)" { + skip "BUG: help command fails" run $VCSH help local good=$output From a3130b07e4c5b51c83de1b302927a81e997bc8a1 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 09:12:03 -0600 Subject: [PATCH 023/151] add explanations to skipped tests --- t/help.t | 6 +----- t/status.t | 3 +-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/t/help.t b/t/help.t index 892446d5..914858ce 100755 --- a/t/help.t +++ b/t/help.t @@ -47,11 +47,7 @@ help_check() { @test "Help text includes init command" { help_check init; } @test "Help text includes list command" { help_check list; } @test "Help text includes list-tracked command" { help_check list-tracked; } -@test "Help text includes list-tracked-by command" { - skip - # FIXME - help_check list-tracked-by; -} +# list-tracked-by is deprecated, not shown in help @test "Help text includes list-untracked command" { help_check list-untracked; } @test "Help text includes pull command" { help_check pull; } @test "Help text includes push command" { help_check push; } diff --git a/t/status.t b/t/status.t index 6ac2d532..054f8856 100755 --- a/t/status.t +++ b/t/status.t @@ -43,8 +43,7 @@ load environment } @test "Status colored when output to tty" { - # Requires socat to create a pseudo-tty - which socat || skip + which socat || skip "socat required to create pseudo-tty" $VCSH init foo touch a From cb03daee83bb94162c89219caba87be4ef0ee4eb Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 09:13:42 -0600 Subject: [PATCH 024/151] set $TERM explicitly for color test --- t/status.t | 3 +++ 1 file changed, 3 insertions(+) diff --git a/t/status.t b/t/status.t index 054f8856..54de93ec 100755 --- a/t/status.t +++ b/t/status.t @@ -50,6 +50,9 @@ load environment $VCSH run foo git add a $VCSH run foo git config --local color.status.added green + # Ensure terminal is something Git will attempt to color + TERM=vt100 + export TERM run socat -u exec:"$VCSH status foo",pty,rawer stdio [ "$output" = $'\e[32mA\e[m a' ] } From 9e2c83931660c0421c729a670e2a0ae91f2e2ef7 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 10:38:15 -0600 Subject: [PATCH 025/151] add tests for run and enter --- t/run-enter.t | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 t/run-enter.t diff --git a/t/run-enter.t b/t/run-enter.t new file mode 100755 index 00000000..6f9de626 --- /dev/null +++ b/t/run-enter.t @@ -0,0 +1,99 @@ +#!/usr/bin/env bats + +load environment + +@test "Run executes command inside specific repository" { + $VCSH clone -b "$TESTBR1" "$TESTREPO" foo + $VCSH clone -b "$TESTBR2" "$TESTREPO" bar + + rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) + rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) + + run $VCSH run foo git rev-parse HEAD + [ "$status" -eq 0 ] + [ "$output" = "$rev1" ] + + run $VCSH run bar git rev-parse HEAD + [ "$status" -eq 0 ] + [ "$output" = "$rev2" ] +} + +@test "Run implied if no explicit command specified" { + $VCSH clone -b "$TESTBR1" "$TESTREPO" foo + $VCSH clone -b "$TESTBR2" "$TESTREPO" bar + + rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) + rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) + + run $VCSH foo rev-parse HEAD + [ "$status" -eq 0 ] + [ "$output" = "$rev1" ] + + run $VCSH bar rev-parse HEAD + [ "$status" -eq 0 ] + [ "$output" = "$rev2" ] +} + +@test "Run returns exit status of subcommand" { + $VCSH init foo + + run $VCSH run foo sh -c 'exit 104' + [ "$status" -eq 104 ] + + run $VCSH run foo sh -c 'exit 42' + [ "$status" -eq 42 ] + + run $VCSH run foo sh -c 'exit 93' + [ "$status" -eq 93 ] +} + +@test "Enter executes inside specific repository" { + $VCSH clone -b "$TESTBR1" "$TESTREPO" foo + $VCSH clone -b "$TESTBR2" "$TESTREPO" bar + + rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) + rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) + + echo 'git rev-parse HEAD > rev' | SHELL=/bin/sh $VCSH enter foo + [ "$(cat rev)" = "$rev1" ] + + echo 'git rev-parse HEAD > rev' | SHELL=/bin/sh $VCSH enter bar + [ "$(cat rev)" = "$rev2" ] +} + +@test "Enter executes \$SHELL" { + $VCSH clone -b "$TESTBR1" "$TESTREPO" foo + + rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) + SHELL='git rev-parse HEAD' run $VCSH enter foo + [ "$status" -eq 0 ] + [ "$output" = "$rev1" ] +} + +@test "Enter implied for single non-command argument" { + $VCSH clone -b "$TESTBR1" "$TESTREPO" foo + $VCSH clone -b "$TESTBR2" "$TESTREPO" bar + + rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) + rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) + + echo 'git rev-parse HEAD > rev' | SHELL=/bin/sh $VCSH foo + [ "$(cat rev)" = "$rev1" ] + + echo 'git rev-parse HEAD > rev' | SHELL=/bin/sh $VCSH bar + [ "$(cat rev)" = "$rev2" ] +} + +@test "Enter returns exit status of subshell" { + skip "BUG: enter does not pass on subshell's exit status" + $VCSH init foo + + echo 'exit 104' | SHELL=/bin/sh $VCSH enter foo + [ "$?" -eq 104 ] + + echo 'exit 42' | SHELL=/bin/sh $VCSH enter foo + [ "$?" -eq 42 ] + + echo 'exit 93' | SHELL=/bin/sh $VCSH enter foo + [ "$?" -eq 93 ] +} From 493e26d4688671bc6d4413690858a64bdb5ae2c9 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 10:53:03 -0600 Subject: [PATCH 026/151] add tests for foreach command --- t/foreach.t | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 t/foreach.t diff --git a/t/foreach.t b/t/foreach.t new file mode 100755 index 00000000..0b4dd92c --- /dev/null +++ b/t/foreach.t @@ -0,0 +1,37 @@ +#!/usr/bin/env bats + +load environment + +@test "Foreach requires an argument" { + ! $VCSH foreach +} + +@test "Foreach does nothing if no repositories exist" { + run $VCSH foreach version + [ "$status" -eq 0 ] + [ "$output" = "" ] +} + +@test "Foreach executes Git command inside each repository" { + $VCSH clone -b "$TESTBR1" "$TESTREPO" foo + $VCSH clone -b "$TESTBR2" "$TESTREPO" bar + + rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) + rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) + + run $VCSH foreach rev-parse HEAD + [ "$status" -eq 0 ] + [ "$output" = $'bar:\n'"$rev2"$'\nfoo:\n'"$rev1" ] +} + +@test "Foreach supports -g for non-Git commands" { + $VCSH clone -b "$TESTBR1" "$TESTREPO" foo + $VCSH clone -b "$TESTBR2" "$TESTREPO" bar + + rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) + rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) + + run $VCSH foreach -g echo test-output + [ "$status" -eq 0 ] + [ "$output" = $'bar:\ntest-output\nfoo:\ntest-output' ] +} From 8c2c4dc4786d05260168b8fb836bb5ea3dabdaf0 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 11:22:41 -0600 Subject: [PATCH 027/151] additional rename tests --- t/rename.t | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/t/rename.t b/t/rename.t index a371eb78..f1f707e9 100755 --- a/t/rename.t +++ b/t/rename.t @@ -2,6 +2,22 @@ load environment +@test "Rename requires two arguments" { + ! $VCSH rename + ! $VCSH rename foo +} + +@test "Repository to be renamed must exist" { + ! $VCSH rename foo bar +} + +@test "Target of rename must not already exist" { + $VCSH init foo + $VCSH init bar + + ! $VCSH rename foo bar +} + @test "Rename works on empty repository" { $VCSH init foo $VCSH rename foo bar @@ -11,18 +27,36 @@ load environment [ "$output" = 'bar' ] } -@test "Rename requires two arguments" { - ! $VCSH rename - ! $VCSH rename foo +@test "Rename works on repository with files/commits" { + $VCSH clone -b "$TESTBR1" "$TESTREPO" foo + rev=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) + + $VCSH rename foo bar + run $VCSH bar rev-parse HEAD + [ "$status" -eq 0 ] + [ "$output" = "$rev" ] } -@test "Repository to be renamed must exist" { - ! $VCSH rename foo bar +@test "Rename adopts existing .gitignore.d files under new name (bug?)" { + $VCSH init foo + + mkdir -p .gitignore.d + echo test > .gitignore.d/bar + + $VCSH rename foo bar + run $VCSH bar ls-files + [ "$status" -eq 0 ] + [ "$output" = ".gitignore.d/bar" ] } -@test "Target of rename must not already exist" { +@test "Rename adopts existing .gitattributes.d files under new name (bug?)" { $VCSH init foo - $VCSH init bar - ! $VCSH rename foo bar + mkdir -p .gitattributes.d + echo '* whitespace' > .gitattributes.d/bar + + $VCSH rename foo bar + run $VCSH bar ls-files + [ "$status" -eq 0 ] + [ "$output" = ".gitattributes.d/bar" ] } From 9a22ae6e1e55ea2146a2679128aed1a776d2e6a7 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 14:49:11 -0600 Subject: [PATCH 028/151] add tests for delete command --- t/delete.t | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100755 t/delete.t diff --git a/t/delete.t b/t/delete.t new file mode 100755 index 00000000..7892841f --- /dev/null +++ b/t/delete.t @@ -0,0 +1,152 @@ +#!/usr/bin/env bats + +load environment + +doit() { + echo "Yes, do as I say" +} + +@test "Delete requires repo name" { + ! $VCSH delete +} + +@test "Repository to be deleted must exist" { + ! $VCSH delete foo +} + +@test "Delete requires confirmation" { + $VCSH init foo + + ! $VCSH delete foo < /dev/null + run $VCSH list + [ "$status" -eq 0 ] + [ "$output" = "foo" ] + + ! echo | $VCSH delete foo + run $VCSH list + [ "$status" -eq 0 ] + [ "$output" = "foo" ] + + ! echo no | $VCSH delete foo + run $VCSH list + [ "$status" -eq 0 ] + [ "$output" = "foo" ] +} + +@test "Deleted repository removed from list" { + $VCSH init foo + $VCSH init bar + doit | $VCSH delete foo + + run $VCSH list + [ "$status" -eq 0 ] + [ "$output" = "bar" ] +} + +@test "Deleted repository cannot be subsequently used" { + $VCSH init foo + doit | $VCSH delete foo + + run $VCSH run foo echo fail + [ "$status" -ne 0 ] + [ "$output" != "fail" ] +} + +@test "Delete lists staged files before confirmation" { + $VCSH init foo + touch randomtexttofind + $VCSH foo add randomtexttofind + + : | $VCSH delete foo | grep -Fq randomtexttofind +} + +@test "Delete lists committed files before confirmation" { + $VCSH init foo + touch randomtexttofind + $VCSH foo add randomtexttofind + $VCSH foo -c user.name="A U Thor" -c user.email="author@example.com" commit -m 'a' + + : | $VCSH delete foo | grep -Fq randomtexttofind +} + +@test "Delete lists files staged for removal before confirmation" { + skip "do we want this?" + + $VCSH init foo + touch randomtexttofind + $VCSH foo add randomtexttofind + $VCSH foo -c user.name="A U Thor" -c user.email="author@example.com" commit -m 'a' + $VCSH foo rm --cached randomtexttofind + + : | $VCSH delete foo | grep -Fq randomtexttofind +} + +@test "Delete removes corresponding files" { + $VCSH init foo + $VCSH init bar + + touch a b c d e + $VCSH foo add b e + $VCSH foo -c user.name="A U Thor" -c user.email="author@example.com" commit -m 'b e' + $VCSH bar add a c + $VCSH bar -c user.name="A U Thor" -c user.email="author@example.com" commit -m 'a c' + + doit | $VCSH delete foo + [ ! -e b ] + [ ! -e e ] + [ -e a ] + [ -e c ] + [ -e d ] + + doit | $VCSH delete bar + [ ! -e a ] + [ ! -e c ] + [ -e d ] +} + +@test "Delete handles filenames with spaces properly" { + skip "BUG" + + $VCSH init foo + touch a b 'a b' + $VCSH foo add 'a b' + $VCSH foo -c user.name="A U Thor" -c user.email="author@example.com" commit -m 'a b' + + doit | $VCSH delete foo + [ ! -e 'a b' ] + [ -e a ] + [ -e b ] +} + +@test "Delete handles filenames with wildcard characters properly" { + skip "BUG" + + $VCSH init foo + touch a b '?' + $VCSH foo add '\?' + $VCSH foo -c user.name="A U Thor" -c user.email="author@example.com" commit -m '?' + + doit | $VCSH delete foo + [ ! -e '?' ] + [ -e a ] + [ -e b ] +} + +@test "Delete can be abbreviated (delet, dele, del, de)" { + $VCSH init a + $VCSH init b + $VCSH init c + $VCSH init d + + doit | $VCSH delet a + ! $VCSH list | grep -Fqx a + + doit | $VCSH dele b + ! $VCSH list | grep -Fqx b + + doit | $VCSH del c + ! $VCSH list | grep -Fqx c + + doit | $VCSH de d + ! $VCSH list | grep -Fqx d +} From ce2437fae616410d02a370c8cc61ff804b8d31a5 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 15:57:35 -0600 Subject: [PATCH 029/151] add abbreviation tests --- t/clone.t | 10 ++++++++++ t/rename.t | 13 +++++++++++++ t/run-enter.t | 22 ++++++++++++++++++++++ t/status.t | 15 +++++++++++++++ t/version.t | 11 +++++++++++ 5 files changed, 71 insertions(+) diff --git a/t/clone.t b/t/clone.t index cc40dc41..1a88f04d 100755 --- a/t/clone.t +++ b/t/clone.t @@ -87,3 +87,13 @@ load environment run $VCSH run "$TESTREPONAME" git branch [ "${#lines[@]}" -eq 1 ] } + +@test "Clone can be abbreviated (clon, clo, cl)" { + $VCSH clon "$TESTREPO" a + $VCSH clo -b "$TESTBR1" "$TESTREPO" b + $VCSH cl -b "$TESTBR2" "$TESTREPO" c + + run $VCSH list + [ "$status" -eq 0 ] + [ "$output" = "$(printf 'a\nb\nc')" ] +} diff --git a/t/rename.t b/t/rename.t index f1f707e9..a48045c6 100755 --- a/t/rename.t +++ b/t/rename.t @@ -60,3 +60,16 @@ load environment [ "$status" -eq 0 ] [ "$output" = ".gitattributes.d/bar" ] } + +@test "Rename can be abbreviated (renam, rena, ren, re)" { + $VCSH init foo + + $VCSH renam foo bar + $VCSH rena bar baz + $VCSH ren baz bat + $VCSH re bat quux + + run $VCSH list + [ "$status" -eq 0 ] + [ "$output" = "quux" ] +} diff --git a/t/run-enter.t b/t/run-enter.t index 6f9de626..0a9c98cf 100755 --- a/t/run-enter.t +++ b/t/run-enter.t @@ -34,6 +34,16 @@ load environment [ "$output" = "$rev2" ] } +@test "Run can be abbreviated (ru)" { + $VCSH clone -b "$TESTBR1" "$TESTREPO" foo + + rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) + + run $VCSH ru foo git rev-parse HEAD + [ "$status" -eq 0 ] + [ "$output" = "$rev1" ] +} + @test "Run returns exit status of subcommand" { $VCSH init foo @@ -97,3 +107,15 @@ load environment echo 'exit 93' | SHELL=/bin/sh $VCSH enter foo [ "$?" -eq 93 ] } + +@test "Enter can be abbreviated (ente, ent, en)" { + $VCSH clone -b "$TESTBR1" "$TESTREPO" foo + + rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) + + echo 'git rev-parse HEAD >> output' | SHELL=/bin/sh $VCSH ente foo + echo 'git rev-parse HEAD >> output' | SHELL=/bin/sh $VCSH ent foo + echo 'git rev-parse HEAD >> output' | SHELL=/bin/sh $VCSH en foo + + [ "$(cat output)" = "$(printf '%s\n%s\n%s' "$rev1" "$rev1" "$rev1")" ] +} diff --git a/t/status.t b/t/status.t index 54de93ec..c56bc5f1 100755 --- a/t/status.t +++ b/t/status.t @@ -56,3 +56,18 @@ load environment run socat -u exec:"$VCSH status foo",pty,rawer stdio [ "$output" = $'\e[32mA\e[m a' ] } + +@test "Status can be abbreviated (statu, stat, sta, st)" { + $VCSH init foo + touch a + $VCSH foo add a + + run $VCSH status + expected=$output + + for cmd in statu stat sta st; do + run $VCSH $cmd + [ "$status" -eq 0 ] + [ "$output" = "$expected" ] + done +} diff --git a/t/version.t b/t/version.t index 1146eaa1..11ce78c3 100755 --- a/t/version.t +++ b/t/version.t @@ -11,3 +11,14 @@ load environment [[ "${lines[0]}" = 'vcsh '[0-9]* ]] [[ "${lines[1]}" = 'git version '[0-9]* ]] } + +@test "Version can be abbreviated (versio, versi, vers, ver, ve)" { + run $VCSH version + expected=$output + + for cmd in versio versi vers ver ve; do + run $VCSH $cmd + [ "$status" -eq 0 ] + [ "$output" = "$expected" ] + done +} From e0a53258144b70bd43bb5f126507a8290f3467c0 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 15:57:51 -0600 Subject: [PATCH 030/151] better description --- t/run-enter.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/run-enter.t b/t/run-enter.t index 0a9c98cf..8633dd33 100755 --- a/t/run-enter.t +++ b/t/run-enter.t @@ -71,7 +71,7 @@ load environment [ "$(cat rev)" = "$rev2" ] } -@test "Enter executes \$SHELL" { +@test "Enter executes \$SHELL inside repository" { $VCSH clone -b "$TESTBR1" "$TESTREPO" foo rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) From 307c13bce3a91b76dc76eeb39565c775ad2f8226 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 16:08:47 -0600 Subject: [PATCH 031/151] pre-set committer/author name and email This makes commits in tests a lot easier --- t/delete.t | 12 ++++++------ t/environment.bash | 13 +++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/t/delete.t b/t/delete.t index 7892841f..d2dc40bd 100755 --- a/t/delete.t +++ b/t/delete.t @@ -64,7 +64,7 @@ doit() { $VCSH init foo touch randomtexttofind $VCSH foo add randomtexttofind - $VCSH foo -c user.name="A U Thor" -c user.email="author@example.com" commit -m 'a' + $VCSH foo commit -m 'a' : | $VCSH delete foo | grep -Fq randomtexttofind } @@ -75,7 +75,7 @@ doit() { $VCSH init foo touch randomtexttofind $VCSH foo add randomtexttofind - $VCSH foo -c user.name="A U Thor" -c user.email="author@example.com" commit -m 'a' + $VCSH foo commit -m 'a' $VCSH foo rm --cached randomtexttofind : | $VCSH delete foo | grep -Fq randomtexttofind @@ -87,9 +87,9 @@ doit() { touch a b c d e $VCSH foo add b e - $VCSH foo -c user.name="A U Thor" -c user.email="author@example.com" commit -m 'b e' + $VCSH foo commit -m 'b e' $VCSH bar add a c - $VCSH bar -c user.name="A U Thor" -c user.email="author@example.com" commit -m 'a c' + $VCSH bar commit -m 'a c' doit | $VCSH delete foo [ ! -e b ] @@ -110,7 +110,7 @@ doit() { $VCSH init foo touch a b 'a b' $VCSH foo add 'a b' - $VCSH foo -c user.name="A U Thor" -c user.email="author@example.com" commit -m 'a b' + $VCSH foo commit -m 'a b' doit | $VCSH delete foo [ ! -e 'a b' ] @@ -124,7 +124,7 @@ doit() { $VCSH init foo touch a b '?' $VCSH foo add '\?' - $VCSH foo -c user.name="A U Thor" -c user.email="author@example.com" commit -m '?' + $VCSH foo commit -m '?' doit | $VCSH delete foo [ ! -e '?' ] diff --git a/t/environment.bash b/t/environment.bash index 1269610e..a26364aa 100644 --- a/t/environment.bash +++ b/t/environment.bash @@ -29,6 +29,19 @@ setup() { export BATS_TESTDIR=$(mktemp -d -p "$BATS_TMPDIR") export HOME=$BATS_TESTDIR cd + + # Clear out variables that affect Git behavior + unset EDITOR VISUAL GIT_EDITOR + + # Set a few Git variables + GIT_AUTHOR_NAME='A U Thor' + GIT_AUTHOR_EMAIL='author@example.com' + GIT_COMMITTER_NAME='C O Mitter' + GIT_COMMITTER_EMAIL='committer@example.com' + GIT_MERGE_VERBOSITY=5 + GIT_MERGE_AUTOEDIT=no + export GIT_{AUTHOR,COMMITTER}_{NAME,EMAIL} + export GIT_MERGE_{VERBOSITY,AUTOEDIT} } teardown() { From f8ef498d74948b011680dc4a7a4659a6c497fb13 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 16:46:02 -0600 Subject: [PATCH 032/151] further tests for status command --- t/status.t | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/t/status.t b/t/status.t index c56bc5f1..61156253 100755 --- a/t/status.t +++ b/t/status.t @@ -2,6 +2,10 @@ load environment +@test "Status argument if any must be a repo" { + ! $VCSH status nope +} + @test "Status command correct for no repos" { run $VCSH status [ "$status" -eq 0 ] @@ -42,6 +46,70 @@ load environment [ "$output" = '' ] } +@test "Status shows added/modified/moved/deleted files" { + $VCSH init foo + + for f in 00 0M 0D M0 MM MD A0 AM AD D0 R0x RMx RDx oo; do + echo "$f" > "$f" + done + $VCSH foo add 00 0M 0D M0 MM MD D0 R0x RMx RDx + $VCSH foo commit -m 'commit' + + # Modified in index + for f in M?; do + echo changed > $f + done + $VCSH foo add M? + + # Added to index + $VCSH foo add A? + + # Deleted in index + $VCSH foo rm -q --cached D? + + # Renamed in index + for f in R?x; do + $VCSH foo mv "$f" "${f%x}" + done + + # Modified locally + for f in ?M; do + echo localchanged > $f + done + + # Deleted locally + rm ?D + + run $VCSH status + [ "$status" -eq 0 ] + [ "$output" = "$(printf '%s\n' \ + 'foo:' \ + ' D 0D' \ + ' M 0M' \ + 'A A0' \ + 'AD AD' \ + 'AM AM' \ + 'D D0' \ + 'M M0' \ + 'MD MD' \ + 'MM MM' \ + 'R R0x -> R0' \ + 'RD RDx -> RD' \ + 'RM RMx -> RM')" ] +} + +@test "Status shows commits behind upstream" { + skip "Test not yet implemented" +} + +@test "Status shows commits ahead of upstream" { + skip "Test not yet implemented" +} + +@test "Status shows commits behind and ahead of upstream" { + skip "Test not yet implemented" +} + @test "Status colored when output to tty" { which socat || skip "socat required to create pseudo-tty" From 74842449f1708c9ce2f8662b72b263936dc182e0 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 17:22:20 -0600 Subject: [PATCH 033/151] add tests for which command --- t/which.t | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100755 t/which.t diff --git a/t/which.t b/t/which.t new file mode 100755 index 00000000..5b8a2c37 --- /dev/null +++ b/t/which.t @@ -0,0 +1,134 @@ +#!/usr/bin/env bats + +load environment + +@test "Which command requires exactly one parameter" { + ! $VCSH which + ! $VCSH which foo bar +} + +@test "Which command does not accept an empty parameter" { + ! $VCSH which '' +} + +@test "Which command fails if no repositories" { + ! $VCSH which nope +} + +@test "Which command fails if pattern not found" { + $VCSH init foo + + touch a + $VCSH foo add a + $VCSH foo commit -m 'a' + + ! $VCSH which nope +} + +@test "Which command matches exact filename" { + $VCSH init foo + + touch hello testfile + $VCSH foo add hello testfile + $VCSH foo commit -m 'testfile' + + run $VCSH which testfile + [ "$status" -eq 0 ] + [ "$output" = "foo: testfile" ] +} + +@test "Which command matches entire path" { + $VCSH init foo + + mkdir -p dir + touch hello dir/testfile + $VCSH foo add hello dir/testfile + $VCSH foo commit -m 'dir/testfile' + + run $VCSH which dir/testfile + [ "$status" -eq 0 ] + [ "$output" = "foo: dir/testfile" ] +} + +@test "Which command matches filename within subdirectory" { + $VCSH init foo + + mkdir -p dir + touch hello dir/testfile + $VCSH foo add hello dir/testfile + $VCSH foo commit -m 'dir/testfile' + + run $VCSH which testfile + [ "$status" -eq 0 ] + [ "$output" = "foo: dir/testfile" ] +} + +@test "Which command matches directory path component" { + $VCSH init foo + + mkdir -p dir/subd + touch hello dir/subd/testfile + $VCSH foo add hello dir/subd/testfile + $VCSH foo commit -m 'dir/subd/testfile' + + run $VCSH which subd + [ "$status" -eq 0 ] + [ "$output" = "foo: dir/subd/testfile" ] +} + +@test "Which command matches partial filename" { + $VCSH init foo + + mkdir -p dir/subd + touch hello dir/subd/testfile + $VCSH foo add hello dir/subd/testfile + $VCSH foo commit -m 'dir/subd/testfile' + + run $VCSH which estf + [ "$status" -eq 0 ] + [ "$output" = "foo: dir/subd/testfile" ] +} + +@test "Which command matches partial path component across slash" { + $VCSH init foo + + mkdir -p dir/subd + touch hello dir/subd/testfile + $VCSH foo add hello dir/subd/testfile + $VCSH foo commit -m 'dir/subd/testfile' + + run $VCSH which bd/te + [ "$status" -eq 0 ] + [ "$output" = "foo: dir/subd/testfile" ] +} + +@test "Which command matches using POSIX BRE" { + $VCSH init foo + + touch calor color colour 'colou?r' + $VCSH foo add * + $VCSH foo commit -m 'color' + + run $VCSH which 'c.lou\?r' + [ "$status" -eq 0 ] + [ "$output" = "$(printf 'foo: calor\nfoo: color\nfoo: colour')" ] +} + +@test "Which command searches all repos" { + $VCSH init foo + $VCSH init bar + $VCSH init baz + + mkdir -p a b c + touch {a,b,c}/{hello,goodbye} + $VCSH foo add a + $VCSH foo commit -m 'hello' + $VCSH bar add b + $VCSH bar commit -m 'hello' + $VCSH baz add c + $VCSH baz commit -m 'hello' + + run $VCSH which hello + [ "$status" -eq 0 ] + [ "$output" = "$(printf 'bar: b/hello\nbaz: c/hello\nfoo: a/hello')" ] +} From b5dd2edbc16934656f868dd135963dde4e6b8995 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 17:57:04 -0600 Subject: [PATCH 034/151] tests for list-tracked command --- t/list-tracked.t | 127 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100755 t/list-tracked.t diff --git a/t/list-tracked.t b/t/list-tracked.t new file mode 100755 index 00000000..f4ef4cd2 --- /dev/null +++ b/t/list-tracked.t @@ -0,0 +1,127 @@ +#!/usr/bin/env bats + +load environment + +@test "list-tracked command works with no repos" { + run $VCSH list-tracked + [ "$status" -eq 0 ] + [ "$output" = "" ] +} + +@test "list-tracked command works with no repos and untracked files" { + touch a b c d e + + run $VCSH list-tracked + [ "$status" -eq 0 ] + [ "$output" = "" ] +} + +@test "list-tracked fails if argument is not a repo" { + skip "BUG" + + ! $VCSH list-tracked nope +} + +@test "list-tracked works on empty repo" { + touch a b c d e + + $VCSH init foo + run $VCSH list-tracked + [ "$status" -eq 0 ] + [ "$output" = "" ] +} + +@test "list-tracked lists files from one repo" { + $VCSH init foo + + touch a b c d e + $VCSH foo add a d + $VCSH foo commit -m 'a d' + + run $VCSH list-tracked + [ "$status" -eq 0 ] + [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/d")" ] +} + +@test "list-tracked lists files from two repos" { + $VCSH init foo + $VCSH init bar + + touch a b c d e + $VCSH foo add a b + $VCSH foo commit -m 'a b' + $VCSH bar add c d + $VCSH bar commit -m 'c d' + + run $VCSH list-tracked + [ "$status" -eq 0 ] + [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b" "$HOME/c" "$HOME/d")" ] +} + +@test "list-tracked lists files from specified repo" { + $VCSH init foo + $VCSH init bar + + touch a b c d e + $VCSH foo add a b + $VCSH foo commit -m 'a b' + $VCSH bar add c d + $VCSH bar commit -m 'c d' + + run $VCSH list-tracked foo + [ "$status" -eq 0 ] + [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" ] + + run $VCSH list-tracked bar + [ "$status" -eq 0 ] + [ "$output" = "$(printf '%s\n' "$HOME/c" "$HOME/d")" ] +} + +@test "list-tracked orders files by path" { + $VCSH init foo + $VCSH init bar + + touch a b c d e + $VCSH foo add a d + $VCSH foo commit -m 'a d' + $VCSH bar add b e + $VCSH bar commit -m 'b e' + + run $VCSH list-tracked + [ "$status" -eq 0 ] + [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b" "$HOME/d" "$HOME/e")" ] +} + +@test "list-tracked does not repeat multiple-tracked files" { + $VCSH init foo + $VCSH init bar + + touch a b + $VCSH foo add a b + $VCSH foo commit -m 'a b' + $VCSH bar add a b + $VCSH bar commit -m 'a b' + + run $VCSH list-tracked + [ "$status" -eq 0 ] + [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" ] +} + +@test "list-tracked accepts each repo for multiple-tracked files" { + $VCSH init foo + $VCSH init bar + + touch a b + $VCSH foo add a b + $VCSH foo commit -m 'a b' + $VCSH bar add a b + $VCSH bar commit -m 'a b' + + run $VCSH list-tracked foo + [ "$status" -eq 0 ] + [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" ] + + run $VCSH list-tracked bar + [ "$status" -eq 0 ] + [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" ] +} From e4bcecce64bf8bbd1ca608722a75c9e61acc907b Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 18:01:48 -0600 Subject: [PATCH 035/151] tests for list-tracked-by (deprecated) --- t/list-tracked.t | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/t/list-tracked.t b/t/list-tracked.t index f4ef4cd2..e55b0548 100755 --- a/t/list-tracked.t +++ b/t/list-tracked.t @@ -2,7 +2,7 @@ load environment -@test "list-tracked command works with no repos" { +@test "list-tracked works with no repos" { run $VCSH list-tracked [ "$status" -eq 0 ] [ "$output" = "" ] @@ -125,3 +125,32 @@ load environment [ "$status" -eq 0 ] [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" ] } + +@test "list-tracked-by requires an argument" { + ! $VCSH list-tracked-by +} + +@test "list-tracked-by fails if argument is not a repo" { + skip "BUG" + + ! $VCSH list-tracked-by nope +} + +@test "list-tracked-by lists files from specified repo" { + $VCSH init foo + $VCSH init bar + + touch a b c d e + $VCSH foo add a b + $VCSH foo commit -m 'a b' + $VCSH bar add c d + $VCSH bar commit -m 'c d' + + run $VCSH list-tracked-by foo + [ "$status" -eq 0 ] + [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" ] + + run $VCSH list-tracked-by bar + [ "$status" -eq 0 ] + [ "$output" = "$(printf '%s\n' "$HOME/c" "$HOME/d")" ] +} From 4bbf1ff0714a2f31f02c7c3052739ea20c46496a Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 22:16:18 -0600 Subject: [PATCH 036/151] add tests for commit commit is currently broken due to missing arg shift --- t/commit.t | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100755 t/commit.t diff --git a/t/commit.t b/t/commit.t new file mode 100755 index 00000000..1bbcfdc9 --- /dev/null +++ b/t/commit.t @@ -0,0 +1,90 @@ +#!/usr/bin/env bats + +load environment + +@test "commit works with no repos" { + run $VCSH commit + [ "$status" -eq 0 ] + [ "$output" = "" ] +} + +@test "commit works with single repo" { + skip "BUG: commit is broken" + + $VCSH init foo + + touch a + $VCSH foo add a + run $VCSH commit -m 'a' + [ "$status" -eq 0 ] + # XXX Is printing a trailing space really intended? + [ "$output" = "foo: " ] + + run $VCSH foo rev-list HEAD --count + [ "$status" -eq 0 ] + [ "$output" = "1" ] +} + +@test "commit works with multiple repos" { + skip "BUG: commit is broken" + + $VCSH init foo + $VCSH init bar + + touch a b + $VCSH foo add a + $VCSH bar add b + run $VCSH commit -m 'ab' + [ "$status" -eq 0 ] + # XXX Is printing a trailing space and blank line really intended? + [ "$output" = "$(printf 'bar: \n\nfoo: ')" ] + + $VCSH foo log --oneline | grep -qx '....... ab' + $VCSH bar log --oneline | grep -qx '....... ab' +} + +@test "commit can handle arguments with spaces" { + skip "BUG: commit is broken" + + $VCSH init foo + $VCSH init bar + + touch a b + $VCSH foo add a + $VCSH bar add b + run $VCSH commit -m 'log message' + [ "$status" -eq 0 ] + # XXX Is printing a trailing space and blank line really intended? + [ "$output" = "$(printf 'bar: \n\nfoo: ')" ] + + $VCSH foo log --oneline | grep -qx '....... log message' + $VCSH bar log --oneline | grep -qx '....... log message' +} + +@test "commit works even if not all repos have changes" { + skip "BUG: commit is broken" + + $VCSH init foo + $VCSH init bar + + touch a b + $VCSH foo add a + $VCSH commit -m 'part1' + + $VCSH bar add b + $VCSH commit -m 'part2' + + $VCSH foo log --oneline | grep -qx '....... part1' + $VCSH bar log --oneline | grep -qx '....... part2' +} + +@test "commit not affected by existing \$VCSH_COMMAND_RETURN_CODE" { + skip "BUG" + + VCSH_COMMAND_RETURN_CODE=1 + export VCSH_COMMAND_RETURN_CODE + + run $VCSH commit + [ "$status" -eq 0 ] + [ "$output" = "" ] +} From cac563634cb0ecfe56fb0c1aebca1b27f9fe4546 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 22:58:59 -0600 Subject: [PATCH 037/151] more of the old tests are replaced now --- t/delete.t | 9 +++++++++ t/prove.t | 24 ------------------------ 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/t/delete.t b/t/delete.t index d2dc40bd..e4ae9e29 100755 --- a/t/delete.t +++ b/t/delete.t @@ -43,6 +43,15 @@ doit() { [ "$output" = "bar" ] } +@test "Deleted repository not in status" { + $VCSH init foo + doit | $VCSH delete foo + + run $VCSH status + [ "$status" -eq 0 ] + [ "$output" = "" ] +} + @test "Deleted repository cannot be subsequently used" { $VCSH init foo doit | $VCSH delete foo diff --git a/t/prove.t b/t/prove.t index 81d908a4..22559e0b 100755 --- a/t/prove.t +++ b/t/prove.t @@ -2,21 +2,6 @@ load environment -@test "100-init.t" { - run $VCSH status - [ "$status" -eq 0 ] - [ "$output" = "" ] - - run $VCSH init test1 - [ "$status" -eq 0 ] - [ "$output" = "Initialized empty shared Git repository in $HOME/.config/vcsh/repo.d/test1.git/" ] - - run $VCSH status - echo "'$output'" - [ "$status" -eq 0 ] - [ "$output" = 'test1:' ] -} - @test "300-add.t" { $VCSH init test1 $VCSH init test2 @@ -32,12 +17,3 @@ load environment [ "$status" -eq 0 ] [ "$output" = $'test2:\nA a' ] } - -@test "950-delete.t" { - $VCSH init test1 - echo 'Yes, do as I say' | run $VCSH delete test1 - - run $VCSH status - [ "$status" -eq 0 ] - [ "$output" = '' ] -} From 56b80670caa36a2dd37a43ce8e4804a53e6dd586 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 23:16:57 -0600 Subject: [PATCH 038/151] tests for pull, almost there! --- t/pull.t | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 t/pull.t diff --git a/t/pull.t b/t/pull.t new file mode 100755 index 00000000..c5858b69 --- /dev/null +++ b/t/pull.t @@ -0,0 +1,85 @@ +#!/usr/bin/env bats + +load environment + +@test "pull works with no repositories" { + run $VCSH pull + [ "$status" -eq 0 ] + [ "$output" = "" ] +} + +@test "pull succeeds if up-to-date" { + git clone "$TESTREPO" upstream + + $VCSH clone upstream foo + run $VCSH pull + [ "$status" -eq 0 ] + [ "$output" = "foo: Already up-to-date." ] +} + +@test "pull works with one repository" { + git clone "$TESTREPO" upstream + + $VCSH clone upstream foo + git -C upstream commit --allow-empty -m 'empty' + run git -C upstream rev-parse HEAD + rev=$output + + $VCSH pull + run $VCSH foo rev-parse HEAD + [ "$status" -eq 0 ] + [ "$output" = "$rev" ] +} + +@test "pull works with multiple repositories" { + git clone -b "$TESTBR1" "$TESTREPO" upstream1 + git clone -b "$TESTBR2" "$TESTREPO" upstream2 + + $VCSH clone -b "$TESTBR1" upstream1 foo + $VCSH clone -b "$TESTBR2" upstream2 bar + + git -C upstream1 commit --allow-empty -m 'empty' + run git -C upstream1 rev-parse HEAD + rev1=$output + + git -C upstream2 commit --allow-empty -m 'empty' + run git -C upstream2 rev-parse HEAD + rev2=$output + + $VCSH pull + + run $VCSH foo rev-parse HEAD + [ "$status" -eq 0 ] + [ "$output" = "$rev1" ] + run $VCSH bar rev-parse HEAD + [ "$status" -eq 0 ] + [ "$output" = "$rev2" ] +} + +@test "pull fails if first pull fails" { + skip "BUG" + + git clone -b "$TESTBR1" "$TESTREPO" upstream1 + git clone -b "$TESTBR2" "$TESTREPO" upstream2 + + $VCSH clone -b "$TESTBR1" upstream1 a + $VCSH clone -b "$TESTBR2" upstream2 b + + rm -rf upstream1 + git -C upstream2 commit --allow-empty -m 'empty' + + ! $VCSH pull +} + +@test "pull fails if last pull fails" { + git clone -b "$TESTBR1" "$TESTREPO" upstream1 + git clone -b "$TESTBR2" "$TESTREPO" upstream2 + + $VCSH clone -b "$TESTBR1" upstream1 a + $VCSH clone -b "$TESTBR2" upstream2 b + + git -C upstream1 commit --allow-empty -m 'empty' + rm -rf upstream2 + + ! $VCSH pull +} From ca9244eedd6b8f5d2ddec6c4d06e48e5bd4608b4 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 25 Feb 2017 23:23:35 -0600 Subject: [PATCH 039/151] tests for push This finishes the major commands, leaving write-gitignore, upgrade, and the (messy and inconsistent) list-untracked, plus tests for features such as hooks and configuration files. --- t/push.t | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 t/push.t diff --git a/t/push.t b/t/push.t new file mode 100755 index 00000000..3f2f1b9b --- /dev/null +++ b/t/push.t @@ -0,0 +1,86 @@ +#!/usr/bin/env bats + +load environment + +@test "push works with no repositories" { + run $VCSH push + [ "$status" -eq 0 ] + [ "$output" = "" ] +} + +@test "push succeeds if up-to-date" { + git clone "$TESTREPO" upstream.git + + $VCSH clone upstream.git foo + run $VCSH push + [ "$status" -eq 0 ] + [ "$output" = "foo: Everything up-to-date" ] +} + +@test "push works with one repository" { + git clone --bare "$TESTREPO" upstream.git + + $VCSH clone upstream.git foo + $VCSH foo commit --allow-empty -m 'empty' + run $VCSH foo rev-parse HEAD + rev=$output + + $VCSH push + + run git -C upstream.git rev-parse HEAD + [ "$status" -eq 0 ] + [ "$output" = "$rev" ] +} + +@test "push works with multiple repositories" { + git clone --bare -b "$TESTBR1" "$TESTREPO" upstream1.git + git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git + + $VCSH clone -b "$TESTBR1" upstream1.git foo + $VCSH clone -b "$TESTBR2" upstream2.git bar + + $VCSH foo commit --allow-empty -m 'empty' + run $VCSH foo rev-parse HEAD + rev1=$output + + $VCSH bar commit --allow-empty -m 'empty' + run $VCSH bar rev-parse HEAD + rev2=$output + + $VCSH push + + run git -C upstream1.git rev-parse HEAD + [ "$status" -eq 0 ] + [ "$output" = "$rev1" ] + run git -C upstream2.git rev-parse HEAD + [ "$status" -eq 0 ] + [ "$output" = "$rev2" ] +} + +@test "push fails if first push fails" { + skip "BUG" + + git clone --bare -b "$TESTBR1" "$TESTREPO" upstream1.git + git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git + + $VCSH clone -b "$TESTBR1" upstream1.git a + $VCSH clone -b "$TESTBR2" upstream2.git b + + rm -rf upstream1.git + $VCSH b commit --allow-empty -m 'empty' + + ! $VCSH push +} + +@test "push fails if last push fails" { + git clone --bare -b "$TESTBR1" "$TESTREPO" upstream1.git + git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git + + $VCSH clone -b "$TESTBR1" upstream1.git a + $VCSH clone -b "$TESTBR2" upstream2.git b + + $VCSH a commit --allow-empty -m 'empty' + rm -rf upstream2.git + + ! $VCSH push +} From 6be27c11ea683ce08aa328eb9261ced4d82794cf Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 26 Feb 2017 00:40:08 -0600 Subject: [PATCH 040/151] squelch messages from older gits --- t/push.t | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/t/push.t b/t/push.t index 3f2f1b9b..106bec59 100755 --- a/t/push.t +++ b/t/push.t @@ -9,9 +9,10 @@ load environment } @test "push succeeds if up-to-date" { - git clone "$TESTREPO" upstream.git + git clone --bare "$TESTREPO" upstream.git $VCSH clone upstream.git foo + $VCSH foo config push.default simple run $VCSH push [ "$status" -eq 0 ] [ "$output" = "foo: Everything up-to-date" ] @@ -21,6 +22,7 @@ load environment git clone --bare "$TESTREPO" upstream.git $VCSH clone upstream.git foo + $VCSH foo config push.default simple $VCSH foo commit --allow-empty -m 'empty' run $VCSH foo rev-parse HEAD rev=$output @@ -37,7 +39,9 @@ load environment git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git $VCSH clone -b "$TESTBR1" upstream1.git foo + $VCSH foo config push.default simple $VCSH clone -b "$TESTBR2" upstream2.git bar + $VCSH bar config push.default simple $VCSH foo commit --allow-empty -m 'empty' run $VCSH foo rev-parse HEAD @@ -64,7 +68,9 @@ load environment git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git $VCSH clone -b "$TESTBR1" upstream1.git a + $VCSH foo config push.default simple $VCSH clone -b "$TESTBR2" upstream2.git b + $VCSH bar config push.default simple rm -rf upstream1.git $VCSH b commit --allow-empty -m 'empty' @@ -77,7 +83,9 @@ load environment git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git $VCSH clone -b "$TESTBR1" upstream1.git a + $VCSH a config push.default simple $VCSH clone -b "$TESTBR2" upstream2.git b + $VCSH b config push.default simple $VCSH a commit --allow-empty -m 'empty' rm -rf upstream2.git From d8117403b12dc839cf0a29216126204bcd7acaed Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 26 Feb 2017 00:42:38 -0600 Subject: [PATCH 041/151] Update Travis script for new tests --- .travis.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index be5a1d79..c92ebc5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,13 @@ -language: perl -before_install: - - cpanm Shell::Command - - cpanm Test::Most - - apt-get moo +sudo: false +language: bash install: - - sudo apt-get update - - sudo apt-get install cowsay git ruby-ronn + - git clone --depth 1 https://github.com/sstephenson/bats + - bats/install.sh "$HOME/.local" +before_script: + - export PATH="$HOME/.local/bin:$PATH" + - echo '-v' > "$HOME/.proverc" script: - make test -after_script: - - make moo notifications: email: on_success: change From 345bb3dd83be1dd667d8b59b90e252ee2fc0c4b6 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 26 Feb 2017 00:47:49 -0600 Subject: [PATCH 042/151] update Travis indicator in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f885b4a3..422aad8f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ vcsh - Version Control System for $HOME - multiple Git repositories in $HOME -[![Build Status](https://travis-ci.org/RichiH/vcsh.svg?branch=master)](https://travis-ci.org/RichiH/vcsh) +[![Build Status](https://travis-ci.org/djpohly/vcsh.svg?branch=bats)](https://travis-ci.org/djpohly/vcsh) # Index From cc9d00ee4e08fa333a4942d5c16c0c55248b1e56 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 26 Feb 2017 21:07:31 -0600 Subject: [PATCH 043/151] assert(): fail more verbosely when testing Some more such functions would be good: assert_exists, assert_noexists, and something along the lines of assert_matches or assert_contains are what come to mind. --- t/clone.t | 40 +++++++++++++++++------------------ t/commit.t | 24 ++++++++++----------- t/delete.t | 24 ++++++++++----------- t/environment.bash | 14 +++++++++++++ t/foreach.t | 12 +++++------ t/help.t | 8 +++---- t/init.t | 16 +++++++------- t/list-tracked.t | 52 +++++++++++++++++++++++----------------------- t/list.t | 52 +++++++++++++++++++++++----------------------- t/prove.t | 8 +++---- t/pull.t | 20 +++++++++--------- t/push.t | 20 +++++++++--------- t/rename.t | 20 +++++++++--------- t/run-enter.t | 46 ++++++++++++++++++++-------------------- t/status.t | 32 ++++++++++++++-------------- t/version.t | 4 ++-- t/which.t | 32 ++++++++++++++-------------- 17 files changed, 219 insertions(+), 205 deletions(-) diff --git a/t/clone.t b/t/clone.t index 1a88f04d..9ce6ec86 100755 --- a/t/clone.t +++ b/t/clone.t @@ -4,22 +4,22 @@ load environment @test "Clone requires a remote" { run $VCSH clone - [ "$status" -eq 1 ] + assert "$status" -eq 1 } @test "Clone uses existing repo name by default" { $VCSH clone "$TESTREPO" $VCSH list run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = "$TESTREPONAME" ] + assert "$status" -eq 0 + assert "$output" = "$TESTREPONAME" } @test "Clone honors specified repo name" { $VCSH clone "$TESTREPO" foo run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = "foo" ] + assert "$status" -eq 0 + assert "$output" = "foo" } @test "Clone uses given remote HEAD by default" { @@ -28,8 +28,8 @@ load environment correct=${output::40} run $VCSH run "$TESTREPONAME" git rev-parse HEAD - [ "$status" -eq 0 ] - [ "$output" = "$correct" ] + assert "$status" -eq 0 + assert "$output" = "$correct" } @test "Clone honors -b option before remote" { @@ -38,8 +38,8 @@ load environment correct=${output::40} run $VCSH run "$TESTREPONAME" git rev-parse "$TESTBR1" - [ "$status" -eq 0 ] - [ "$output" = "$correct" ] + assert "$status" -eq 0 + assert "$output" = "$correct" } @test "Clone honors -b option before remote and repo name" { @@ -48,8 +48,8 @@ load environment correct=${output::40} run $VCSH run foo git rev-parse "$TESTBR1" - [ "$status" -eq 0 ] - [ "$output" = "$correct" ] + assert "$status" -eq 0 + assert "$output" = "$correct" } @test "Clone honors -b option after remote" { @@ -58,8 +58,8 @@ load environment correct=${output::40} run $VCSH run "$TESTREPONAME" git rev-parse "$TESTBR1" - [ "$status" -eq 0 ] - [ "$output" = "$correct" ] + assert "$status" -eq 0 + assert "$output" = "$correct" } @test "Clone honors -b option between remote and repo name" { @@ -68,8 +68,8 @@ load environment correct=${output::40} run $VCSH run foo git rev-parse "$TESTBR1" - [ "$status" -eq 0 ] - [ "$output" = "$correct" ] + assert "$status" -eq 0 + assert "$output" = "$correct" } @test "Clone honors -b option after repo name" { @@ -78,14 +78,14 @@ load environment correct=${output::40} run $VCSH run foo git rev-parse "$TESTBR1" - [ "$status" -eq 0 ] - [ "$output" = "$correct" ] + assert "$status" -eq 0 + assert "$output" = "$correct" } @test "Clone -b option clones only one branch" { $VCSH clone -b "$TESTBR1" "$TESTREPO" run $VCSH run "$TESTREPONAME" git branch - [ "${#lines[@]}" -eq 1 ] + assert "${#lines[@]}" -eq 1 } @test "Clone can be abbreviated (clon, clo, cl)" { @@ -94,6 +94,6 @@ load environment $VCSH cl -b "$TESTBR2" "$TESTREPO" c run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = "$(printf 'a\nb\nc')" ] + assert "$status" -eq 0 + assert "$output" = "$(printf 'a\nb\nc')" } diff --git a/t/commit.t b/t/commit.t index 1bbcfdc9..2841ce9e 100755 --- a/t/commit.t +++ b/t/commit.t @@ -4,8 +4,8 @@ load environment @test "commit works with no repos" { run $VCSH commit - [ "$status" -eq 0 ] - [ "$output" = "" ] + assert "$status" -eq 0 + assert "$output" = "" } @test "commit works with single repo" { @@ -16,13 +16,13 @@ load environment touch a $VCSH foo add a run $VCSH commit -m 'a' - [ "$status" -eq 0 ] + assert "$status" -eq 0 # XXX Is printing a trailing space really intended? - [ "$output" = "foo: " ] + assert "$output" = "foo: " run $VCSH foo rev-list HEAD --count - [ "$status" -eq 0 ] - [ "$output" = "1" ] + assert "$status" -eq 0 + assert "$output" = "1" } @test "commit works with multiple repos" { @@ -35,9 +35,9 @@ load environment $VCSH foo add a $VCSH bar add b run $VCSH commit -m 'ab' - [ "$status" -eq 0 ] + assert "$status" -eq 0 # XXX Is printing a trailing space and blank line really intended? - [ "$output" = "$(printf 'bar: \n\nfoo: ')" ] + assert "$output" = "$(printf 'bar: \n\nfoo: ')" $VCSH foo log --oneline | grep -qx '....... ab' $VCSH bar log --oneline | grep -qx '....... ab' @@ -53,9 +53,9 @@ load environment $VCSH foo add a $VCSH bar add b run $VCSH commit -m 'log message' - [ "$status" -eq 0 ] + assert "$status" -eq 0 # XXX Is printing a trailing space and blank line really intended? - [ "$output" = "$(printf 'bar: \n\nfoo: ')" ] + assert "$output" = "$(printf 'bar: \n\nfoo: ')" $VCSH foo log --oneline | grep -qx '....... log message' $VCSH bar log --oneline | grep -qx '....... log message' @@ -85,6 +85,6 @@ load environment export VCSH_COMMAND_RETURN_CODE run $VCSH commit - [ "$status" -eq 0 ] - [ "$output" = "" ] + assert "$status" -eq 0 + assert "$output" = "" } diff --git a/t/delete.t b/t/delete.t index e4ae9e29..ea329b53 100755 --- a/t/delete.t +++ b/t/delete.t @@ -19,18 +19,18 @@ doit() { ! $VCSH delete foo < /dev/null run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = "foo" ] + assert "$status" -eq 0 + assert "$output" = "foo" ! echo | $VCSH delete foo run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = "foo" ] + assert "$status" -eq 0 + assert "$output" = "foo" ! echo no | $VCSH delete foo run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = "foo" ] + assert "$status" -eq 0 + assert "$output" = "foo" } @test "Deleted repository removed from list" { @@ -39,8 +39,8 @@ doit() { doit | $VCSH delete foo run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = "bar" ] + assert "$status" -eq 0 + assert "$output" = "bar" } @test "Deleted repository not in status" { @@ -48,8 +48,8 @@ doit() { doit | $VCSH delete foo run $VCSH status - [ "$status" -eq 0 ] - [ "$output" = "" ] + assert "$status" -eq 0 + assert "$output" = "" } @test "Deleted repository cannot be subsequently used" { @@ -57,8 +57,8 @@ doit() { doit | $VCSH delete foo run $VCSH run foo echo fail - [ "$status" -ne 0 ] - [ "$output" != "fail" ] + assert "$status" -ne 0 + assert "$output" != "fail" } @test "Delete lists staged files before confirmation" { diff --git a/t/environment.bash b/t/environment.bash index a26364aa..99819123 100644 --- a/t/environment.bash +++ b/t/environment.bash @@ -57,3 +57,17 @@ num_gitrepos() { # Prints the number of apparent Git repositories below $1 find "$1" -mindepth 1 -type d -name '*.git' | wc -l } + +assert() { + if [ $# -ne 3 ]; then + echo 'assert: requires three arguments (forgot to quote?)' >&2 + return 2 + fi + + if ! test "$@"; then + echo "assertion \"$2\" failed" >&2 + echo "actual : \"$1\"" >&2 + echo "reference: \"$3\"" >&2 + return 1 + fi +} diff --git a/t/foreach.t b/t/foreach.t index 0b4dd92c..3b72baf5 100755 --- a/t/foreach.t +++ b/t/foreach.t @@ -8,8 +8,8 @@ load environment @test "Foreach does nothing if no repositories exist" { run $VCSH foreach version - [ "$status" -eq 0 ] - [ "$output" = "" ] + assert "$status" -eq 0 + assert "$output" = "" } @test "Foreach executes Git command inside each repository" { @@ -20,8 +20,8 @@ load environment rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) run $VCSH foreach rev-parse HEAD - [ "$status" -eq 0 ] - [ "$output" = $'bar:\n'"$rev2"$'\nfoo:\n'"$rev1" ] + assert "$status" -eq 0 + assert "$output" = $'bar:\n'"$rev2"$'\nfoo:\n'"$rev1" } @test "Foreach supports -g for non-Git commands" { @@ -32,6 +32,6 @@ load environment rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) run $VCSH foreach -g echo test-output - [ "$status" -eq 0 ] - [ "$output" = $'bar:\ntest-output\nfoo:\ntest-output' ] + assert "$status" -eq 0 + assert "$output" = $'bar:\ntest-output\nfoo:\ntest-output' } diff --git a/t/help.t b/t/help.t index 914858ce..cd2aa600 100755 --- a/t/help.t +++ b/t/help.t @@ -23,12 +23,12 @@ load environment local good=$output run $VCSH hel - [ "$status" -eq 0 ] - [ "$output" = "$good" ] + assert "$status" -eq 0 + assert "$output" = "$good" run $VCSH he - [ "$status" -eq 0 ] - [ "$output" = "$good" ] + assert "$status" -eq 0 + assert "$output" = "$good" } # Help should explain each command. (Note: adjust the help_check function if diff --git a/t/init.t b/t/init.t index 7c2e0d8f..f6b0390a 100755 --- a/t/init.t +++ b/t/init.t @@ -25,7 +25,7 @@ load environment toplevel="$output" run $VCSH run bar git rev-parse --show-toplevel - [ "$output" = "$toplevel" ] + assert "$output" = "$toplevel" } @test "Init command respects alternate \$VCSH_REPO_D" { @@ -54,8 +54,8 @@ load environment $VCSH in test2 run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = $'test1\ntest2' ] + assert "$status" -eq 0 + assert "$output" = $'test1\ntest2' } @test "\$VCSH_REPO_D overrides \$XDG_CONFIG_HOME and \$HOME for init" { @@ -78,15 +78,15 @@ load environment $VCSH init test1 run $VCSH run test1 git config vcsh.vcsh - [ "$status" -eq 0 ] - [ "$output" = "true" ] + assert "$status" -eq 0 + assert "$output" = "true" } @test "Files created by init are not readable by other users" { # verifies commit e220a61 $VCSH init foo run find "$PWD" -type f -perm /g+rwx,o+rwx - [ "$output" = '' ] + assert "$output" = '' } @test "Init command adds matching gitignore.d files" { @@ -99,12 +99,12 @@ load environment @test "Init command creates new Git repository" { run num_gitrepos "$PWD" - [ "$output" = '0' ] + assert "$output" = '0' for i in $(seq 5); do $VCSH init "test$i" run num_gitrepos "$PWD" - [ "$output" = "$i" ] + assert "$output" = "$i" done } diff --git a/t/list-tracked.t b/t/list-tracked.t index e55b0548..7840b512 100755 --- a/t/list-tracked.t +++ b/t/list-tracked.t @@ -4,16 +4,16 @@ load environment @test "list-tracked works with no repos" { run $VCSH list-tracked - [ "$status" -eq 0 ] - [ "$output" = "" ] + assert "$status" -eq 0 + assert "$output" = "" } @test "list-tracked command works with no repos and untracked files" { touch a b c d e run $VCSH list-tracked - [ "$status" -eq 0 ] - [ "$output" = "" ] + assert "$status" -eq 0 + assert "$output" = "" } @test "list-tracked fails if argument is not a repo" { @@ -27,8 +27,8 @@ load environment $VCSH init foo run $VCSH list-tracked - [ "$status" -eq 0 ] - [ "$output" = "" ] + assert "$status" -eq 0 + assert "$output" = "" } @test "list-tracked lists files from one repo" { @@ -39,8 +39,8 @@ load environment $VCSH foo commit -m 'a d' run $VCSH list-tracked - [ "$status" -eq 0 ] - [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/d")" ] + assert "$status" -eq 0 + assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/d")" } @test "list-tracked lists files from two repos" { @@ -54,8 +54,8 @@ load environment $VCSH bar commit -m 'c d' run $VCSH list-tracked - [ "$status" -eq 0 ] - [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b" "$HOME/c" "$HOME/d")" ] + assert "$status" -eq 0 + assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b" "$HOME/c" "$HOME/d")" } @test "list-tracked lists files from specified repo" { @@ -69,12 +69,12 @@ load environment $VCSH bar commit -m 'c d' run $VCSH list-tracked foo - [ "$status" -eq 0 ] - [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" ] + assert "$status" -eq 0 + assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" run $VCSH list-tracked bar - [ "$status" -eq 0 ] - [ "$output" = "$(printf '%s\n' "$HOME/c" "$HOME/d")" ] + assert "$status" -eq 0 + assert "$output" = "$(printf '%s\n' "$HOME/c" "$HOME/d")" } @test "list-tracked orders files by path" { @@ -88,8 +88,8 @@ load environment $VCSH bar commit -m 'b e' run $VCSH list-tracked - [ "$status" -eq 0 ] - [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b" "$HOME/d" "$HOME/e")" ] + assert "$status" -eq 0 + assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b" "$HOME/d" "$HOME/e")" } @test "list-tracked does not repeat multiple-tracked files" { @@ -103,8 +103,8 @@ load environment $VCSH bar commit -m 'a b' run $VCSH list-tracked - [ "$status" -eq 0 ] - [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" ] + assert "$status" -eq 0 + assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" } @test "list-tracked accepts each repo for multiple-tracked files" { @@ -118,12 +118,12 @@ load environment $VCSH bar commit -m 'a b' run $VCSH list-tracked foo - [ "$status" -eq 0 ] - [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" ] + assert "$status" -eq 0 + assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" run $VCSH list-tracked bar - [ "$status" -eq 0 ] - [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" ] + assert "$status" -eq 0 + assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" } @test "list-tracked-by requires an argument" { @@ -147,10 +147,10 @@ load environment $VCSH bar commit -m 'c d' run $VCSH list-tracked-by foo - [ "$status" -eq 0 ] - [ "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" ] + assert "$status" -eq 0 + assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" run $VCSH list-tracked-by bar - [ "$status" -eq 0 ] - [ "$output" = "$(printf '%s\n' "$HOME/c" "$HOME/d")" ] + assert "$status" -eq 0 + assert "$output" = "$(printf '%s\n' "$HOME/c" "$HOME/d")" } diff --git a/t/list.t b/t/list.t index 2337e483..711b500b 100755 --- a/t/list.t +++ b/t/list.t @@ -4,22 +4,22 @@ load environment @test "List command correct for no repositories" { run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = '' ] + assert "$status" -eq 0 + assert "$output" = '' } @test "List command displays inited repository" { $VCSH init test1 run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = 'test1' ] + assert "$status" -eq 0 + assert "$output" = 'test1' } @test "List command displays cloned repository" { $VCSH clone "$TESTREPO" test1 run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = 'test1' ] + assert "$status" -eq 0 + assert "$output" = 'test1' } @test "List command displays multiple repositories" { @@ -27,8 +27,8 @@ load environment $VCSH init bar $VCSH init baz run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = $'bar\nbaz\nfoo' ] + assert "$status" -eq 0 + assert "$output" = $'bar\nbaz\nfoo' } @test "List command respects \$VCSH_REPO_D" { @@ -36,12 +36,12 @@ load environment VCSH_REPO_D="$PWD/bar" $VCSH init test2 VCSH_REPO_D="$PWD/foo" run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = 'test1' ] + assert "$status" -eq 0 + assert "$output" = 'test1' VCSH_REPO_D="$PWD/bar" run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = 'test2' ] + assert "$status" -eq 0 + assert "$output" = 'test2' } @test "List command respects \$XDG_CONFIG_HOME" { @@ -49,12 +49,12 @@ load environment XDG_CONFIG_HOME="$PWD/bar" $VCSH init test2 XDG_CONFIG_HOME="$PWD/foo" run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = 'test1' ] + assert "$status" -eq 0 + assert "$output" = 'test1' XDG_CONFIG_HOME="$PWD/bar" run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = 'test2' ] + assert "$status" -eq 0 + assert "$output" = 'test2' } @test "List command respects \$HOME" { @@ -62,12 +62,12 @@ load environment HOME="$PWD/bar" $VCSH init test2 HOME="$PWD/foo" run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = 'test1' ] + assert "$status" -eq 0 + assert "$output" = 'test1' HOME="$PWD/bar" run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = 'test2' ] + assert "$status" -eq 0 + assert "$output" = 'test2' } @test "List command prioritizes \$XDG_CONFIG_HOME over \$HOME" { @@ -75,8 +75,8 @@ load environment HOME="$PWD/bar" $VCSH init wrong HOME="$PWD/bar" XDG_CONFIG_HOME="$PWD/foo/.config" run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = 'correct' ] + assert "$status" -eq 0 + assert "$output" = 'correct' } @test "List command prioritizes \$VCSH_REPO_D over \$HOME" { @@ -84,8 +84,8 @@ load environment HOME="$PWD/bar" $VCSH init wrong HOME="$PWD/bar" VCSH_REPO_D="$PWD/foo/.config/vcsh/repo.d" run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = 'correct' ] + assert "$status" -eq 0 + assert "$output" = 'correct' } @test "List command prioritizes \$VCSH_REPO_D over \$XDG_CONFIG_HOME" { @@ -93,6 +93,6 @@ load environment XDG_CONFIG_HOME="$PWD/bar" $VCSH init wrong XDG_CONFIG_HOME="$PWD/bar" VCSH_REPO_D="$PWD/foo/vcsh/repo.d" run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = 'correct' ] + assert "$status" -eq 0 + assert "$output" = 'correct' } diff --git a/t/prove.t b/t/prove.t index 22559e0b..37bf954a 100755 --- a/t/prove.t +++ b/t/prove.t @@ -10,10 +10,10 @@ load environment $VCSH test2 add 'a' run $VCSH status - [ "$status" -eq 0 ] - [ "$output" = $'test1:\n\ntest2:\nA a' ] + assert "$status" -eq 0 + assert "$output" = $'test1:\n\ntest2:\nA a' run $VCSH status --terse - [ "$status" -eq 0 ] - [ "$output" = $'test2:\nA a' ] + assert "$status" -eq 0 + assert "$output" = $'test2:\nA a' } diff --git a/t/pull.t b/t/pull.t index c5858b69..b54d8e46 100755 --- a/t/pull.t +++ b/t/pull.t @@ -4,8 +4,8 @@ load environment @test "pull works with no repositories" { run $VCSH pull - [ "$status" -eq 0 ] - [ "$output" = "" ] + assert "$status" -eq 0 + assert "$output" = "" } @test "pull succeeds if up-to-date" { @@ -13,8 +13,8 @@ load environment $VCSH clone upstream foo run $VCSH pull - [ "$status" -eq 0 ] - [ "$output" = "foo: Already up-to-date." ] + assert "$status" -eq 0 + assert "$output" = "foo: Already up-to-date." } @test "pull works with one repository" { @@ -27,8 +27,8 @@ load environment $VCSH pull run $VCSH foo rev-parse HEAD - [ "$status" -eq 0 ] - [ "$output" = "$rev" ] + assert "$status" -eq 0 + assert "$output" = "$rev" } @test "pull works with multiple repositories" { @@ -49,11 +49,11 @@ load environment $VCSH pull run $VCSH foo rev-parse HEAD - [ "$status" -eq 0 ] - [ "$output" = "$rev1" ] + assert "$status" -eq 0 + assert "$output" = "$rev1" run $VCSH bar rev-parse HEAD - [ "$status" -eq 0 ] - [ "$output" = "$rev2" ] + assert "$status" -eq 0 + assert "$output" = "$rev2" } @test "pull fails if first pull fails" { diff --git a/t/push.t b/t/push.t index 106bec59..e169641f 100755 --- a/t/push.t +++ b/t/push.t @@ -4,8 +4,8 @@ load environment @test "push works with no repositories" { run $VCSH push - [ "$status" -eq 0 ] - [ "$output" = "" ] + assert "$status" -eq 0 + assert "$output" = "" } @test "push succeeds if up-to-date" { @@ -14,8 +14,8 @@ load environment $VCSH clone upstream.git foo $VCSH foo config push.default simple run $VCSH push - [ "$status" -eq 0 ] - [ "$output" = "foo: Everything up-to-date" ] + assert "$status" -eq 0 + assert "$output" = "foo: Everything up-to-date" } @test "push works with one repository" { @@ -30,8 +30,8 @@ load environment $VCSH push run git -C upstream.git rev-parse HEAD - [ "$status" -eq 0 ] - [ "$output" = "$rev" ] + assert "$status" -eq 0 + assert "$output" = "$rev" } @test "push works with multiple repositories" { @@ -54,11 +54,11 @@ load environment $VCSH push run git -C upstream1.git rev-parse HEAD - [ "$status" -eq 0 ] - [ "$output" = "$rev1" ] + assert "$status" -eq 0 + assert "$output" = "$rev1" run git -C upstream2.git rev-parse HEAD - [ "$status" -eq 0 ] - [ "$output" = "$rev2" ] + assert "$status" -eq 0 + assert "$output" = "$rev2" } @test "push fails if first push fails" { diff --git a/t/rename.t b/t/rename.t index a48045c6..2a6efe48 100755 --- a/t/rename.t +++ b/t/rename.t @@ -23,8 +23,8 @@ load environment $VCSH rename foo bar run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = 'bar' ] + assert "$status" -eq 0 + assert "$output" = 'bar' } @test "Rename works on repository with files/commits" { @@ -33,8 +33,8 @@ load environment $VCSH rename foo bar run $VCSH bar rev-parse HEAD - [ "$status" -eq 0 ] - [ "$output" = "$rev" ] + assert "$status" -eq 0 + assert "$output" = "$rev" } @test "Rename adopts existing .gitignore.d files under new name (bug?)" { @@ -45,8 +45,8 @@ load environment $VCSH rename foo bar run $VCSH bar ls-files - [ "$status" -eq 0 ] - [ "$output" = ".gitignore.d/bar" ] + assert "$status" -eq 0 + assert "$output" = ".gitignore.d/bar" } @test "Rename adopts existing .gitattributes.d files under new name (bug?)" { @@ -57,8 +57,8 @@ load environment $VCSH rename foo bar run $VCSH bar ls-files - [ "$status" -eq 0 ] - [ "$output" = ".gitattributes.d/bar" ] + assert "$status" -eq 0 + assert "$output" = ".gitattributes.d/bar" } @test "Rename can be abbreviated (renam, rena, ren, re)" { @@ -70,6 +70,6 @@ load environment $VCSH re bat quux run $VCSH list - [ "$status" -eq 0 ] - [ "$output" = "quux" ] + assert "$status" -eq 0 + assert "$output" = "quux" } diff --git a/t/run-enter.t b/t/run-enter.t index 8633dd33..b2187d8c 100755 --- a/t/run-enter.t +++ b/t/run-enter.t @@ -10,12 +10,12 @@ load environment rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) run $VCSH run foo git rev-parse HEAD - [ "$status" -eq 0 ] - [ "$output" = "$rev1" ] + assert "$status" -eq 0 + assert "$output" = "$rev1" run $VCSH run bar git rev-parse HEAD - [ "$status" -eq 0 ] - [ "$output" = "$rev2" ] + assert "$status" -eq 0 + assert "$output" = "$rev2" } @test "Run implied if no explicit command specified" { @@ -26,12 +26,12 @@ load environment rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) run $VCSH foo rev-parse HEAD - [ "$status" -eq 0 ] - [ "$output" = "$rev1" ] + assert "$status" -eq 0 + assert "$output" = "$rev1" run $VCSH bar rev-parse HEAD - [ "$status" -eq 0 ] - [ "$output" = "$rev2" ] + assert "$status" -eq 0 + assert "$output" = "$rev2" } @test "Run can be abbreviated (ru)" { @@ -40,21 +40,21 @@ load environment rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) run $VCSH ru foo git rev-parse HEAD - [ "$status" -eq 0 ] - [ "$output" = "$rev1" ] + assert "$status" -eq 0 + assert "$output" = "$rev1" } @test "Run returns exit status of subcommand" { $VCSH init foo run $VCSH run foo sh -c 'exit 104' - [ "$status" -eq 104 ] + assert "$status" -eq 104 run $VCSH run foo sh -c 'exit 42' - [ "$status" -eq 42 ] + assert "$status" -eq 42 run $VCSH run foo sh -c 'exit 93' - [ "$status" -eq 93 ] + assert "$status" -eq 93 } @test "Enter executes inside specific repository" { @@ -65,10 +65,10 @@ load environment rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) echo 'git rev-parse HEAD > rev' | SHELL=/bin/sh $VCSH enter foo - [ "$(cat rev)" = "$rev1" ] + assert "$(cat rev)" = "$rev1" echo 'git rev-parse HEAD > rev' | SHELL=/bin/sh $VCSH enter bar - [ "$(cat rev)" = "$rev2" ] + assert "$(cat rev)" = "$rev2" } @test "Enter executes \$SHELL inside repository" { @@ -76,8 +76,8 @@ load environment rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) SHELL='git rev-parse HEAD' run $VCSH enter foo - [ "$status" -eq 0 ] - [ "$output" = "$rev1" ] + assert "$status" -eq 0 + assert "$output" = "$rev1" } @test "Enter implied for single non-command argument" { @@ -88,10 +88,10 @@ load environment rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) echo 'git rev-parse HEAD > rev' | SHELL=/bin/sh $VCSH foo - [ "$(cat rev)" = "$rev1" ] + assert "$(cat rev)" = "$rev1" echo 'git rev-parse HEAD > rev' | SHELL=/bin/sh $VCSH bar - [ "$(cat rev)" = "$rev2" ] + assert "$(cat rev)" = "$rev2" } @test "Enter returns exit status of subshell" { @@ -99,13 +99,13 @@ load environment $VCSH init foo echo 'exit 104' | SHELL=/bin/sh $VCSH enter foo - [ "$?" -eq 104 ] + assert "$?" -eq 104 echo 'exit 42' | SHELL=/bin/sh $VCSH enter foo - [ "$?" -eq 42 ] + assert "$?" -eq 42 echo 'exit 93' | SHELL=/bin/sh $VCSH enter foo - [ "$?" -eq 93 ] + assert "$?" -eq 93 } @test "Enter can be abbreviated (ente, ent, en)" { @@ -117,5 +117,5 @@ load environment echo 'git rev-parse HEAD >> output' | SHELL=/bin/sh $VCSH ent foo echo 'git rev-parse HEAD >> output' | SHELL=/bin/sh $VCSH en foo - [ "$(cat output)" = "$(printf '%s\n%s\n%s' "$rev1" "$rev1" "$rev1")" ] + assert "$(cat output)" = "$(printf '%s\n%s\n%s' "$rev1" "$rev1" "$rev1")" } diff --git a/t/status.t b/t/status.t index 61156253..a6b35869 100755 --- a/t/status.t +++ b/t/status.t @@ -8,16 +8,16 @@ load environment @test "Status command correct for no repos" { run $VCSH status - [ "$status" -eq 0 ] - [ "$output" = '' ] + assert "$status" -eq 0 + assert "$output" = '' } @test "Status command correct for empty repo" { $VCSH init foo run $VCSH status - [ "$status" -eq 0 ] - [ "$output" = 'foo:' ] + assert "$status" -eq 0 + assert "$output" = 'foo:' } @test "Status command correct for multiple empty repos" { @@ -25,16 +25,16 @@ load environment $VCSH init bar run $VCSH status - [ "$status" -eq 0 ] - [ "$output" = $'bar:\n\nfoo:' ] + assert "$status" -eq 0 + assert "$output" = $'bar:\n\nfoo:' } @test "Terse status correct for empty repo" { $VCSH init foo run $VCSH status --terse - [ "$status" -eq 0 ] - [ "$output" = '' ] + assert "$status" -eq 0 + assert "$output" = '' } @test "Terse status correct for multiple empty repos" { @@ -42,8 +42,8 @@ load environment $VCSH init bar run $VCSH status --terse - [ "$status" -eq 0 ] - [ "$output" = '' ] + assert "$status" -eq 0 + assert "$output" = '' } @test "Status shows added/modified/moved/deleted files" { @@ -81,8 +81,8 @@ load environment rm ?D run $VCSH status - [ "$status" -eq 0 ] - [ "$output" = "$(printf '%s\n' \ + assert "$status" -eq 0 + assert "$output" = "$(printf '%s\n' \ 'foo:' \ ' D 0D' \ ' M 0M' \ @@ -95,7 +95,7 @@ load environment 'MM MM' \ 'R R0x -> R0' \ 'RD RDx -> RD' \ - 'RM RMx -> RM')" ] + 'RM RMx -> RM')" } @test "Status shows commits behind upstream" { @@ -122,7 +122,7 @@ load environment TERM=vt100 export TERM run socat -u exec:"$VCSH status foo",pty,rawer stdio - [ "$output" = $'\e[32mA\e[m a' ] + assert "$output" = $'\e[32mA\e[m a' } @test "Status can be abbreviated (statu, stat, sta, st)" { @@ -135,7 +135,7 @@ load environment for cmd in statu stat sta st; do run $VCSH $cmd - [ "$status" -eq 0 ] - [ "$output" = "$expected" ] + assert "$status" -eq 0 + assert "$output" = "$expected" done } diff --git a/t/version.t b/t/version.t index 11ce78c3..7c764b03 100755 --- a/t/version.t +++ b/t/version.t @@ -18,7 +18,7 @@ load environment for cmd in versio versi vers ver ve; do run $VCSH $cmd - [ "$status" -eq 0 ] - [ "$output" = "$expected" ] + assert "$status" -eq 0 + assert "$output" = "$expected" done } diff --git a/t/which.t b/t/which.t index 5b8a2c37..8afae559 100755 --- a/t/which.t +++ b/t/which.t @@ -33,8 +33,8 @@ load environment $VCSH foo commit -m 'testfile' run $VCSH which testfile - [ "$status" -eq 0 ] - [ "$output" = "foo: testfile" ] + assert "$status" -eq 0 + assert "$output" = "foo: testfile" } @test "Which command matches entire path" { @@ -46,8 +46,8 @@ load environment $VCSH foo commit -m 'dir/testfile' run $VCSH which dir/testfile - [ "$status" -eq 0 ] - [ "$output" = "foo: dir/testfile" ] + assert "$status" -eq 0 + assert "$output" = "foo: dir/testfile" } @test "Which command matches filename within subdirectory" { @@ -59,8 +59,8 @@ load environment $VCSH foo commit -m 'dir/testfile' run $VCSH which testfile - [ "$status" -eq 0 ] - [ "$output" = "foo: dir/testfile" ] + assert "$status" -eq 0 + assert "$output" = "foo: dir/testfile" } @test "Which command matches directory path component" { @@ -72,8 +72,8 @@ load environment $VCSH foo commit -m 'dir/subd/testfile' run $VCSH which subd - [ "$status" -eq 0 ] - [ "$output" = "foo: dir/subd/testfile" ] + assert "$status" -eq 0 + assert "$output" = "foo: dir/subd/testfile" } @test "Which command matches partial filename" { @@ -85,8 +85,8 @@ load environment $VCSH foo commit -m 'dir/subd/testfile' run $VCSH which estf - [ "$status" -eq 0 ] - [ "$output" = "foo: dir/subd/testfile" ] + assert "$status" -eq 0 + assert "$output" = "foo: dir/subd/testfile" } @test "Which command matches partial path component across slash" { @@ -98,8 +98,8 @@ load environment $VCSH foo commit -m 'dir/subd/testfile' run $VCSH which bd/te - [ "$status" -eq 0 ] - [ "$output" = "foo: dir/subd/testfile" ] + assert "$status" -eq 0 + assert "$output" = "foo: dir/subd/testfile" } @test "Which command matches using POSIX BRE" { @@ -110,8 +110,8 @@ load environment $VCSH foo commit -m 'color' run $VCSH which 'c.lou\?r' - [ "$status" -eq 0 ] - [ "$output" = "$(printf 'foo: calor\nfoo: color\nfoo: colour')" ] + assert "$status" -eq 0 + assert "$output" = "$(printf 'foo: calor\nfoo: color\nfoo: colour')" } @test "Which command searches all repos" { @@ -129,6 +129,6 @@ load environment $VCSH baz commit -m 'hello' run $VCSH which hello - [ "$status" -eq 0 ] - [ "$output" = "$(printf 'bar: b/hello\nbaz: c/hello\nfoo: a/hello')" ] + assert "$status" -eq 0 + assert "$output" = "$(printf 'bar: b/hello\nbaz: c/hello\nfoo: a/hello')" } From 1bac18a72715add6f2a2d6ed7732227d588e9f1a Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 26 Feb 2017 21:32:11 -0600 Subject: [PATCH 044/151] add verbose assert_file function Use this instead of [ -e "$file" ] or other file-based tests for more info on failure. --- t/delete.t | 28 ++++++++++++++-------------- t/environment.bash | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/t/delete.t b/t/delete.t index ea329b53..fd73d449 100755 --- a/t/delete.t +++ b/t/delete.t @@ -101,16 +101,16 @@ doit() { $VCSH bar commit -m 'a c' doit | $VCSH delete foo - [ ! -e b ] - [ ! -e e ] - [ -e a ] - [ -e c ] - [ -e d ] + assert_file ! -e b + assert_file ! -e e + assert_file -e a + assert_file -e c + assert_file -e d doit | $VCSH delete bar - [ ! -e a ] - [ ! -e c ] - [ -e d ] + assert_file ! -e a + assert_file ! -e c + assert_file -e d } @test "Delete handles filenames with spaces properly" { @@ -122,9 +122,9 @@ doit() { $VCSH foo commit -m 'a b' doit | $VCSH delete foo - [ ! -e 'a b' ] - [ -e a ] - [ -e b ] + assert_file ! -e 'a b' + assert_file -e a + assert_file -e b } @test "Delete handles filenames with wildcard characters properly" { @@ -136,9 +136,9 @@ doit() { $VCSH foo commit -m '?' doit | $VCSH delete foo - [ ! -e '?' ] - [ -e a ] - [ -e b ] + assert_file ! -e '?' + assert_file -e a + assert_file -e b } @test "Delete can be abbreviated (delet, dele, del, de)" { diff --git a/t/environment.bash b/t/environment.bash index 99819123..8c9df2e3 100644 --- a/t/environment.bash +++ b/t/environment.bash @@ -71,3 +71,24 @@ assert() { return 1 fi } + +assert_file() { + negate= + if [ "$1" = "!" ]; then + if [ $# -ne 3 ]; then + echo 'assert_file: requires two arguments after ! (forgot to quote?)' >&2 + return 2 + fi + negate='! ' + shift + elif [ $# -ne 2 ]; then + echo 'assert_file: requires two arguments (forgot to quote?)' >&2 + return 2 + fi + + if ! test $negate "$@"; then + echo "assertion \"$negate$1\" failed" >&2 + echo "file: \"$2\"" >&2 + return 1 + fi +} From b8c12c9714f6f4f3f8e7e1ea8d41e88604fb51b8 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 26 Feb 2017 22:39:17 -0600 Subject: [PATCH 045/151] use "! || false" "! " by itself doesn't trigger -e/errexit, so there were potentially spurious passes. The || false makes the line fail in a way that *does* trigger errexit. --- t/delete.t | 18 +++++++++--------- t/foreach.t | 2 +- t/help.t | 2 +- t/init.t | 18 +++++++++--------- t/list-tracked.t | 6 +++--- t/pull.t | 4 ++-- t/push.t | 4 ++-- t/rename.t | 8 ++++---- t/status.t | 2 +- t/which.t | 10 +++++----- 10 files changed, 37 insertions(+), 37 deletions(-) diff --git a/t/delete.t b/t/delete.t index fd73d449..62759f0d 100755 --- a/t/delete.t +++ b/t/delete.t @@ -7,27 +7,27 @@ doit() { } @test "Delete requires repo name" { - ! $VCSH delete + ! $VCSH delete || false } @test "Repository to be deleted must exist" { - ! $VCSH delete foo + ! $VCSH delete foo || false } @test "Delete requires confirmation" { $VCSH init foo - ! $VCSH delete foo < /dev/null + ! $VCSH delete foo < /dev/null || false run $VCSH list assert "$status" -eq 0 assert "$output" = "foo" - ! echo | $VCSH delete foo + ! echo | $VCSH delete foo || false run $VCSH list assert "$status" -eq 0 assert "$output" = "foo" - ! echo no | $VCSH delete foo + ! echo no | $VCSH delete foo || false run $VCSH list assert "$status" -eq 0 assert "$output" = "foo" @@ -148,14 +148,14 @@ doit() { $VCSH init d doit | $VCSH delet a - ! $VCSH list | grep -Fqx a + ! $VCSH list | grep -Fqx a || false doit | $VCSH dele b - ! $VCSH list | grep -Fqx b + ! $VCSH list | grep -Fqx b || false doit | $VCSH del c - ! $VCSH list | grep -Fqx c + ! $VCSH list | grep -Fqx c || false doit | $VCSH de d - ! $VCSH list | grep -Fqx d + ! $VCSH list | grep -Fqx d || false } diff --git a/t/foreach.t b/t/foreach.t index 3b72baf5..740a4ada 100755 --- a/t/foreach.t +++ b/t/foreach.t @@ -3,7 +3,7 @@ load environment @test "Foreach requires an argument" { - ! $VCSH foreach + ! $VCSH foreach || false } @test "Foreach does nothing if no repositories exist" { diff --git a/t/help.t b/t/help.t index cd2aa600..5a20af57 100755 --- a/t/help.t +++ b/t/help.t @@ -10,7 +10,7 @@ load environment $VCSH help 2>&1 1>/dev/null | grep -q '' ! $VCSH help 2>/dev/null | - grep -q '' + grep -q '' || false } @test "Help command prints usage on first line" { run $VCSH help diff --git a/t/init.t b/t/init.t index f6b0390a..a1048796 100755 --- a/t/init.t +++ b/t/init.t @@ -7,14 +7,14 @@ load environment } @test "Init command takes exactly one parameter" { - ! $VCSH init - ! $VCSH init foo bar + ! $VCSH init || false + ! $VCSH init foo bar || false $VCSH init baz } @test "Init command fails if repository already exists" { $VCSH init exists - ! $VCSH init exists + ! $VCSH init exists || false } @test "Init creates repositories with same toplevel" { @@ -46,7 +46,7 @@ load environment @test "Init command fails if directories cannot be created" { mkdir ro chmod a-w ro - ! HOME="$PWD/ro" $VCSH init foo + ! HOME="$PWD/ro" $VCSH init foo || false } @test "Init command can be abbreviated 'ini'/'in'" { @@ -109,9 +109,9 @@ load environment } @test "VCSH_GITIGNORE variable is validated" { - ! VCSH_GITIGNORE=x $VCSH init foo - ! VCSH_GITIGNORE=nonsense $VCSH init foo - ! VCSH_GITIGNORE=fhqwhgads $VCSH init foo + ! VCSH_GITIGNORE=x $VCSH init foo || false + ! VCSH_GITIGNORE=nonsense $VCSH init foo || false + ! VCSH_GITIGNORE=fhqwhgads $VCSH init foo || false } @test "Init command sets core.excludesfile with VCSH_GITIGNORE=exact" { @@ -130,7 +130,7 @@ load environment @test "Init command does not set core.excludesfile with VCSH_GITIGNORE=none" { VCSH_GITIGNORE=none $VCSH init test1 - ! $VCSH run test1 git config core.excludesfile + ! $VCSH run test1 git config core.excludesfile || false } @test "Init command sets core.attributesfile with VCSH_GITATTRIBUTES!=none" { @@ -140,5 +140,5 @@ load environment @test "Init command does not set core.attributesfile with VCSH_GITATTRIBUTES=none" { VCSH_GITATTRIBUTES=none $VCSH init test1 - ! $VCSH run test1 git config core.attributesfile + ! $VCSH run test1 git config core.attributesfile || false } diff --git a/t/list-tracked.t b/t/list-tracked.t index 7840b512..28500c1e 100755 --- a/t/list-tracked.t +++ b/t/list-tracked.t @@ -19,7 +19,7 @@ load environment @test "list-tracked fails if argument is not a repo" { skip "BUG" - ! $VCSH list-tracked nope + ! $VCSH list-tracked nope || false } @test "list-tracked works on empty repo" { @@ -127,13 +127,13 @@ load environment } @test "list-tracked-by requires an argument" { - ! $VCSH list-tracked-by + ! $VCSH list-tracked-by || false } @test "list-tracked-by fails if argument is not a repo" { skip "BUG" - ! $VCSH list-tracked-by nope + ! $VCSH list-tracked-by nope || false } @test "list-tracked-by lists files from specified repo" { diff --git a/t/pull.t b/t/pull.t index b54d8e46..03afd83f 100755 --- a/t/pull.t +++ b/t/pull.t @@ -68,7 +68,7 @@ load environment rm -rf upstream1 git -C upstream2 commit --allow-empty -m 'empty' - ! $VCSH pull + ! $VCSH pull || false } @test "pull fails if last pull fails" { @@ -81,5 +81,5 @@ load environment git -C upstream1 commit --allow-empty -m 'empty' rm -rf upstream2 - ! $VCSH pull + ! $VCSH pull || false } diff --git a/t/push.t b/t/push.t index e169641f..2d0eb942 100755 --- a/t/push.t +++ b/t/push.t @@ -75,7 +75,7 @@ load environment rm -rf upstream1.git $VCSH b commit --allow-empty -m 'empty' - ! $VCSH push + ! $VCSH push || false } @test "push fails if last push fails" { @@ -90,5 +90,5 @@ load environment $VCSH a commit --allow-empty -m 'empty' rm -rf upstream2.git - ! $VCSH push + ! $VCSH push || false } diff --git a/t/rename.t b/t/rename.t index 2a6efe48..a04a22f7 100755 --- a/t/rename.t +++ b/t/rename.t @@ -3,19 +3,19 @@ load environment @test "Rename requires two arguments" { - ! $VCSH rename - ! $VCSH rename foo + ! $VCSH rename || false + ! $VCSH rename foo || false } @test "Repository to be renamed must exist" { - ! $VCSH rename foo bar + ! $VCSH rename foo bar || false } @test "Target of rename must not already exist" { $VCSH init foo $VCSH init bar - ! $VCSH rename foo bar + ! $VCSH rename foo bar || false } @test "Rename works on empty repository" { diff --git a/t/status.t b/t/status.t index a6b35869..1d4aea76 100755 --- a/t/status.t +++ b/t/status.t @@ -3,7 +3,7 @@ load environment @test "Status argument if any must be a repo" { - ! $VCSH status nope + ! $VCSH status nope || false } @test "Status command correct for no repos" { diff --git a/t/which.t b/t/which.t index 8afae559..c575388c 100755 --- a/t/which.t +++ b/t/which.t @@ -3,16 +3,16 @@ load environment @test "Which command requires exactly one parameter" { - ! $VCSH which - ! $VCSH which foo bar + ! $VCSH which || false + ! $VCSH which foo bar || false } @test "Which command does not accept an empty parameter" { - ! $VCSH which '' + ! $VCSH which '' || false } @test "Which command fails if no repositories" { - ! $VCSH which nope + ! $VCSH which nope || false } @test "Which command fails if pattern not found" { @@ -22,7 +22,7 @@ load environment $VCSH foo add a $VCSH foo commit -m 'a' - ! $VCSH which nope + ! $VCSH which nope || false } @test "Which command matches exact filename" { From d383e845ee5fcc94b6be0e0deee664c9cdc55a61 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 26 Feb 2017 22:41:22 -0600 Subject: [PATCH 046/151] this test now fails unless skipped vcsh's argument-number checking is kind of loose at the moment. --- t/init.t | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/init.t b/t/init.t index a1048796..fc2f45b5 100755 --- a/t/init.t +++ b/t/init.t @@ -7,6 +7,8 @@ load environment } @test "Init command takes exactly one parameter" { + skip "BUG" + ! $VCSH init || false ! $VCSH init foo bar || false $VCSH init baz From 95214caab6dff0a0378c1fd109f32b1b0ae74cbc Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 26 Feb 2017 22:51:20 -0600 Subject: [PATCH 047/151] add and use assert_grep Verbose version of grep -q for better test output --- t/commit.t | 12 ++++++------ t/debug.t | 4 ++-- t/delete.t | 14 +++++++------- t/environment.bash | 5 +++++ t/help.t | 11 ++++------- t/init.t | 2 +- t/version.t | 4 ++-- 7 files changed, 27 insertions(+), 25 deletions(-) diff --git a/t/commit.t b/t/commit.t index 2841ce9e..d1ad56d0 100755 --- a/t/commit.t +++ b/t/commit.t @@ -39,8 +39,8 @@ load environment # XXX Is printing a trailing space and blank line really intended? assert "$output" = "$(printf 'bar: \n\nfoo: ')" - $VCSH foo log --oneline | grep -qx '....... ab' - $VCSH bar log --oneline | grep -qx '....... ab' + $VCSH foo log --oneline | assert_grep -x '....... ab' + $VCSH bar log --oneline | assert_grep -x '....... ab' } @test "commit can handle arguments with spaces" { @@ -57,8 +57,8 @@ load environment # XXX Is printing a trailing space and blank line really intended? assert "$output" = "$(printf 'bar: \n\nfoo: ')" - $VCSH foo log --oneline | grep -qx '....... log message' - $VCSH bar log --oneline | grep -qx '....... log message' + $VCSH foo log --oneline | assert_grep -x '....... log message' + $VCSH bar log --oneline | assert_grep -x '....... log message' } @test "commit works even if not all repos have changes" { @@ -74,8 +74,8 @@ load environment $VCSH bar add b $VCSH commit -m 'part2' - $VCSH foo log --oneline | grep -qx '....... part1' - $VCSH bar log --oneline | grep -qx '....... part2' + $VCSH foo log --oneline | assert_grep -x '....... part1' + $VCSH bar log --oneline | assert_grep -x '....... part2' } @test "commit not affected by existing \$VCSH_COMMAND_RETURN_CODE" { diff --git a/t/debug.t b/t/debug.t index 8d6aea95..5b8f8f43 100755 --- a/t/debug.t +++ b/t/debug.t @@ -3,7 +3,7 @@ load environment @test "Debug output includes git version" { - $VCSH -d init foo |& grep -q 'git version [0-9]' - $VCSH -d list |& grep -q 'git version [0-9]' + $VCSH -d init foo |& assert_grep 'git version [0-9]' + $VCSH -d list |& assert_grep 'git version [0-9]' # XXX add more? } diff --git a/t/delete.t b/t/delete.t index 62759f0d..c111d673 100755 --- a/t/delete.t +++ b/t/delete.t @@ -66,7 +66,7 @@ doit() { touch randomtexttofind $VCSH foo add randomtexttofind - : | $VCSH delete foo | grep -Fq randomtexttofind + : | $VCSH delete foo | assert_grep -F randomtexttofind } @test "Delete lists committed files before confirmation" { @@ -75,7 +75,7 @@ doit() { $VCSH foo add randomtexttofind $VCSH foo commit -m 'a' - : | $VCSH delete foo | grep -Fq randomtexttofind + : | $VCSH delete foo | assert_grep -F randomtexttofind } @test "Delete lists files staged for removal before confirmation" { @@ -87,7 +87,7 @@ doit() { $VCSH foo commit -m 'a' $VCSH foo rm --cached randomtexttofind - : | $VCSH delete foo | grep -Fq randomtexttofind + : | $VCSH delete foo | assert_grep -F randomtexttofind } @test "Delete removes corresponding files" { @@ -148,14 +148,14 @@ doit() { $VCSH init d doit | $VCSH delet a - ! $VCSH list | grep -Fqx a || false + ! $VCSH list | assert_grep -Fx a || false doit | $VCSH dele b - ! $VCSH list | grep -Fqx b || false + ! $VCSH list | assert_grep -Fx b || false doit | $VCSH del c - ! $VCSH list | grep -Fqx c || false + ! $VCSH list | assert_grep -Fx c || false doit | $VCSH de d - ! $VCSH list | grep -Fqx d || false + ! $VCSH list | assert_grep -Fx d || false } diff --git a/t/environment.bash b/t/environment.bash index 8c9df2e3..212c27a0 100644 --- a/t/environment.bash +++ b/t/environment.bash @@ -92,3 +92,8 @@ assert_file() { return 1 fi } + +# Similar to grep -q, but prints the entire input to stderr for debugging +assert_grep() { + tee /dev/stderr | grep "$@" > /dev/null +} diff --git a/t/help.t b/t/help.t index 5a20af57..5f7d762f 100755 --- a/t/help.t +++ b/t/help.t @@ -7,14 +7,12 @@ load environment $VCSH help } @test "Help command writes to stderr and not stdout" { - $VCSH help 2>&1 1>/dev/null | - grep -q '' - ! $VCSH help 2>/dev/null | - grep -q '' || false + $VCSH help 2>&1 1>/dev/null | assert_grep '' + ! $VCSH help 2>/dev/null | assert_grep '' || false } @test "Help command prints usage on first line" { run $VCSH help - [[ "$output" = 'usage: '* ]] + echo "${lines[0]}" | assert_grep '^usage: ' } @test "Help command can be abbreviated (hel, he)" { @@ -34,8 +32,7 @@ load environment # Help should explain each command. (Note: adjust the help_check function if # the format of help output changes.) help_check() { - $VCSH help 2>&1 | - grep -q "^ $1\\b" + $VCSH help 2>&1 | assert_grep "^ $1\\b" } @test "Help text includes clone command" { help_check clone; } diff --git a/t/init.t b/t/init.t index fc2f45b5..606c5b78 100755 --- a/t/init.t +++ b/t/init.t @@ -96,7 +96,7 @@ load environment touch .gitattributes.d/test1 .gitignore.d/test1 VCSH_GITIGNORE=exact $VCSH init test1 - $VCSH status test1 | grep -Fqx 'A .gitignore.d/test1' + $VCSH status test1 | assert_grep -Fx 'A .gitignore.d/test1' } @test "Init command creates new Git repository" { diff --git a/t/version.t b/t/version.t index 7c764b03..15d28b21 100755 --- a/t/version.t +++ b/t/version.t @@ -8,8 +8,8 @@ load environment @test "Version command prints vcsh and git versions" { run $VCSH version - [[ "${lines[0]}" = 'vcsh '[0-9]* ]] - [[ "${lines[1]}" = 'git version '[0-9]* ]] + echo "${lines[0]}" | assert_grep '^vcsh [0-9]' + echo "${lines[1]}" | assert_grep '^git version [0-9]' } @test "Version can be abbreviated (versio, versi, vers, ver, ve)" { From ec4c89da4278c9e0f5587705149a8dbf6fb380b4 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 4 May 2017 19:51:34 -0500 Subject: [PATCH 048/151] convert help.t to Git's test-lib --- t/help.t | 94 ++-- t/test-lib-functions.sh | 1015 ++++++++++++++++++++++++++++++++++++++ t/test-lib.sh | 1030 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 2082 insertions(+), 57 deletions(-) create mode 100644 t/test-lib-functions.sh create mode 100644 t/test-lib.sh diff --git a/t/help.t b/t/help.t index 5f7d762f..979f32bb 100755 --- a/t/help.t +++ b/t/help.t @@ -1,57 +1,37 @@ -#!/usr/bin/env bats - -load environment - -@test "Help command succeeds" { - skip "BUG: help command fails" - $VCSH help -} -@test "Help command writes to stderr and not stdout" { - $VCSH help 2>&1 1>/dev/null | assert_grep '' - ! $VCSH help 2>/dev/null | assert_grep '' || false -} -@test "Help command prints usage on first line" { - run $VCSH help - echo "${lines[0]}" | assert_grep '^usage: ' -} - -@test "Help command can be abbreviated (hel, he)" { - skip "BUG: help command fails" - run $VCSH help - local good=$output - - run $VCSH hel - assert "$status" -eq 0 - assert "$output" = "$good" - - run $VCSH he - assert "$status" -eq 0 - assert "$output" = "$good" -} - -# Help should explain each command. (Note: adjust the help_check function if -# the format of help output changes.) -help_check() { - $VCSH help 2>&1 | assert_grep "^ $1\\b" -} - -@test "Help text includes clone command" { help_check clone; } -@test "Help text includes commit command" { help_check commit; } -@test "Help text includes delete command" { help_check delete; } -@test "Help text includes enter command" { help_check enter; } -@test "Help text includes foreach command" { help_check foreach; } -@test "Help text includes help command" { help_check help; } -@test "Help text includes init command" { help_check init; } -@test "Help text includes list command" { help_check list; } -@test "Help text includes list-tracked command" { help_check list-tracked; } -# list-tracked-by is deprecated, not shown in help -@test "Help text includes list-untracked command" { help_check list-untracked; } -@test "Help text includes pull command" { help_check pull; } -@test "Help text includes push command" { help_check push; } -@test "Help text includes rename command" { help_check rename; } -@test "Help text includes run command" { help_check run; } -@test "Help text includes status command" { help_check status; } -@test "Help text includes upgrade command" { help_check upgrade; } -@test "Help text includes version command" { help_check version; } -@test "Help text includes which command" { help_check which; } -@test "Help text includes write-gitignore command" { help_check write-gitignore; } +#!/bin/bash + +test_description='Help command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +VCSH='sh vcsh' + +test_expect_failure 'Help command succeeds' \ + '$VCSH help' + +test_expect_success 'Help command writes to stderr and not stdout' \ + '$VCSH help 2>&1 1>/dev/null | assert_grep "" && + ! $VCSH help 2>/dev/null | assert_grep ""' + +test_expect_success 'Help command prints usage on first line' \ + '$VCSH help |& + head -1 | + assert_grep "^usage: "' + +test_expect_failure 'Help command can be abbreviated (hel, he)' \ + 'good="$($VCSH help 2>&1)" && + output1=$($VCSH hel 2>&1)" && + assert "$output1" = "$good" && + output2=$($VCSH he 2>&1)" && + assert "$output2" = "$good"' + +# Help should explain each non-deprecated command. (Note: adjust this if the +# format of help output changes.) +for cmd in clone commit delete enter foreach help init list list-tracked list-untracked \ + pull push rename run status upgrade version which write-gitignore; do + test_expect_success "Help text includes $cmd command" \ + '$VCSH help 2>&1 | assert_grep "^ '"$cmd"'\\b"' +done + +test_done diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh new file mode 100644 index 00000000..5ee12433 --- /dev/null +++ b/t/test-lib-functions.sh @@ -0,0 +1,1015 @@ +# Library of functions shared by all tests scripts, included by +# test-lib.sh. +# +# Copyright (c) 2005 Junio C Hamano +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/ . + +# The semantics of the editor variables are that of invoking +# sh -c "$EDITOR \"$@\"" files ... +# +# If our trash directory contains shell metacharacters, they will be +# interpreted if we just set $EDITOR directly, so do a little dance with +# environment variables to work around this. +# +# In particular, quoting isn't enough, as the path may contain the same quote +# that we're using. +test_set_editor () { + FAKE_EDITOR="$1" + export FAKE_EDITOR + EDITOR='"$FAKE_EDITOR"' + export EDITOR +} + +test_set_index_version () { + GIT_INDEX_VERSION="$1" + export GIT_INDEX_VERSION +} + +test_decode_color () { + awk ' + function name(n) { + if (n == 0) return "RESET"; + if (n == 1) return "BOLD"; + if (n == 30) return "BLACK"; + if (n == 31) return "RED"; + if (n == 32) return "GREEN"; + if (n == 33) return "YELLOW"; + if (n == 34) return "BLUE"; + if (n == 35) return "MAGENTA"; + if (n == 36) return "CYAN"; + if (n == 37) return "WHITE"; + if (n == 40) return "BLACK"; + if (n == 41) return "BRED"; + if (n == 42) return "BGREEN"; + if (n == 43) return "BYELLOW"; + if (n == 44) return "BBLUE"; + if (n == 45) return "BMAGENTA"; + if (n == 46) return "BCYAN"; + if (n == 47) return "BWHITE"; + } + { + while (match($0, /\033\[[0-9;]*m/) != 0) { + printf "%s<", substr($0, 1, RSTART-1); + codes = substr($0, RSTART+2, RLENGTH-3); + if (length(codes) == 0) + printf "%s", name(0) + else { + n = split(codes, ary, ";"); + sep = ""; + for (i = 1; i <= n; i++) { + printf "%s%s", sep, name(ary[i]); + sep = ";" + } + } + printf ">"; + $0 = substr($0, RSTART + RLENGTH, length($0) - RSTART - RLENGTH + 1); + } + print + } + ' +} + +lf_to_nul () { + perl -pe 'y/\012/\000/' +} + +nul_to_q () { + perl -pe 'y/\000/Q/' +} + +q_to_nul () { + perl -pe 'y/Q/\000/' +} + +q_to_cr () { + tr Q '\015' +} + +q_to_tab () { + tr Q '\011' +} + +qz_to_tab_space () { + tr QZ '\011\040' +} + +append_cr () { + sed -e 's/$/Q/' | tr Q '\015' +} + +remove_cr () { + tr '\015' Q | sed -e 's/Q$//' +} + +# In some bourne shell implementations, the "unset" builtin returns +# nonzero status when a variable to be unset was not set in the first +# place. +# +# Use sane_unset when that should not be considered an error. + +sane_unset () { + unset "$@" + return 0 +} + +test_tick () { + if test -z "${test_tick+set}" + then + test_tick=1112911993 + else + test_tick=$(($test_tick + 60)) + fi + GIT_COMMITTER_DATE="$test_tick -0700" + GIT_AUTHOR_DATE="$test_tick -0700" + export GIT_COMMITTER_DATE GIT_AUTHOR_DATE +} + +# Stop execution and start a shell. This is useful for debugging tests. +# +# Be sure to remove all invocations of this command before submitting. + +test_pause () { + "$SHELL_PATH" <&6 >&5 2>&7 +} + +# Wrap git in gdb. Adding this to a command can make it easier to +# understand what is going on in a failing test. +# +# Example: "debug git checkout master". +debug () { + GIT_TEST_GDB=1 "$@" <&6 >&5 2>&7 +} + +# Call test_commit with the arguments +# [-C ] [ [ []]]" +# +# This will commit a file with the given contents and the given commit +# message, and tag the resulting commit with the given tag name. +# +# , , and all default to . +# +# If the first argument is "-C", the second argument is used as a path for +# the git invocations. + +test_commit () { + notick= && + signoff= && + indir= && + while test $# != 0 + do + case "$1" in + --notick) + notick=yes + ;; + --signoff) + signoff="$1" + ;; + -C) + indir="$2" + shift + ;; + *) + break + ;; + esac + shift + done && + indir=${indir:+"$indir"/} && + file=${2:-"$1.t"} && + echo "${3-$1}" > "$indir$file" && + git ${indir:+ -C "$indir"} add "$file" && + if test -z "$notick" + then + test_tick + fi && + git ${indir:+ -C "$indir"} commit $signoff -m "$1" && + git ${indir:+ -C "$indir"} tag "${4:-$1}" +} + +# Call test_merge with the arguments " ", where +# can be a tag pointing to the commit-to-merge. + +test_merge () { + test_tick && + git merge -m "$1" "$2" && + git tag "$1" +} + +# This function helps systems where core.filemode=false is set. +# Use it instead of plain 'chmod +x' to set or unset the executable bit +# of a file in the working directory and add it to the index. + +test_chmod () { + chmod "$@" && + git update-index --add "--chmod=$@" +} + +# Unset a configuration variable, but don't fail if it doesn't exist. +test_unconfig () { + config_dir= + if test "$1" = -C + then + shift + config_dir=$1 + shift + fi + git ${config_dir:+-C "$config_dir"} config --unset-all "$@" + config_status=$? + case "$config_status" in + 5) # ok, nothing to unset + config_status=0 + ;; + esac + return $config_status +} + +# Set git config, automatically unsetting it after the test is over. +test_config () { + config_dir= + if test "$1" = -C + then + shift + config_dir=$1 + shift + fi + test_when_finished "test_unconfig ${config_dir:+-C '$config_dir'} '$1'" && + git ${config_dir:+-C "$config_dir"} config "$@" +} + +test_config_global () { + test_when_finished "test_unconfig --global '$1'" && + git config --global "$@" +} + +write_script () { + { + echo "#!${2-"$SHELL_PATH"}" && + cat + } >"$1" && + chmod +x "$1" +} + +# Use test_set_prereq to tell that a particular prerequisite is available. +# The prerequisite can later be checked for in two ways: +# +# - Explicitly using test_have_prereq. +# +# - Implicitly by specifying the prerequisite tag in the calls to +# test_expect_{success,failure,code}. +# +# The single parameter is the prerequisite tag (a simple word, in all +# capital letters by convention). + +test_set_prereq () { + satisfied_prereq="$satisfied_prereq$1 " +} +satisfied_prereq=" " +lazily_testable_prereq= lazily_tested_prereq= + +# Usage: test_lazy_prereq PREREQ 'script' +test_lazy_prereq () { + lazily_testable_prereq="$lazily_testable_prereq$1 " + eval test_prereq_lazily_$1=\$2 +} + +test_run_lazy_prereq_ () { + script=' +mkdir -p "$TRASH_DIRECTORY/prereq-test-dir" && +( + cd "$TRASH_DIRECTORY/prereq-test-dir" &&'"$2"' +)' + say >&3 "checking prerequisite: $1" + say >&3 "$script" + test_eval_ "$script" + eval_ret=$? + rm -rf "$TRASH_DIRECTORY/prereq-test-dir" + if test "$eval_ret" = 0; then + say >&3 "prerequisite $1 ok" + else + say >&3 "prerequisite $1 not satisfied" + fi + return $eval_ret +} + +test_have_prereq () { + # prerequisites can be concatenated with ',' + save_IFS=$IFS + IFS=, + set -- $* + IFS=$save_IFS + + total_prereq=0 + ok_prereq=0 + missing_prereq= + + for prerequisite + do + case "$prerequisite" in + !*) + negative_prereq=t + prerequisite=${prerequisite#!} + ;; + *) + negative_prereq= + esac + + case " $lazily_tested_prereq " in + *" $prerequisite "*) + ;; + *) + case " $lazily_testable_prereq " in + *" $prerequisite "*) + eval "script=\$test_prereq_lazily_$prerequisite" && + if test_run_lazy_prereq_ "$prerequisite" "$script" + then + test_set_prereq $prerequisite + fi + lazily_tested_prereq="$lazily_tested_prereq$prerequisite " + esac + ;; + esac + + total_prereq=$(($total_prereq + 1)) + case "$satisfied_prereq" in + *" $prerequisite "*) + satisfied_this_prereq=t + ;; + *) + satisfied_this_prereq= + esac + + case "$satisfied_this_prereq,$negative_prereq" in + t,|,t) + ok_prereq=$(($ok_prereq + 1)) + ;; + *) + # Keep a list of missing prerequisites; restore + # the negative marker if necessary. + prerequisite=${negative_prereq:+!}$prerequisite + if test -z "$missing_prereq" + then + missing_prereq=$prerequisite + else + missing_prereq="$prerequisite,$missing_prereq" + fi + esac + done + + test $total_prereq = $ok_prereq +} + +test_declared_prereq () { + case ",$test_prereq," in + *,$1,*) + return 0 + ;; + esac + return 1 +} + +test_verify_prereq () { + test -z "$test_prereq" || + expr >/dev/null "$test_prereq" : '[A-Z0-9_,!]*$' || + error "bug in the test script: '$test_prereq' does not look like a prereq" +} + +test_expect_failure () { + test_start_ + test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq= + test "$#" = 2 || + error "bug in the test script: not 2 or 3 parameters to test-expect-failure" + test_verify_prereq + export test_prereq + if ! test_skip "$@" + then + say >&3 "checking known breakage: $2" + if test_run_ "$2" expecting_failure + then + test_known_broken_ok_ "$1" + else + test_known_broken_failure_ "$1" + fi + fi + test_finish_ +} + +test_expect_success () { + test_start_ + test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq= + test "$#" = 2 || + error "bug in the test script: not 2 or 3 parameters to test-expect-success" + test_verify_prereq + export test_prereq + if ! test_skip "$@" + then + say >&3 "expecting success: $2" + if test_run_ "$2" + then + test_ok_ "$1" + else + test_failure_ "$@" + fi + fi + test_finish_ +} + +# test_external runs external test scripts that provide continuous +# test output about their progress, and succeeds/fails on +# zero/non-zero exit code. It outputs the test output on stdout even +# in non-verbose mode, and announces the external script with "# run +# : ..." before running it. When providing relative paths, keep in +# mind that all scripts run in "trash directory". +# Usage: test_external description command arguments... +# Example: test_external 'Perl API' perl ../path/to/test.pl +test_external () { + test "$#" = 4 && { test_prereq=$1; shift; } || test_prereq= + test "$#" = 3 || + error >&5 "bug in the test script: not 3 or 4 parameters to test_external" + descr="$1" + shift + test_verify_prereq + export test_prereq + if ! test_skip "$descr" "$@" + then + # Announce the script to reduce confusion about the + # test output that follows. + say_color "" "# run $test_count: $descr ($*)" + # Export TEST_DIRECTORY, TRASH_DIRECTORY and GIT_TEST_LONG + # to be able to use them in script + export TEST_DIRECTORY TRASH_DIRECTORY GIT_TEST_LONG + # Run command; redirect its stderr to &4 as in + # test_run_, but keep its stdout on our stdout even in + # non-verbose mode. + "$@" 2>&4 + if test "$?" = 0 + then + if test $test_external_has_tap -eq 0; then + test_ok_ "$descr" + else + say_color "" "# test_external test $descr was ok" + test_success=$(($test_success + 1)) + fi + else + if test $test_external_has_tap -eq 0; then + test_failure_ "$descr" "$@" + else + say_color error "# test_external test $descr failed: $@" + test_failure=$(($test_failure + 1)) + fi + fi + fi +} + +# Like test_external, but in addition tests that the command generated +# no output on stderr. +test_external_without_stderr () { + # The temporary file has no (and must have no) security + # implications. + tmp=${TMPDIR:-/tmp} + stderr="$tmp/git-external-stderr.$$.tmp" + test_external "$@" 4> "$stderr" + test -f "$stderr" || error "Internal error: $stderr disappeared." + descr="no stderr: $1" + shift + say >&3 "# expecting no stderr from previous command" + if test ! -s "$stderr" + then + rm "$stderr" + + if test $test_external_has_tap -eq 0; then + test_ok_ "$descr" + else + say_color "" "# test_external_without_stderr test $descr was ok" + test_success=$(($test_success + 1)) + fi + else + if test "$verbose" = t + then + output=$(echo; echo "# Stderr is:"; cat "$stderr") + else + output= + fi + # rm first in case test_failure exits. + rm "$stderr" + if test $test_external_has_tap -eq 0; then + test_failure_ "$descr" "$@" "$output" + else + say_color error "# test_external_without_stderr test $descr failed: $@: $output" + test_failure=$(($test_failure + 1)) + fi + fi +} + +# debugging-friendly alternatives to "test [-f|-d|-e]" +# The commands test the existence or non-existence of $1. $2 can be +# given to provide a more precise diagnosis. +test_path_is_file () { + if ! test -f "$1" + then + echo "File $1 doesn't exist. $2" + false + fi +} + +test_path_is_dir () { + if ! test -d "$1" + then + echo "Directory $1 doesn't exist. $2" + false + fi +} + +# Check if the directory exists and is empty as expected, barf otherwise. +test_dir_is_empty () { + test_path_is_dir "$1" && + if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')" + then + echo "Directory '$1' is not empty, it contains:" + ls -la "$1" + return 1 + fi +} + +test_path_is_missing () { + if test -e "$1" + then + echo "Path exists:" + ls -ld "$1" + if test $# -ge 1 + then + echo "$*" + fi + false + fi +} + +# test_line_count checks that a file has the number of lines it +# ought to. For example: +# +# test_expect_success 'produce exactly one line of output' ' +# do something >output && +# test_line_count = 1 output +# ' +# +# is like "test $(wc -l &2 "test_must_fail: command succeeded: $*" + return 1 + elif test_match_signal 13 $exit_code && list_contains "$_test_ok" sigpipe + then + return 0 + elif test $exit_code -gt 129 && test $exit_code -le 192 + then + echo >&2 "test_must_fail: died by signal $(($exit_code - 128)): $*" + return 1 + elif test $exit_code -eq 127 + then + echo >&2 "test_must_fail: command not found: $*" + return 1 + elif test $exit_code -eq 126 + then + echo >&2 "test_must_fail: valgrind error: $*" + return 1 + fi + return 0 +} + +# Similar to test_must_fail, but tolerates success, too. This is +# meant to be used in contexts like: +# +# test_expect_success 'some command works without configuration' ' +# test_might_fail git config --unset all.configuration && +# do something +# ' +# +# Writing "git config --unset all.configuration || :" would be wrong, +# because we want to notice if it fails due to segv. + +test_might_fail () { + test_must_fail ok=success "$@" +} + +# Similar to test_must_fail and test_might_fail, but check that a +# given command exited with a given exit code. Meant to be used as: +# +# test_expect_success 'Merge with d/f conflicts' ' +# test_expect_code 1 git merge "merge msg" B master +# ' + +test_expect_code () { + want_code=$1 + shift + "$@" + exit_code=$? + if test $exit_code = $want_code + then + return 0 + fi + + echo >&2 "test_expect_code: command exited with $exit_code, we wanted $want_code $*" + return 1 +} + +# test_cmp is a helper function to compare actual and expected output. +# You can use it like: +# +# test_expect_success 'foo works' ' +# echo expected >expected && +# foo >actual && +# test_cmp expected actual +# ' +# +# This could be written as either "cmp" or "diff -u", but: +# - cmp's output is not nearly as easy to read as diff -u +# - not all diff versions understand "-u" + +test_cmp() { + $GIT_TEST_CMP "$@" +} + +# test_cmp_bin - helper to compare binary files + +test_cmp_bin() { + cmp "$@" +} + +# Call any command "$@" but be more verbose about its +# failure. This is handy for commands like "test" which do +# not output anything when they fail. +verbose () { + "$@" && return 0 + echo >&2 "command failed: $(git rev-parse --sq-quote "$@")" + return 1 +} + +# Check if the file expected to be empty is indeed empty, and barfs +# otherwise. + +test_must_be_empty () { + if test -s "$1" + then + echo "'$1' is not empty, it contains:" + cat "$1" + return 1 + fi +} + +# Tests that its two parameters refer to the same revision +test_cmp_rev () { + git rev-parse --verify "$1" >expect.rev && + git rev-parse --verify "$2" >actual.rev && + test_cmp expect.rev actual.rev +} + +# Print a sequence of integers in increasing order, either with +# two arguments (start and end): +# +# test_seq 1 5 -- outputs 1 2 3 4 5 one line at a time +# +# or with one argument (end), in which case it starts counting +# from 1. + +test_seq () { + case $# in + 1) set 1 "$@" ;; + 2) ;; + *) error "bug in the test script: not 1 or 2 parameters to test_seq" ;; + esac + test_seq_counter__=$1 + while test "$test_seq_counter__" -le "$2" + do + echo "$test_seq_counter__" + test_seq_counter__=$(( $test_seq_counter__ + 1 )) + done +} + +# This function can be used to schedule some commands to be run +# unconditionally at the end of the test to restore sanity: +# +# test_expect_success 'test core.capslock' ' +# git config core.capslock true && +# test_when_finished "git config --unset core.capslock" && +# hello world +# ' +# +# That would be roughly equivalent to +# +# test_expect_success 'test core.capslock' ' +# git config core.capslock true && +# hello world +# git config --unset core.capslock +# ' +# +# except that the greeting and config --unset must both succeed for +# the test to pass. +# +# Note that under --immediate mode, no clean-up is done to help diagnose +# what went wrong. + +test_when_finished () { + # We cannot detect when we are in a subshell in general, but by + # doing so on Bash is better than nothing (the test will + # silently pass on other shells). + test "${BASH_SUBSHELL-0}" = 0 || + error "bug in test script: test_when_finished does nothing in a subshell" + test_cleanup="{ $* + } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup" +} + +# Most tests can use the created repository, but some may need to create more. +# Usage: test_create_repo +test_create_repo () { + test "$#" = 1 || + error "bug in the test script: not 1 parameter to test-create-repo" + repo="$1" + mkdir -p "$repo" + ( + cd "$repo" || error "Cannot setup test environment" + "$GIT_EXEC_PATH/git-init" "--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 || + error "cannot run git init -- have you built things yet?" + mv .git/hooks .git/hooks-disabled + ) || exit +} + +# This function helps on symlink challenged file systems when it is not +# important that the file system entry is a symbolic link. +# Use test_ln_s_add instead of "ln -s x y && git add y" to add a +# symbolic link entry y to the index. + +test_ln_s_add () { + if test_have_prereq SYMLINKS + then + ln -s "$1" "$2" && + git update-index --add "$2" + else + printf '%s' "$1" >"$2" && + ln_s_obj=$(git hash-object -w "$2") && + git update-index --add --cacheinfo 120000 $ln_s_obj "$2" && + # pick up stat info from the file + git update-index "$2" + fi +} + +# This function writes out its parameters, one per line +test_write_lines () { + printf "%s\n" "$@" +} + +perl () { + command "$PERL_PATH" "$@" +} + +# Is the value one of the various ways to spell a boolean true/false? +test_normalize_bool () { + git -c magic.variable="$1" config --bool magic.variable 2>/dev/null +} + +# Given a variable $1, normalize the value of it to one of "true", +# "false", or "auto" and store the result to it. +# +# test_tristate GIT_TEST_HTTPD +# +# A variable set to an empty string is set to 'false'. +# A variable set to 'false' or 'auto' keeps its value. +# Anything else is set to 'true'. +# An unset variable defaults to 'auto'. +# +# The last rule is to allow people to set the variable to an empty +# string and export it to decline testing the particular feature +# for versions both before and after this change. We used to treat +# both unset and empty variable as a signal for "do not test" and +# took any non-empty string as "please test". + +test_tristate () { + if eval "test x\"\${$1+isset}\" = xisset" + then + # explicitly set + eval " + case \"\$$1\" in + '') $1=false ;; + auto) ;; + *) $1=\$(test_normalize_bool \$$1 || echo true) ;; + esac + " + else + eval "$1=auto" + fi +} + +# Exit the test suite, either by skipping all remaining tests or by +# exiting with an error. If "$1" is "auto", we then we assume we were +# opportunistically trying to set up some tests and we skip. If it is +# "true", then we report a failure. +# +# The error/skip message should be given by $2. +# +test_skip_or_die () { + case "$1" in + auto) + skip_all=$2 + test_done + ;; + true) + error "$2" + ;; + *) + error "BUG: test tristate is '$1' (real error: $2)" + esac +} + +# The following mingw_* functions obey POSIX shell syntax, but are actually +# bash scripts, and are meant to be used only with bash on Windows. + +# A test_cmp function that treats LF and CRLF equal and avoids to fork +# diff when possible. +mingw_test_cmp () { + # Read text into shell variables and compare them. If the results + # are different, use regular diff to report the difference. + local test_cmp_a= test_cmp_b= + + # When text came from stdin (one argument is '-') we must feed it + # to diff. + local stdin_for_diff= + + # Since it is difficult to detect the difference between an + # empty input file and a failure to read the files, we go straight + # to diff if one of the inputs is empty. + if test -s "$1" && test -s "$2" + then + # regular case: both files non-empty + mingw_read_file_strip_cr_ test_cmp_a <"$1" + mingw_read_file_strip_cr_ test_cmp_b <"$2" + elif test -s "$1" && test "$2" = - + then + # read 2nd file from stdin + mingw_read_file_strip_cr_ test_cmp_a <"$1" + mingw_read_file_strip_cr_ test_cmp_b + stdin_for_diff='<<<"$test_cmp_b"' + elif test "$1" = - && test -s "$2" + then + # read 1st file from stdin + mingw_read_file_strip_cr_ test_cmp_a + mingw_read_file_strip_cr_ test_cmp_b <"$2" + stdin_for_diff='<<<"$test_cmp_a"' + fi + test -n "$test_cmp_a" && + test -n "$test_cmp_b" && + test "$test_cmp_a" = "$test_cmp_b" || + eval "diff -u \"\$@\" $stdin_for_diff" +} + +# $1 is the name of the shell variable to fill in +mingw_read_file_strip_cr_ () { + # Read line-wise using LF as the line separator + # and use IFS to strip CR. + local line + while : + do + if IFS=$'\r' read -r -d $'\n' line + then + # good + line=$line$'\n' + else + # we get here at EOF, but also if the last line + # was not terminated by LF; in the latter case, + # some text was read + if test -z "$line" + then + # EOF, really + break + fi + fi + eval "$1=\$$1\$line" + done +} + +# Like "env FOO=BAR some-program", but run inside a subshell, which means +# it also works for shell functions (though those functions cannot impact +# the environment outside of the test_env invocation). +test_env () { + ( + while test $# -gt 0 + do + case "$1" in + *=*) + eval "${1%%=*}=\${1#*=}" + eval "export ${1%%=*}" + shift + ;; + *) + "$@" + exit + ;; + esac + done + ) +} + +# Returns true if the numeric exit code in "$2" represents the expected signal +# in "$1". Signals should be given numerically. +test_match_signal () { + if test "$2" = "$((128 + $1))" + then + # POSIX + return 0 + elif test "$2" = "$((256 + $1))" + then + # ksh + return 0 + fi + return 1 +} + +# Read up to "$1" bytes (or to EOF) from stdin and write them to stdout. +test_copy_bytes () { + perl -e ' + my $len = $ARGV[1]; + while ($len > 0) { + my $s; + my $nread = sysread(STDIN, $s, $len); + die "cannot read: $!" unless defined($nread); + print $s; + $len -= $nread; + } + ' - "$1" +} + +# run "$@" inside a non-git directory +nongit () { + test -d non-repo || + mkdir non-repo || + return 1 + + ( + GIT_CEILING_DIRECTORIES=$(pwd) && + export GIT_CEILING_DIRECTORIES && + cd non-repo && + "$@" + ) +} diff --git a/t/test-lib.sh b/t/test-lib.sh new file mode 100644 index 00000000..77211c0d --- /dev/null +++ b/t/test-lib.sh @@ -0,0 +1,1030 @@ +# Test framework for git. See t/README for usage. +# +# Copyright (c) 2005 Junio C Hamano +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/ . + +# Test the binaries we have just built. The tests are kept in +# t/ subdirectory and are run in 'trash directory' subdirectory. +if test -z "$TEST_DIRECTORY" +then + # We allow tests to override this, in case they want to run tests + # outside of t/, e.g. for running tests on the test library + # itself. + TEST_DIRECTORY=$(pwd) +else + # ensure that TEST_DIRECTORY is an absolute path so that it + # is valid even if the current working directory is changed + TEST_DIRECTORY=$(cd "$TEST_DIRECTORY" && pwd) || exit 1 +fi +if test -z "$TEST_OUTPUT_DIRECTORY" +then + # Similarly, override this to store the test-results subdir + # elsewhere + TEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY +fi +GIT_BUILD_DIR="$TEST_DIRECTORY"/.. + +################################################################ +# It appears that people try to run tests without building... +if ! test -x "$GIT_BUILD_DIR/vcsh" +then + echo >&2 'error: you do not seem to have built git yet.' + exit 1 +fi + +export PERL_PATH=perl SHELL_PATH=sh + +# if --tee was passed, write the output not only to the terminal, but +# additionally to the file test-results/$BASENAME.out, too. +case "$GIT_TEST_TEE_STARTED, $* " in +done,*) + # do not redirect again + ;; +*' --tee '*|*' --va'*|*' --verbose-log '*) + mkdir -p "$TEST_OUTPUT_DIRECTORY/test-results" + BASE="$TEST_OUTPUT_DIRECTORY/test-results/$(basename "$0" .sh)" + + # Make this filename available to the sub-process in case it is using + # --verbose-log. + GIT_TEST_TEE_OUTPUT_FILE=$BASE.out + export GIT_TEST_TEE_OUTPUT_FILE + + # Truncate before calling "tee -a" to get rid of the results + # from any previous runs. + >"$GIT_TEST_TEE_OUTPUT_FILE" + + (GIT_TEST_TEE_STARTED=done ${SHELL_PATH} "$0" "$@" 2>&1; + echo $? >"$BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE" + test "$(cat "$BASE.exit")" = 0 + exit + ;; +esac + +# For repeatability, reset the environment to known value. +# TERM is sanitized below, after saving color control sequences. +LANG=C +LC_ALL=C +PAGER=cat +TZ=UTC +export LANG LC_ALL PAGER TZ +EDITOR=: +# A call to "unset" with no arguments causes at least Solaris 10 +# /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets +# deriving from the command substitution clustered with the other +# ones. +unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH" -e ' + my @env = keys %ENV; + my $ok = join("|", qw( + TRACE + DEBUG + USE_LOOKUP + TEST + .*_TEST + PROVE + VALGRIND + UNZIP + PERF_ + CURL_VERBOSE + TRACE_CURL + )); + my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env); + print join("\n", @vars); +') +unset XDG_CONFIG_HOME +unset GITPERLLIB +GIT_AUTHOR_EMAIL=author@example.com +GIT_AUTHOR_NAME='A U Thor' +GIT_COMMITTER_EMAIL=committer@example.com +GIT_COMMITTER_NAME='C O Mitter' +GIT_MERGE_VERBOSITY=5 +GIT_MERGE_AUTOEDIT=no +export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT +export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME +export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME +export EDITOR + +# Tests using GIT_TRACE typically don't want : output +GIT_TRACE_BARE=1 +export GIT_TRACE_BARE + +if test -n "${TEST_GIT_INDEX_VERSION:+isset}" +then + GIT_INDEX_VERSION="$TEST_GIT_INDEX_VERSION" + export GIT_INDEX_VERSION +fi + +# Add libc MALLOC and MALLOC_PERTURB test +if test -n "$TEST_NO_MALLOC_CHECK" +then + setup_malloc_check () { + : nothing + } + teardown_malloc_check () { + : nothing + } +else + setup_malloc_check () { + MALLOC_CHECK_=3 MALLOC_PERTURB_=165 + export MALLOC_CHECK_ MALLOC_PERTURB_ + } + teardown_malloc_check () { + unset MALLOC_CHECK_ MALLOC_PERTURB_ + } +fi + +: ${ASAN_OPTIONS=detect_leaks=0} +export ASAN_OPTIONS + +# Protect ourselves from common misconfiguration to export +# CDPATH into the environment +unset CDPATH + +unset GREP_OPTIONS +unset UNZIP + +case $(echo $GIT_TRACE |tr "[A-Z]" "[a-z]") in +1|2|true) + GIT_TRACE=4 + ;; +esac + +# Convenience +# +# A regexp to match 5 and 40 hexdigits +_x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' +_x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05" + +# Zero SHA-1 +_z40=0000000000000000000000000000000000000000 + +EMPTY_TREE=4b825dc642cb6eb9a060e54bf8d69288fbee4904 +EMPTY_BLOB=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 + +# Line feed +LF=' +' + +# UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores +# when case-folding filenames +u200c=$(printf '\342\200\214') + +export _x05 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB + +# Each test should start with something like this, after copyright notices: +# +# test_description='Description of this test... +# This test checks if command xyzzy does the right thing... +# ' +# . ./test-lib.sh +test "x$TERM" != "xdumb" && ( + test -t 1 && + tput bold >/dev/null 2>&1 && + tput setaf 1 >/dev/null 2>&1 && + tput sgr0 >/dev/null 2>&1 + ) && + color=t + +while test "$#" -ne 0 +do + case "$1" in + -d|--d|--de|--deb|--debu|--debug) + debug=t; shift ;; + -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate) + immediate=t; shift ;; + -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests) + GIT_TEST_LONG=t; export GIT_TEST_LONG; shift ;; + -r) + shift; test "$#" -ne 0 || { + echo 'error: -r requires an argument' >&2; + exit 1; + } + run_list=$1; shift ;; + --run=*) + run_list=${1#--*=}; shift ;; + -h|--h|--he|--hel|--help) + help=t; shift ;; + -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) + verbose=t; shift ;; + --verbose-only=*) + verbose_only=${1#--*=} + shift ;; + -q|--q|--qu|--qui|--quie|--quiet) + # Ignore --quiet under a TAP::Harness. Saying how many tests + # passed without the ok/not ok details is always an error. + test -z "$HARNESS_ACTIVE" && quiet=t; shift ;; + --with-dashes) + with_dashes=t; shift ;; + --no-color) + color=; shift ;; + --tee) + shift ;; # was handled already + --root=*) + root=${1#--*=} + shift ;; + --chain-lint) + GIT_TEST_CHAIN_LINT=1 + shift ;; + --no-chain-lint) + GIT_TEST_CHAIN_LINT=0 + shift ;; + -x) + trace=t + verbose=t + shift ;; + --verbose-log) + verbose_log=t + shift ;; + *) + echo "error: unknown test option '$1'" >&2; exit 1 ;; + esac +done + +if test -n "$color" +then + # Save the color control sequences now rather than run tput + # each time say_color() is called. This is done for two + # reasons: + # * TERM will be changed to dumb + # * HOME will be changed to a temporary directory and tput + # might need to read ~/.terminfo from the original HOME + # directory to get the control sequences + # Note: This approach assumes the control sequences don't end + # in a newline for any terminal of interest (command + # substitutions strip trailing newlines). Given that most + # (all?) terminals in common use are related to ECMA-48, this + # shouldn't be a problem. + say_color_error=$(tput bold; tput setaf 1) # bold red + say_color_skip=$(tput setaf 4) # blue + say_color_warn=$(tput setaf 3) # brown/yellow + say_color_pass=$(tput setaf 2) # green + say_color_info=$(tput setaf 6) # cyan + say_color_reset=$(tput sgr0) + say_color_="" # no formatting for normal text + say_color () { + test -z "$1" && test -n "$quiet" && return + eval "say_color_color=\$say_color_$1" + shift + printf "%s\\n" "$say_color_color$*$say_color_reset" + } +else + say_color() { + test -z "$1" && test -n "$quiet" && return + shift + printf "%s\n" "$*" + } +fi + +TERM=dumb +export TERM + +error () { + say_color error "error: $*" + GIT_EXIT_OK=t + exit 1 +} + +say () { + say_color info "$*" +} + +if test -n "$HARNESS_ACTIVE" +then + if test "$verbose" = t || test -n "$verbose_only" + then + printf 'Bail out! %s\n' \ + 'verbose mode forbidden under TAP harness; try --verbose-log' + exit 1 + fi +fi + +test "${test_description}" != "" || +error "Test script did not set test_description." + +if test "$help" = "t" +then + printf '%s\n' "$test_description" + exit 0 +fi + +exec 5>&1 +exec 6<&0 +exec 7>&2 +if test "$verbose_log" = "t" +then + exec 3>>"$GIT_TEST_TEE_OUTPUT_FILE" 4>&3 +elif test "$verbose" = "t" +then + exec 4>&2 3>&1 +else + exec 4>/dev/null 3>/dev/null +fi + +# Send any "-x" output directly to stderr to avoid polluting tests +# which capture stderr. We can do this unconditionally since it +# has no effect if tracing isn't turned on. +# +# Note that this sets up the trace fd as soon as we assign the variable, so it +# must come after the creation of descriptor 4 above. Likewise, we must never +# unset this, as it has the side effect of closing descriptor 4, which we +# use to show verbose tests to the user. +# +# Note also that we don't need or want to export it. The tracing is local to +# this shell, and we would not want to influence any shells we exec. +BASH_XTRACEFD=4 + +test_failure=0 +test_count=0 +test_fixed=0 +test_broken=0 +test_success=0 + +test_external_has_tap=0 + +die () { + code=$? + if test -n "$GIT_EXIT_OK" + then + exit $code + else + echo >&5 "FATAL: Unexpected exit with code $code" + exit 1 + fi +} + +GIT_EXIT_OK= +trap 'die' EXIT +trap 'exit $?' INT + +# The user-facing functions are loaded from a separate file so that +# test_perf subshells can have them too +. "$TEST_DIRECTORY/test-lib-functions.sh" + +# You are not expected to call test_ok_ and test_failure_ directly, use +# the test_expect_* functions instead. + +test_ok_ () { + test_success=$(($test_success + 1)) + say_color "" "ok $test_count - $@" +} + +test_failure_ () { + test_failure=$(($test_failure + 1)) + say_color error "not ok $test_count - $1" + shift + printf '%s\n' "$*" | sed -e 's/^/# /' + test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; } +} + +test_known_broken_ok_ () { + test_fixed=$(($test_fixed+1)) + say_color error "ok $test_count - $@ # TODO known breakage vanished" +} + +test_known_broken_failure_ () { + test_broken=$(($test_broken+1)) + say_color warn "not ok $test_count - $@ # TODO known breakage" +} + +test_debug () { + test "$debug" = "" || eval "$1" +} + +match_pattern_list () { + arg="$1" + shift + test -z "$*" && return 1 + for pattern_ + do + case "$arg" in + $pattern_) + return 0 + esac + done + return 1 +} + +match_test_selector_list () { + title="$1" + shift + arg="$1" + shift + test -z "$1" && return 0 + + # Both commas and whitespace are accepted as separators. + OLDIFS=$IFS + IFS=' ,' + set -- $1 + IFS=$OLDIFS + + # If the first selector is negative we include by default. + include= + case "$1" in + !*) include=t ;; + esac + + for selector + do + orig_selector=$selector + + positive=t + case "$selector" in + !*) + positive= + selector=${selector##?} + ;; + esac + + test -z "$selector" && continue + + case "$selector" in + *-*) + if expr "z${selector%%-*}" : "z[0-9]*[^0-9]" >/dev/null + then + echo "error: $title: invalid non-numeric in range" \ + "start: '$orig_selector'" >&2 + exit 1 + fi + if expr "z${selector#*-}" : "z[0-9]*[^0-9]" >/dev/null + then + echo "error: $title: invalid non-numeric in range" \ + "end: '$orig_selector'" >&2 + exit 1 + fi + ;; + *) + if expr "z$selector" : "z[0-9]*[^0-9]" >/dev/null + then + echo "error: $title: invalid non-numeric in test" \ + "selector: '$orig_selector'" >&2 + exit 1 + fi + esac + + # Short cut for "obvious" cases + test -z "$include" && test -z "$positive" && continue + test -n "$include" && test -n "$positive" && continue + + case "$selector" in + -*) + if test $arg -le ${selector#-} + then + include=$positive + fi + ;; + *-) + if test $arg -ge ${selector%-} + then + include=$positive + fi + ;; + *-*) + if test ${selector%%-*} -le $arg \ + && test $arg -le ${selector#*-} + then + include=$positive + fi + ;; + *) + if test $arg -eq $selector + then + include=$positive + fi + ;; + esac + done + + test -n "$include" +} + +maybe_teardown_verbose () { + test -z "$verbose_only" && return + exec 4>/dev/null 3>/dev/null + verbose= +} + +last_verbose=t +maybe_setup_verbose () { + test -z "$verbose_only" && return + if match_pattern_list $test_count $verbose_only + then + exec 4>&2 3>&1 + # Emit a delimiting blank line when going from + # non-verbose to verbose. Within verbose mode the + # delimiter is printed by test_expect_*. The choice + # of the initial $last_verbose is such that before + # test 1, we do not print it. + test -z "$last_verbose" && echo >&3 "" + verbose=t + else + exec 4>/dev/null 3>/dev/null + verbose= + fi + last_verbose=$verbose +} + +maybe_teardown_valgrind () { + test -z "$GIT_VALGRIND" && return + GIT_VALGRIND_ENABLED= +} + +maybe_setup_valgrind () { + test -z "$GIT_VALGRIND" && return + if test -z "$valgrind_only" + then + GIT_VALGRIND_ENABLED=t + return + fi + GIT_VALGRIND_ENABLED= + if match_pattern_list $test_count $valgrind_only + then + GIT_VALGRIND_ENABLED=t + fi +} + +want_trace () { + test "$trace" = t && test "$verbose" = t +} + +# This is a separate function because some tests use +# "return" to end a test_expect_success block early +# (and we want to make sure we run any cleanup like +# "set +x"). +test_eval_inner_ () { + # Do not add anything extra (including LF) after '$*' + eval " + want_trace && set -x + $*" +} + +test_eval_ () { + # We run this block with stderr redirected to avoid extra cruft + # during a "-x" trace. Once in "set -x" mode, we cannot prevent + # the shell from printing the "set +x" to turn it off (nor the saving + # of $? before that). But we can make sure that the output goes to + # /dev/null. + # + # The test itself is run with stderr put back to &4 (so either to + # /dev/null, or to the original stderr if --verbose was used). + { + test_eval_inner_ "$@" &3 2>&4 + test_eval_ret_=$? + if want_trace + then + set +x + if test "$test_eval_ret_" != 0 + then + say_color error >&4 "error: last command exited with \$?=$test_eval_ret_" + fi + fi + } 2>/dev/null + return $test_eval_ret_ +} + +test_run_ () { + test_cleanup=: + expecting_failure=$2 + + if test "${GIT_TEST_CHAIN_LINT:-1}" != 0; then + # turn off tracing for this test-eval, as it simply creates + # confusing noise in the "-x" output + trace_tmp=$trace + trace= + # 117 is magic because it is unlikely to match the exit + # code of other programs + if test "OK-117" != "$(test_eval_ "(exit 117) && $1${LF}${LF}echo OK-\$?" 3>&1)" + then + error "bug in the test script: broken &&-chain or run-away HERE-DOC: $1" + fi + trace=$trace_tmp + fi + + setup_malloc_check + test_eval_ "$1" + eval_ret=$? + teardown_malloc_check + + if test -z "$immediate" || test $eval_ret = 0 || + test -n "$expecting_failure" && test "$test_cleanup" != ":" + then + setup_malloc_check + test_eval_ "$test_cleanup" + teardown_malloc_check + fi + if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE" + then + echo "" + fi + return "$eval_ret" +} + +test_start_ () { + test_count=$(($test_count+1)) + maybe_setup_verbose + maybe_setup_valgrind +} + +test_finish_ () { + echo >&3 "" + maybe_teardown_valgrind + maybe_teardown_verbose +} + +test_skip () { + to_skip= + skipped_reason= + if match_pattern_list $this_test.$test_count $GIT_SKIP_TESTS + then + to_skip=t + skipped_reason="GIT_SKIP_TESTS" + fi + if test -z "$to_skip" && test -n "$test_prereq" && + ! test_have_prereq "$test_prereq" + then + to_skip=t + + of_prereq= + if test "$missing_prereq" != "$test_prereq" + then + of_prereq=" of $test_prereq" + fi + skipped_reason="missing $missing_prereq${of_prereq}" + fi + if test -z "$to_skip" && test -n "$run_list" && + ! match_test_selector_list '--run' $test_count "$run_list" + then + to_skip=t + skipped_reason="--run" + fi + + case "$to_skip" in + t) + say_color skip >&3 "skipping test: $@" + say_color skip "ok $test_count # skip $1 ($skipped_reason)" + : true + ;; + *) + false + ;; + esac +} + +# stub; perf-lib overrides it +test_at_end_hook_ () { + : +} + +test_done () { + GIT_EXIT_OK=t + + if test -z "$HARNESS_ACTIVE" + then + test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results" + mkdir -p "$test_results_dir" + base=${0##*/} + test_results_path="$test_results_dir/${base%.sh}.counts" + + cat >"$test_results_path" <<-EOF + total $test_count + success $test_success + fixed $test_fixed + broken $test_broken + failed $test_failure + + EOF + fi + + if test "$test_fixed" != 0 + then + say_color error "# $test_fixed known breakage(s) vanished; please update test(s)" + fi + if test "$test_broken" != 0 + then + say_color warn "# still have $test_broken known breakage(s)" + fi + if test "$test_broken" != 0 || test "$test_fixed" != 0 + then + test_remaining=$(( $test_count - $test_broken - $test_fixed )) + msg="remaining $test_remaining test(s)" + else + test_remaining=$test_count + msg="$test_count test(s)" + fi + case "$test_failure" in + 0) + # Maybe print SKIP message + if test -n "$skip_all" && test $test_count -gt 0 + then + error "Can't use skip_all after running some tests" + fi + test -z "$skip_all" || skip_all=" # SKIP $skip_all" + + if test $test_external_has_tap -eq 0 + then + if test $test_remaining -gt 0 + then + say_color pass "# passed all $msg" + fi + say "1..$test_count$skip_all" + fi + + test -d "$remove_trash" && + cd "$(dirname "$remove_trash")" && + rm -rf "$(basename "$remove_trash")" + + test_at_end_hook_ + + exit 0 ;; + + *) + if test $test_external_has_tap -eq 0 + then + say_color error "# failed $test_failure among $msg" + say "1..$test_count" + fi + + exit 1 ;; + + esac +} + +GIT_EXEC_PATH=$(git --exec-path) || error "Cannot run git." +PATH=$GIT_BUILD_DIR:$PATH + +GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt +GIT_CONFIG_NOSYSTEM=1 +GIT_ATTR_NOSYSTEM=1 +export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM + +if test -z "$GIT_TEST_CMP" +then + if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT" + then + GIT_TEST_CMP="$DIFF -c" + else + GIT_TEST_CMP="$DIFF -u" + fi +fi + +GITPERLLIB="$GIT_BUILD_DIR"/perl/blib/lib:"$GIT_BUILD_DIR"/perl/blib/arch/auto/Git +export GITPERLLIB + +# Test repository +TRASH_DIRECTORY="trash directory.$(basename "$0" .sh)" +test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY" +case "$TRASH_DIRECTORY" in +/*) ;; # absolute path is good + *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;; +esac +test ! -z "$debug" || remove_trash=$TRASH_DIRECTORY +rm -fr "$TRASH_DIRECTORY" || { + GIT_EXIT_OK=t + echo >&5 "FATAL: Cannot prepare test area" + exit 1 +} + +HOME="$TRASH_DIRECTORY" +GNUPGHOME="$HOME/gnupg-home-not-used" +export HOME GNUPGHOME + +mkdir -p "$TRASH_DIRECTORY" + +# Use -P to resolve symlinks in our working directory so that the cwd +# in subprocesses like git equals our $PWD (for pathname comparisons). +cd -P "$TRASH_DIRECTORY" || exit 1 + +this_test=${0##*/} +this_test=${this_test%%-*} +if match_pattern_list "$this_test" $GIT_SKIP_TESTS +then + say_color info >&3 "skipping test $this_test altogether" + skip_all="skip all tests in $this_test" + test_done +fi + +# Provide an implementation of the 'yes' utility +yes () { + if test $# = 0 + then + y=y + else + y="$*" + fi + + i=0 + while test $i -lt 99 + do + echo "$y" + i=$(($i+1)) + done +} + +# Fix some commands on Windows +uname_s=$(uname -s) +case $uname_s in +*MINGW*) + # Windows has its own (incompatible) sort and find + sort () { + /usr/bin/sort "$@" + } + find () { + /usr/bin/find "$@" + } + sum () { + md5sum "$@" + } + # git sees Windows-style pwd + pwd () { + builtin pwd -W + } + # no POSIX permissions + # backslashes in pathspec are converted to '/' + # exec does not inherit the PID + test_set_prereq MINGW + test_set_prereq NATIVE_CRLF + test_set_prereq SED_STRIPS_CR + test_set_prereq GREP_STRIPS_CR + GIT_TEST_CMP=mingw_test_cmp + ;; +*CYGWIN*) + test_set_prereq POSIXPERM + test_set_prereq EXECKEEPSPID + test_set_prereq CYGWIN + test_set_prereq SED_STRIPS_CR + test_set_prereq GREP_STRIPS_CR + ;; +*) + test_set_prereq POSIXPERM + test_set_prereq BSLASHPSPEC + test_set_prereq EXECKEEPSPID + ;; +esac + +( COLUMNS=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1 +test -z "$NO_PERL" && test_set_prereq PERL +test -z "$NO_PYTHON" && test_set_prereq PYTHON +test -n "$USE_LIBPCRE" && test_set_prereq LIBPCRE +test -z "$NO_GETTEXT" && test_set_prereq GETTEXT + +# Can we rely on git's output in the C locale? +if test -n "$GETTEXT_POISON" +then + GIT_GETTEXT_POISON=YesPlease + export GIT_GETTEXT_POISON + test_set_prereq GETTEXT_POISON +else + test_set_prereq C_LOCALE_OUTPUT +fi + +# Use this instead of test_cmp to compare files that contain expected and +# actual output from git commands that can be translated. When running +# under GETTEXT_POISON this pretends that the command produced expected +# results. +test_i18ncmp () { + test -n "$GETTEXT_POISON" || test_cmp "$@" +} + +# Use this instead of "grep expected-string actual" to see if the +# output from a git command that can be translated either contains an +# expected string, or does not contain an unwanted one. When running +# under GETTEXT_POISON this pretends that the command produced expected +# results. +test_i18ngrep () { + if test -n "$GETTEXT_POISON" + then + : # pretend success + elif test "x!" = "x$1" + then + shift + ! grep "$@" + else + grep "$@" + fi +} + +test_lazy_prereq PIPE ' + # test whether the filesystem supports FIFOs + case $(uname -s) in + CYGWIN*|MINGW*) + false + ;; + *) + rm -f testfifo && mkfifo testfifo + ;; + esac +' + +test_lazy_prereq SYMLINKS ' + # test whether the filesystem supports symbolic links + ln -s x y && test -h y +' + +test_lazy_prereq FILEMODE ' + test "$(git config --bool core.filemode)" = true +' + +test_lazy_prereq CASE_INSENSITIVE_FS ' + echo good >CamelCase && + echo bad >camelcase && + test "$(cat CamelCase)" != good +' + +test_lazy_prereq UTF8_NFD_TO_NFC ' + # check whether FS converts nfd unicode to nfc + auml=$(printf "\303\244") + aumlcdiar=$(printf "\141\314\210") + >"$auml" && + case "$(echo *)" in + "$aumlcdiar") + true ;; + *) + false ;; + esac +' + +test_lazy_prereq AUTOIDENT ' + sane_unset GIT_AUTHOR_NAME && + sane_unset GIT_AUTHOR_EMAIL && + git var GIT_AUTHOR_IDENT +' + +test_lazy_prereq EXPENSIVE ' + test -n "$GIT_TEST_LONG" +' + +test_lazy_prereq USR_BIN_TIME ' + test -x /usr/bin/time +' + +test_lazy_prereq NOT_ROOT ' + uid=$(id -u) && + test "$uid" != 0 +' + +test_lazy_prereq JGIT ' + type jgit +' + +# SANITY is about "can you correctly predict what the filesystem would +# do by only looking at the permission bits of the files and +# directories?" A typical example of !SANITY is running the test +# suite as root, where a test may expect "chmod -r file && cat file" +# to fail because file is supposed to be unreadable after a successful +# chmod. In an environment (i.e. combination of what filesystem is +# being used and who is running the tests) that lacks SANITY, you may +# be able to delete or create a file when the containing directory +# doesn't have write permissions, or access a file even if the +# containing directory doesn't have read or execute permissions. + +test_lazy_prereq SANITY ' + mkdir SANETESTD.1 SANETESTD.2 && + + chmod +w SANETESTD.1 SANETESTD.2 && + >SANETESTD.1/x 2>SANETESTD.2/x && + chmod -w SANETESTD.1 && + chmod -r SANETESTD.1/x && + chmod -rx SANETESTD.2 || + error "bug in test sript: cannot prepare SANETESTD" + + ! test -r SANETESTD.1/x && + ! rm SANETESTD.1/x && ! test -f SANETESTD.2/x + status=$? + + chmod +rwx SANETESTD.1 SANETESTD.2 && + rm -rf SANETESTD.1 SANETESTD.2 || + error "bug in test sript: cannot clean SANETESTD" + return $status +' + +test FreeBSD != $uname_s || GIT_UNZIP=${GIT_UNZIP:-/usr/local/bin/unzip} +GIT_UNZIP=${GIT_UNZIP:-unzip} +test_lazy_prereq UNZIP ' + "$GIT_UNZIP" -v + test $? -ne 127 +' + +run_with_limited_cmdline () { + (ulimit -s 128 && "$@") +} + +test_lazy_prereq CMDLINE_LIMIT 'run_with_limited_cmdline true' + +build_option () { + git version --build-options | + sed -ne "s/^$1: //p" +} + +test_lazy_prereq LONG_IS_64BIT ' + test 8 -le "$(build_option sizeof-long)" +' From d0f3315b905f3100cba78a2fb64594a081e41149 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 5 May 2017 09:02:31 -0500 Subject: [PATCH 049/151] move test-lib tests to *.sh --- t/{help.t => help.sh} | 2 -- 1 file changed, 2 deletions(-) rename t/{help.t => help.sh} (98%) diff --git a/t/help.t b/t/help.sh similarity index 98% rename from t/help.t rename to t/help.sh index 979f32bb..732526a4 100755 --- a/t/help.t +++ b/t/help.sh @@ -5,8 +5,6 @@ test_description='Help command' . test-lib.sh . "$TEST_DIRECTORY/environment.bash" -VCSH='sh vcsh' - test_expect_failure 'Help command succeeds' \ '$VCSH help' From 63640ff4d709c1e99b09813155a383d7869f9831 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 5 May 2017 16:17:13 -0500 Subject: [PATCH 050/151] more progress on test-lib-ifying tests --- t/environment.bash | 71 +++++++--------------- t/help.sh | 2 +- t/init-umask.sh | 14 +++++ t/init.sh | 129 +++++++++++++++++++++++++++++++++++++++ t/init.t | 146 --------------------------------------------- 5 files changed, 165 insertions(+), 197 deletions(-) create mode 100755 t/init-umask.sh create mode 100755 t/init.sh delete mode 100755 t/init.t diff --git a/t/environment.bash b/t/environment.bash index 212c27a0..e6d5dfec 100644 --- a/t/environment.bash +++ b/t/environment.bash @@ -1,57 +1,28 @@ -setup() { - export VCSH="$BATS_TEST_DIRNAME/../vcsh" - export LC_ALL=C +# Command to run for vcsh (test-lib will put build dir at the head of PATH) +# To test other shells: "dash vcsh", "zsh vcsh", etc. +export VCSH="vcsh" - # XXX Currently the /etc/vcsh/config file can affect testcases. - # Perhaps it should be ignored if one exists in $XDG_CONFIG_HOME or was - # specified with -c? +# XXX Currently the /etc/vcsh/config file can affect testcases. +# Perhaps it should be ignored if one exists in $XDG_CONFIG_HOME or was +# specified with -c? - # Test repository. For faster tests, you can create a local mirror and - # use that instead. - : ${TESTREPO:='https://github.com/djpohly/vcsh_testrepo.git'} - : ${TESTREPONAME:='vcsh_testrepo'} - export TESTREPO TESTREPONAME - export TESTM1=master - export TESTM2=master2 - export TESTBR1=branch1 - export TESTBR2=branch2 - export TESTBRX=conflict +# Test repository. For faster tests, you can create a local mirror and +# use that instead. +: ${TESTREPO:='https://github.com/djpohly/vcsh_testrepo.git'} +: ${TESTREPONAME:='vcsh_testrepo'} +export TESTREPO TESTREPONAME +export TESTM1=master +export TESTM2=master2 +export TESTBR1=branch1 +export TESTBR2=branch2 +export TESTBRX=conflict - # Other things used in tests - export GITVERSION=$(git version) +# Other things used in tests +export GITVERSION=$(git version) - # Clear out environment variables that affect VCSH behavior - unset VCSH_OPTION_CONFIG VCSH_REPO_D VCSH_HOOK_D VCSH_OVERLAY_D - unset VCSH_BASE VCSH_GITIGNORE VCSH_GITATTRIBUTES VCSH_WORKTREE - unset XDG_CONFIG_HOME - - # Make a directory for testing and make it $HOME - export BATS_TESTDIR=$(mktemp -d -p "$BATS_TMPDIR") - export HOME=$BATS_TESTDIR - cd - - # Clear out variables that affect Git behavior - unset EDITOR VISUAL GIT_EDITOR - - # Set a few Git variables - GIT_AUTHOR_NAME='A U Thor' - GIT_AUTHOR_EMAIL='author@example.com' - GIT_COMMITTER_NAME='C O Mitter' - GIT_COMMITTER_EMAIL='committer@example.com' - GIT_MERGE_VERBOSITY=5 - GIT_MERGE_AUTOEDIT=no - export GIT_{AUTHOR,COMMITTER}_{NAME,EMAIL} - export GIT_MERGE_{VERBOSITY,AUTOEDIT} -} - -teardown() { - # Don't saw off the branch you're sitting on - cd / - - # Make sure removal will succeed even if we have altered permissions - chmod -R a+rwx "$BATS_TESTDIR" - rm -rf "$BATS_TESTDIR" -} +# Clear out environment variables that affect VCSH behavior +unset VCSH_OPTION_CONFIG VCSH_REPO_D VCSH_HOOK_D VCSH_OVERLAY_D +unset VCSH_BASE VCSH_GITIGNORE VCSH_GITATTRIBUTES VCSH_WORKTREE num_gitrepos() { # Prints the number of apparent Git repositories below $1 diff --git a/t/help.sh b/t/help.sh index 732526a4..823b1fd5 100755 --- a/t/help.sh +++ b/t/help.sh @@ -10,7 +10,7 @@ test_expect_failure 'Help command succeeds' \ test_expect_success 'Help command writes to stderr and not stdout' \ '$VCSH help 2>&1 1>/dev/null | assert_grep "" && - ! $VCSH help 2>/dev/null | assert_grep ""' + $VCSH help 2>/dev/null | test_must_fail assert_grep ""' test_expect_success 'Help command prints usage on first line' \ '$VCSH help |& diff --git a/t/init-umask.sh b/t/init-umask.sh new file mode 100755 index 00000000..47045fdb --- /dev/null +++ b/t/init-umask.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +test_description='Ensure init creates files with limited permissions' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +# verifies commit e220a61 +test_expect_success 'Files created by init are not readable by other users' \ + '$VCSH init foo && + output="$(find "$HOME" -type f -perm /g+rwx,o+rwx)" && + assert "$output" = ""' + +test_done diff --git a/t/init.sh b/t/init.sh new file mode 100755 index 00000000..090983c5 --- /dev/null +++ b/t/init.sh @@ -0,0 +1,129 @@ +#!/bin/bash + +test_description='Init command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Init command succeeds' \ + '$VCSH init foo' + +test_expect_success 'Init command fails if repository already exists' \ + 'test_must_fail $VCSH init foo' + +test_expect_success 'Init command can be abbreviated (ini, in)' \ + '$VCSH ini bar && + $VCSH in baz && + test_must_fail $VCSH ini foo && + test_must_fail $VCSH in foo' + +test_expect_failure 'Init command takes exactly one parameter' \ + 'test_must_fail $VCSH init && + test_must_fail $VCSH init one two && + test_must_fail $VCSH init a b c' + +test_expect_success 'Init creates repositories with same toplevel' \ + 'toplevel="$($VCSH run foo git rev-parse --show-toplevel)" && + output="$($VCSH run bar git rev-parse --show-toplevel)" && + assert "$output" = "$toplevel"' + +test_expect_success 'Init command respects alternate $VCSH_REPO_D' \ + 'mkdir -p repod1 repod2 && + VCSH_REPO_D="$PWD/repod1" $VCSH init alt-repo && + VCSH_REPO_D="$PWD/repod2" $VCSH init alt-repo' + +test_expect_success 'Init command respects alternate $XDG_CONFIG_HOME' \ + 'mkdir -p xdg1 xdg2 && + XDG_CONFIG_HOME="$PWD/xdg1" $VCSH init alt-xdg && + XDG_CONFIG_HOME="$PWD/xdg2" $VCSH init alt-xdg' + +test_expect_success 'Init command respects alternate $HOME' \ + 'mkdir -p home1 home2 && + HOME="$PWD/home1" $VCSH init alt-home && + HOME="$PWD/home2" $VCSH init alt-home' + +test_expect_success 'Init command fails if directories cannot be created' \ + 'mkdir ro && + chmod a-w ro && + HOME="$PWD/ro" test_must_fail $VCSH init foo' + +test_expect_success '$VCSH_REPO_D overrides $XDG_CONFIG_HOME and $HOME for init' \ + 'mkdir -p foo4 bar4 foo4a bar4a over4a over4b && + HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4a" $VCSH init samename && + HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename && + HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename && + HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename && + HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4b" $VCSH init samename && + HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename && + HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename && + HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename' + +test_expect_success '$XDG_CONFIG_HOME overrides $HOME for init' \ + 'mkdir -p foo5 bar5 over5a over5b && + HOME="$PWD/foo5" XDG_CONFIG_HOME="$PWD/over5a" $VCSH init samename && + HOME="$PWD/bar5" XDG_CONFIG_HOME="$PWD/over5a" test_must_fail $VCSH init samename && + HOME="$PWD/foo5" XDG_CONFIG_HOME="$PWD/over5b" $VCSH init samename && + HOME="$PWD/bar5" XDG_CONFIG_HOME="$PWD/over5b" test_must_fail $VCSH init samename' + +# Too internal to implementation? If another command verifies +# vcsh.vcsh, use that instead of git config. +test_expect_success 'Init command marks repository with vcsh.vcsh=true' \ + 'output=$($VCSH run foo git config vcsh.vcsh) && + assert "$output" = "true"' + +test_expect_success 'Init command adds matching gitignore.d files' \ + 'mkdir -p .gitattributes.d .gitignore.d && + touch .gitattributes.d/test1 .gitignore.d/test1 && + + VCSH_GITIGNORE=exact $VCSH init test1 && + $VCSH status test1 | assert_grep -Fx "A .gitignore.d/test1"' + +: << EOF +test_expect_success 'Init command creates new Git repository' \ + 'run num_gitrepos "$PWD" + assert "$output" = "0" + + for i in $(seq 5); do + $VCSH init "test$i" + run num_gitrepos "$PWD" + assert "$output" = "$i" + done' +} + +test_expect_success 'VCSH_GITIGNORE variable is validated' \ + test_must_fail VCSH_GITIGNORE=x $VCSH init foo || false + test_must_fail VCSH_GITIGNORE=nonsense $VCSH init foo || false + test_must_fail VCSH_GITIGNORE=fhqwhgads $VCSH init foo || false +} + +test_expect_success 'Init command sets core.excludesfile with VCSH_GITIGNORE=exact' \ + # XXX test instead by making sure files are actually excluded, not by + # reading config option + VCSH_GITIGNORE=exact $VCSH init test1 + $VCSH run test1 git config core.excludesfile +} + +test_expect_success 'Init command sets core.excludesfile with VCSH_GITIGNORE=recursive' \ + # XXX test instead by making sure files are actually excluded, not by + # reading config option + VCSH_GITIGNORE=recursive $VCSH init test1 + $VCSH run test1 git config core.excludesfile +} + +test_expect_success 'Init command does not set core.excludesfile with VCSH_GITIGNORE=none' \ + VCSH_GITIGNORE=none $VCSH init test1 + test_must_fail $VCSH run test1 git config core.excludesfile || false +} + +test_expect_success 'Init command sets core.attributesfile with VCSH_GITATTRIBUTES!=none' \ + VCSH_GITATTRIBUTES=whatever $VCSH init test1 + $VCSH run test1 git config core.attributesfile +} + +test_expect_success 'Init command does not set core.attributesfile with VCSH_GITATTRIBUTES=none' \ + VCSH_GITATTRIBUTES=none $VCSH init test1 + test_must_fail $VCSH run test1 git config core.attributesfile || false +} +EOF + +test_done diff --git a/t/init.t b/t/init.t deleted file mode 100755 index 606c5b78..00000000 --- a/t/init.t +++ /dev/null @@ -1,146 +0,0 @@ -#!/usr/bin/env bats - -load environment - -@test "Init command succeeds" { - $VCSH init foo -} - -@test "Init command takes exactly one parameter" { - skip "BUG" - - ! $VCSH init || false - ! $VCSH init foo bar || false - $VCSH init baz -} - -@test "Init command fails if repository already exists" { - $VCSH init exists - ! $VCSH init exists || false -} - -@test "Init creates repositories with same toplevel" { - $VCSH init foo - $VCSH init bar - - run $VCSH run foo git rev-parse --show-toplevel - toplevel="$output" - - run $VCSH run bar git rev-parse --show-toplevel - assert "$output" = "$toplevel" -} - -@test "Init command respects alternate \$VCSH_REPO_D" { - VCSH_REPO_D="$PWD/foo" $VCSH init samename - VCSH_REPO_D="$PWD/bar" $VCSH init samename -} - -@test "Init command respects alternate \$XDG_CONFIG_HOME" { - XDG_CONFIG_HOME="$PWD/foo" $VCSH init samename - XDG_CONFIG_HOME="$PWD/bar" $VCSH init samename -} - -@test "Init command respects alternate \$HOME" { - HOME="$PWD/foo" $VCSH init samename - HOME="$PWD/bar" $VCSH init samename -} - -@test "Init command fails if directories cannot be created" { - mkdir ro - chmod a-w ro - ! HOME="$PWD/ro" $VCSH init foo || false -} - -@test "Init command can be abbreviated 'ini'/'in'" { - $VCSH ini test1 - $VCSH in test2 - - run $VCSH list - assert "$status" -eq 0 - assert "$output" = $'test1\ntest2' -} - -@test "\$VCSH_REPO_D overrides \$XDG_CONFIG_HOME and \$HOME for init" { - HOME="$PWD/foo" $VCSH init samename1 - XDG_CONFIG_HOME="$PWD/bar" $VCSH init samename2 - - HOME="$PWD/foo" XDG_CONFIG_HOME="$PWD/bar" VCSH_REPO_D="$PWD/baz" $VCSH init samename1 - HOME="$PWD/foo" XDG_CONFIG_HOME="$PWD/bar" VCSH_REPO_D="$PWD/baz" $VCSH init samename2 -} - -@test "\$XDG_CONFIG_HOME overrides \$HOME for init" { - HOME="$PWD/foo" $VCSH init samename - HOME="$PWD/foo" XDG_CONFIG_HOME="$PWD/bar" $VCSH init samename -} - -@test "Init command marks repository with vcsh.vcsh=true" { - # Too internal to implementation? If another command verifies - # vcsh.vcsh, use that instead of git config. - - $VCSH init test1 - - run $VCSH run test1 git config vcsh.vcsh - assert "$status" -eq 0 - assert "$output" = "true" -} - -@test "Files created by init are not readable by other users" { - # verifies commit e220a61 - $VCSH init foo - run find "$PWD" -type f -perm /g+rwx,o+rwx - assert "$output" = '' -} - -@test "Init command adds matching gitignore.d files" { - mkdir -p .gitattributes.d .gitignore.d - touch .gitattributes.d/test1 .gitignore.d/test1 - - VCSH_GITIGNORE=exact $VCSH init test1 - $VCSH status test1 | assert_grep -Fx 'A .gitignore.d/test1' -} - -@test "Init command creates new Git repository" { - run num_gitrepos "$PWD" - assert "$output" = '0' - - for i in $(seq 5); do - $VCSH init "test$i" - run num_gitrepos "$PWD" - assert "$output" = "$i" - done -} - -@test "VCSH_GITIGNORE variable is validated" { - ! VCSH_GITIGNORE=x $VCSH init foo || false - ! VCSH_GITIGNORE=nonsense $VCSH init foo || false - ! VCSH_GITIGNORE=fhqwhgads $VCSH init foo || false -} - -@test "Init command sets core.excludesfile with VCSH_GITIGNORE=exact" { - # XXX test instead by making sure files are actually excluded, not by - # reading config option - VCSH_GITIGNORE=exact $VCSH init test1 - $VCSH run test1 git config core.excludesfile -} - -@test "Init command sets core.excludesfile with VCSH_GITIGNORE=recursive" { - # XXX test instead by making sure files are actually excluded, not by - # reading config option - VCSH_GITIGNORE=recursive $VCSH init test1 - $VCSH run test1 git config core.excludesfile -} - -@test "Init command does not set core.excludesfile with VCSH_GITIGNORE=none" { - VCSH_GITIGNORE=none $VCSH init test1 - ! $VCSH run test1 git config core.excludesfile || false -} - -@test "Init command sets core.attributesfile with VCSH_GITATTRIBUTES!=none" { - VCSH_GITATTRIBUTES=whatever $VCSH init test1 - $VCSH run test1 git config core.attributesfile -} - -@test "Init command does not set core.attributesfile with VCSH_GITATTRIBUTES=none" { - VCSH_GITATTRIBUTES=none $VCSH init test1 - ! $VCSH run test1 git config core.attributesfile || false -} From 34b4f1029e3ee1d9d3fa5b9381579dc1ecc04265 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 5 May 2017 20:49:48 -0500 Subject: [PATCH 051/151] easy approach: split bats test into many test-lib --- t/init.sh | 48 ------------------------------------------------ t/init2.sh | 19 +++++++++++++++++++ t/init3.sh | 13 +++++++++++++ t/init4.sh | 14 ++++++++++++++ t/init5.sh | 14 ++++++++++++++ t/init6.sh | 12 ++++++++++++ t/init7.sh | 12 ++++++++++++ t/init8.sh | 12 ++++++++++++ 8 files changed, 96 insertions(+), 48 deletions(-) create mode 100755 t/init2.sh create mode 100755 t/init3.sh create mode 100755 t/init4.sh create mode 100755 t/init5.sh create mode 100755 t/init6.sh create mode 100755 t/init7.sh create mode 100755 t/init8.sh diff --git a/t/init.sh b/t/init.sh index 090983c5..e6102343 100755 --- a/t/init.sh +++ b/t/init.sh @@ -78,52 +78,4 @@ test_expect_success 'Init command adds matching gitignore.d files' \ VCSH_GITIGNORE=exact $VCSH init test1 && $VCSH status test1 | assert_grep -Fx "A .gitignore.d/test1"' -: << EOF -test_expect_success 'Init command creates new Git repository' \ - 'run num_gitrepos "$PWD" - assert "$output" = "0" - - for i in $(seq 5); do - $VCSH init "test$i" - run num_gitrepos "$PWD" - assert "$output" = "$i" - done' -} - -test_expect_success 'VCSH_GITIGNORE variable is validated' \ - test_must_fail VCSH_GITIGNORE=x $VCSH init foo || false - test_must_fail VCSH_GITIGNORE=nonsense $VCSH init foo || false - test_must_fail VCSH_GITIGNORE=fhqwhgads $VCSH init foo || false -} - -test_expect_success 'Init command sets core.excludesfile with VCSH_GITIGNORE=exact' \ - # XXX test instead by making sure files are actually excluded, not by - # reading config option - VCSH_GITIGNORE=exact $VCSH init test1 - $VCSH run test1 git config core.excludesfile -} - -test_expect_success 'Init command sets core.excludesfile with VCSH_GITIGNORE=recursive' \ - # XXX test instead by making sure files are actually excluded, not by - # reading config option - VCSH_GITIGNORE=recursive $VCSH init test1 - $VCSH run test1 git config core.excludesfile -} - -test_expect_success 'Init command does not set core.excludesfile with VCSH_GITIGNORE=none' \ - VCSH_GITIGNORE=none $VCSH init test1 - test_must_fail $VCSH run test1 git config core.excludesfile || false -} - -test_expect_success 'Init command sets core.attributesfile with VCSH_GITATTRIBUTES!=none' \ - VCSH_GITATTRIBUTES=whatever $VCSH init test1 - $VCSH run test1 git config core.attributesfile -} - -test_expect_success 'Init command does not set core.attributesfile with VCSH_GITATTRIBUTES=none' \ - VCSH_GITATTRIBUTES=none $VCSH init test1 - test_must_fail $VCSH run test1 git config core.attributesfile || false -} -EOF - test_done diff --git a/t/init2.sh b/t/init2.sh new file mode 100755 index 00000000..d23007ac --- /dev/null +++ b/t/init2.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +test_description='Init command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Init command creates new Git repository' \ + 'output=$(num_gitrepos "$PWD") && + assert "$output" = "0" && + + for i in $(seq 5) + do + $VCSH init "test$i" && + output=$(num_gitrepos "$PWD") && + assert "$output" = "$i" + done' + +test_done diff --git a/t/init3.sh b/t/init3.sh new file mode 100755 index 00000000..ccdb9882 --- /dev/null +++ b/t/init3.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +test_description='Init command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'VCSH_GITIGNORE variable is validated' \ + 'VCSH_GITIGNORE=x test_must_fail $VCSH init foo && + VCSH_GITIGNORE=nonsense test_must_fail $VCSH init foo && + VCSH_GITIGNORE=fhqwhgads test_must_fail $VCSH init foo' + +test_done diff --git a/t/init4.sh b/t/init4.sh new file mode 100755 index 00000000..63afc9f2 --- /dev/null +++ b/t/init4.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +test_description='Init command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +# XXX test instead by making sure files are actually excluded, not by +# reading config option +test_expect_success 'Init command sets core.excludesfile with VCSH_GITIGNORE=exact' \ + 'VCSH_GITIGNORE=exact $VCSH init test1 && + $VCSH run test1 git config core.excludesfile' + +test_done diff --git a/t/init5.sh b/t/init5.sh new file mode 100755 index 00000000..13390d68 --- /dev/null +++ b/t/init5.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +test_description='Init command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +# XXX test instead by making sure files are actually excluded, not by +# reading config option +test_expect_success 'Init command sets core.excludesfile with VCSH_GITIGNORE=recursive' \ + 'VCSH_GITIGNORE=recursive $VCSH init test1 && + $VCSH run test1 git config core.excludesfile' + +test_done diff --git a/t/init6.sh b/t/init6.sh new file mode 100755 index 00000000..69636ade --- /dev/null +++ b/t/init6.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='Init command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Init command does not set core.excludesfile with VCSH_GITIGNORE=none' \ + 'VCSH_GITIGNORE=none $VCSH init test1 && + test_must_fail $VCSH run test1 git config core.excludesfile' + +test_done diff --git a/t/init7.sh b/t/init7.sh new file mode 100755 index 00000000..6ef097b7 --- /dev/null +++ b/t/init7.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='Init command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Init command sets core.attributesfile with VCSH_GITATTRIBUTES!=none' \ + 'VCSH_GITATTRIBUTES=whatever $VCSH init test1 && + $VCSH run test1 git config core.attributesfile' + +test_done diff --git a/t/init8.sh b/t/init8.sh new file mode 100755 index 00000000..a70e9373 --- /dev/null +++ b/t/init8.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='Init command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Init command does not set core.attributesfile with VCSH_GITATTRIBUTES=none' \ + 'VCSH_GITATTRIBUTES=none $VCSH init test1 && + test_must_fail $VCSH run test1 git config core.attributesfile' + +test_done From 1a00254b11bb485d8bd036cd97a157e1f989f968 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 5 May 2017 21:23:06 -0500 Subject: [PATCH 052/151] split and convert clone tests --- t/clone.t | 99 ---------------------------------------------------- t/clone1.sh | 11 ++++++ t/clone10.sh | 13 +++++++ t/clone11.sh | 16 +++++++++ t/clone2.sh | 14 ++++++++ t/clone3.sh | 13 +++++++ t/clone4.sh | 16 +++++++++ t/clone5.sh | 16 +++++++++ t/clone6.sh | 16 +++++++++ t/clone7.sh | 16 +++++++++ t/clone8.sh | 16 +++++++++ t/clone9.sh | 16 +++++++++ 12 files changed, 163 insertions(+), 99 deletions(-) delete mode 100755 t/clone.t create mode 100755 t/clone1.sh create mode 100755 t/clone10.sh create mode 100755 t/clone11.sh create mode 100755 t/clone2.sh create mode 100755 t/clone3.sh create mode 100755 t/clone4.sh create mode 100755 t/clone5.sh create mode 100755 t/clone6.sh create mode 100755 t/clone7.sh create mode 100755 t/clone8.sh create mode 100755 t/clone9.sh diff --git a/t/clone.t b/t/clone.t deleted file mode 100755 index 9ce6ec86..00000000 --- a/t/clone.t +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env bats - -load environment - -@test "Clone requires a remote" { - run $VCSH clone - assert "$status" -eq 1 -} - -@test "Clone uses existing repo name by default" { - $VCSH clone "$TESTREPO" - $VCSH list - run $VCSH list - assert "$status" -eq 0 - assert "$output" = "$TESTREPONAME" -} - -@test "Clone honors specified repo name" { - $VCSH clone "$TESTREPO" foo - run $VCSH list - assert "$status" -eq 0 - assert "$output" = "foo" -} - -@test "Clone uses given remote HEAD by default" { - $VCSH clone "$TESTREPO" - run git ls-remote "$TESTREPO" HEAD - correct=${output::40} - - run $VCSH run "$TESTREPONAME" git rev-parse HEAD - assert "$status" -eq 0 - assert "$output" = "$correct" -} - -@test "Clone honors -b option before remote" { - $VCSH clone -b "$TESTBR1" "$TESTREPO" - run git ls-remote "$TESTREPO" "$TESTBR1" - correct=${output::40} - - run $VCSH run "$TESTREPONAME" git rev-parse "$TESTBR1" - assert "$status" -eq 0 - assert "$output" = "$correct" -} - -@test "Clone honors -b option before remote and repo name" { - $VCSH clone -b "$TESTBR1" "$TESTREPO" foo - run git ls-remote "$TESTREPO" "$TESTBR1" - correct=${output::40} - - run $VCSH run foo git rev-parse "$TESTBR1" - assert "$status" -eq 0 - assert "$output" = "$correct" -} - -@test "Clone honors -b option after remote" { - $VCSH clone "$TESTREPO" -b "$TESTBR1" - run git ls-remote "$TESTREPO" "$TESTBR1" - correct=${output::40} - - run $VCSH run "$TESTREPONAME" git rev-parse "$TESTBR1" - assert "$status" -eq 0 - assert "$output" = "$correct" -} - -@test "Clone honors -b option between remote and repo name" { - $VCSH clone "$TESTREPO" -b "$TESTBR1" foo - run git ls-remote "$TESTREPO" "$TESTBR1" - correct=${output::40} - - run $VCSH run foo git rev-parse "$TESTBR1" - assert "$status" -eq 0 - assert "$output" = "$correct" -} - -@test "Clone honors -b option after repo name" { - $VCSH clone "$TESTREPO" foo -b "$TESTBR1" - run git ls-remote "$TESTREPO" "$TESTBR1" - correct=${output::40} - - run $VCSH run foo git rev-parse "$TESTBR1" - assert "$status" -eq 0 - assert "$output" = "$correct" -} - -@test "Clone -b option clones only one branch" { - $VCSH clone -b "$TESTBR1" "$TESTREPO" - run $VCSH run "$TESTREPONAME" git branch - assert "${#lines[@]}" -eq 1 -} - -@test "Clone can be abbreviated (clon, clo, cl)" { - $VCSH clon "$TESTREPO" a - $VCSH clo -b "$TESTBR1" "$TESTREPO" b - $VCSH cl -b "$TESTBR2" "$TESTREPO" c - - run $VCSH list - assert "$status" -eq 0 - assert "$output" = "$(printf 'a\nb\nc')" -} diff --git a/t/clone1.sh b/t/clone1.sh new file mode 100755 index 00000000..5eee3daf --- /dev/null +++ b/t/clone1.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +test_description='Clone command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Clone requires a remote' \ + 'test_must_fail $VCSH clone' + +test_done diff --git a/t/clone10.sh b/t/clone10.sh new file mode 100755 index 00000000..496e70cc --- /dev/null +++ b/t/clone10.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +test_description='Clone command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Clone -b option clones only one branch' \ + '$VCSH clone -b "$TESTBR1" "$TESTREPO" && + $VCSH run "$TESTREPONAME" git branch >output && + test_line_count = 1 output' + +test_done diff --git a/t/clone11.sh b/t/clone11.sh new file mode 100755 index 00000000..8fc02e98 --- /dev/null +++ b/t/clone11.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='Clone command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Clone can be abbreviated (clon, clo, cl)' \ + '$VCSH clon "$TESTREPO" a && + $VCSH clo -b "$TESTBR1" "$TESTREPO" b && + $VCSH cl -b "$TESTBR2" "$TESTREPO" c && + + output="$($VCSH list)" && + assert "$output" = "$(printf '\''a\nb\nc'\'')"' + +test_done diff --git a/t/clone2.sh b/t/clone2.sh new file mode 100755 index 00000000..efcfdfe0 --- /dev/null +++ b/t/clone2.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +test_description='Clone command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Clone uses existing repo name by default' \ + '$VCSH clone "$TESTREPO" && + $VCSH list && + output="$($VCSH list)" && + assert "$output" = "$TESTREPONAME" + +test_done diff --git a/t/clone3.sh b/t/clone3.sh new file mode 100755 index 00000000..4a0031c5 --- /dev/null +++ b/t/clone3.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +test_description='Clone command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Clone honors specified repo name' \ + '$VCSH clone "$TESTREPO" foo && + output=$($VCSH list) && + assert "$output" = "foo"' + +test_done diff --git a/t/clone4.sh b/t/clone4.sh new file mode 100755 index 00000000..ef0135d4 --- /dev/null +++ b/t/clone4.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='Clone command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Clone uses given remote HEAD by default' \ + '$VCSH clone "$TESTREPO" && + output="$(git ls-remote "$TESTREPO" HEAD)" && + correct=${output::40} && + + output="$($VCSH run "$TESTREPONAME" git rev-parse HEAD)" && + assert "$output" = "$correct"' + +test_done diff --git a/t/clone5.sh b/t/clone5.sh new file mode 100755 index 00000000..41986cc1 --- /dev/null +++ b/t/clone5.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='Clone command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Clone honors -b option before remote' \ + '$VCSH clone -b "$TESTBR1" "$TESTREPO" && + output="$(git ls-remote "$TESTREPO" "$TESTBR1")" && + correct=${output::40} && + + output="$($VCSH run "$TESTREPONAME" git rev-parse "$TESTBR1")" && + assert "$output" = "$correct"' + +test_done diff --git a/t/clone6.sh b/t/clone6.sh new file mode 100755 index 00000000..a899a16c --- /dev/null +++ b/t/clone6.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='Clone command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Clone honors -b option before remote and repo name' \ + '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && + output="$(git ls-remote "$TESTREPO" "$TESTBR1")" && + correct=${output::40} && + + output="$($VCSH run foo git rev-parse "$TESTBR1")" && + assert "$output" = "$correct"' + +test_done diff --git a/t/clone7.sh b/t/clone7.sh new file mode 100755 index 00000000..9f5dbef7 --- /dev/null +++ b/t/clone7.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='Clone command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +@test "Clone honors -b option after remote" { + $VCSH clone "$TESTREPO" -b "$TESTBR1" && + output="$(git ls-remote "$TESTREPO" "$TESTBR1")" && + correct=${output::40} && + + output="$($VCSH run "$TESTREPONAME" git rev-parse "$TESTBR1")" && + assert "$output" = "$correct"' + +test_done diff --git a/t/clone8.sh b/t/clone8.sh new file mode 100755 index 00000000..5a297e9f --- /dev/null +++ b/t/clone8.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='Clone command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Clone honors -b option between remote and repo name' \ + '$VCSH clone "$TESTREPO" -b "$TESTBR1" foo && + output="$(git ls-remote "$TESTREPO" "$TESTBR1")" && + correct=${output::40} && + + output="$($VCSH run foo git rev-parse "$TESTBR1")" && + assert "$output" = "$correct"' + +test_done diff --git a/t/clone9.sh b/t/clone9.sh new file mode 100755 index 00000000..cf3e58f6 --- /dev/null +++ b/t/clone9.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='Clone command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Clone honors -b option after repo name' \ + '$VCSH clone "$TESTREPO" foo -b "$TESTBR1" && + output="$(git ls-remote "$TESTREPO" "$TESTBR1")" && + correct=${output::40} && + + output="$($VCSH run foo git rev-parse "$TESTBR1")" && + assert "$output" = "$correct"' + +test_done From d4769f68c56c68af897eee4e740d72b41cdadefa Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 6 May 2017 02:09:14 -0500 Subject: [PATCH 053/151] update tests to use more test-lib idioms --- t/clone11.sh | 7 +++++-- t/clone2.sh | 6 +++--- t/clone3.sh | 5 +++-- t/clone4.sh | 8 ++++---- t/clone5.sh | 8 ++++---- t/clone6.sh | 8 ++++---- t/clone7.sh | 12 ++++++------ t/clone8.sh | 8 ++++---- t/clone9.sh | 8 ++++---- t/environment.bash | 8 ++++++-- t/init-umask.sh | 4 ++-- t/init.sh | 11 ++++++----- t/init2.sh | 11 +++++------ t/test-lib.sh | 2 +- 14 files changed, 57 insertions(+), 49 deletions(-) diff --git a/t/clone11.sh b/t/clone11.sh index 8fc02e98..4719fbde 100755 --- a/t/clone11.sh +++ b/t/clone11.sh @@ -10,7 +10,10 @@ test_expect_success 'Clone can be abbreviated (clon, clo, cl)' \ $VCSH clo -b "$TESTBR1" "$TESTREPO" b && $VCSH cl -b "$TESTBR2" "$TESTREPO" c && - output="$($VCSH list)" && - assert "$output" = "$(printf '\''a\nb\nc'\'')"' + echo a > expected && + echo b >> expected && + echo c >> expected && + $VCSH list >output && + test_cmp expected output' test_done diff --git a/t/clone2.sh b/t/clone2.sh index efcfdfe0..ccc42d81 100755 --- a/t/clone2.sh +++ b/t/clone2.sh @@ -7,8 +7,8 @@ test_description='Clone command' test_expect_success 'Clone uses existing repo name by default' \ '$VCSH clone "$TESTREPO" && - $VCSH list && - output="$($VCSH list)" && - assert "$output" = "$TESTREPONAME" + echo "$TESTREPONAME" >expected && + $VCSH list >output && + test_cmp expected output' test_done diff --git a/t/clone3.sh b/t/clone3.sh index 4a0031c5..9ed2173c 100755 --- a/t/clone3.sh +++ b/t/clone3.sh @@ -7,7 +7,8 @@ test_description='Clone command' test_expect_success 'Clone honors specified repo name' \ '$VCSH clone "$TESTREPO" foo && - output=$($VCSH list) && - assert "$output" = "foo"' + echo foo >expected && + $VCSH list >output && + test_cmp expected output' test_done diff --git a/t/clone4.sh b/t/clone4.sh index ef0135d4..ec8d30a6 100755 --- a/t/clone4.sh +++ b/t/clone4.sh @@ -7,10 +7,10 @@ test_description='Clone command' test_expect_success 'Clone uses given remote HEAD by default' \ '$VCSH clone "$TESTREPO" && - output="$(git ls-remote "$TESTREPO" HEAD)" && - correct=${output::40} && + git ls-remote "$TESTREPO" HEAD | head -c40 >expected && + echo >>expected && - output="$($VCSH run "$TESTREPONAME" git rev-parse HEAD)" && - assert "$output" = "$correct"' + $VCSH run "$TESTREPONAME" git rev-parse HEAD >output && + test_cmp expected output' test_done diff --git a/t/clone5.sh b/t/clone5.sh index 41986cc1..af5297c6 100755 --- a/t/clone5.sh +++ b/t/clone5.sh @@ -7,10 +7,10 @@ test_description='Clone command' test_expect_success 'Clone honors -b option before remote' \ '$VCSH clone -b "$TESTBR1" "$TESTREPO" && - output="$(git ls-remote "$TESTREPO" "$TESTBR1")" && - correct=${output::40} && + git ls-remote "$TESTREPO" "$TESTBR1" | head -c40 >expected && + echo >>expected && - output="$($VCSH run "$TESTREPONAME" git rev-parse "$TESTBR1")" && - assert "$output" = "$correct"' + $VCSH run "$TESTREPONAME" git rev-parse "$TESTBR1" >output && + test_cmp expected output' test_done diff --git a/t/clone6.sh b/t/clone6.sh index a899a16c..7649b11e 100755 --- a/t/clone6.sh +++ b/t/clone6.sh @@ -7,10 +7,10 @@ test_description='Clone command' test_expect_success 'Clone honors -b option before remote and repo name' \ '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && - output="$(git ls-remote "$TESTREPO" "$TESTBR1")" && - correct=${output::40} && + git ls-remote "$TESTREPO" "$TESTBR1" | head -c40 >expected && + echo >>expected && - output="$($VCSH run foo git rev-parse "$TESTBR1")" && - assert "$output" = "$correct"' + $VCSH run foo git rev-parse "$TESTBR1" >output && + test_cmp expected output' test_done diff --git a/t/clone7.sh b/t/clone7.sh index 9f5dbef7..352d4fa2 100755 --- a/t/clone7.sh +++ b/t/clone7.sh @@ -5,12 +5,12 @@ test_description='Clone command' . test-lib.sh . "$TEST_DIRECTORY/environment.bash" -@test "Clone honors -b option after remote" { - $VCSH clone "$TESTREPO" -b "$TESTBR1" && - output="$(git ls-remote "$TESTREPO" "$TESTBR1")" && - correct=${output::40} && +test_expect_success 'Clone honors -b option after remote' \ + '$VCSH clone "$TESTREPO" -b "$TESTBR1" && + git ls-remote "$TESTREPO" "$TESTBR1" | head -c40 >expected && + echo >>expected && - output="$($VCSH run "$TESTREPONAME" git rev-parse "$TESTBR1")" && - assert "$output" = "$correct"' + $VCSH run "$TESTREPONAME" git rev-parse "$TESTBR1" >output && + test_cmp expected output' test_done diff --git a/t/clone8.sh b/t/clone8.sh index 5a297e9f..2bbfd6aa 100755 --- a/t/clone8.sh +++ b/t/clone8.sh @@ -7,10 +7,10 @@ test_description='Clone command' test_expect_success 'Clone honors -b option between remote and repo name' \ '$VCSH clone "$TESTREPO" -b "$TESTBR1" foo && - output="$(git ls-remote "$TESTREPO" "$TESTBR1")" && - correct=${output::40} && + git ls-remote "$TESTREPO" "$TESTBR1" | head -c40 >expected && + echo >>expected && - output="$($VCSH run foo git rev-parse "$TESTBR1")" && - assert "$output" = "$correct"' + $VCSH run foo git rev-parse "$TESTBR1" >output && + test_cmp expected output' test_done diff --git a/t/clone9.sh b/t/clone9.sh index cf3e58f6..7e3554b3 100755 --- a/t/clone9.sh +++ b/t/clone9.sh @@ -7,10 +7,10 @@ test_description='Clone command' test_expect_success 'Clone honors -b option after repo name' \ '$VCSH clone "$TESTREPO" foo -b "$TESTBR1" && - output="$(git ls-remote "$TESTREPO" "$TESTBR1")" && - correct=${output::40} && + git ls-remote "$TESTREPO" "$TESTBR1" | head -c40 >expected && + echo >>expected && - output="$($VCSH run foo git rev-parse "$TESTBR1")" && - assert "$output" = "$correct"' + $VCSH run foo git rev-parse "$TESTBR1" >output && + test_cmp expected output' test_done diff --git a/t/environment.bash b/t/environment.bash index e6d5dfec..ab2dd5f3 100644 --- a/t/environment.bash +++ b/t/environment.bash @@ -24,9 +24,13 @@ export GITVERSION=$(git version) unset VCSH_OPTION_CONFIG VCSH_REPO_D VCSH_HOOK_D VCSH_OVERLAY_D unset VCSH_BASE VCSH_GITIGNORE VCSH_GITATTRIBUTES VCSH_WORKTREE +find_gitrepos() { + # Prints apparent Git repositories below $1 + find "$1" -mindepth 1 -type d -name '*.git' +} + num_gitrepos() { - # Prints the number of apparent Git repositories below $1 - find "$1" -mindepth 1 -type d -name '*.git' | wc -l + find_gitrepos "$@" | wc -l } assert() { diff --git a/t/init-umask.sh b/t/init-umask.sh index 47045fdb..f59ebd68 100755 --- a/t/init-umask.sh +++ b/t/init-umask.sh @@ -8,7 +8,7 @@ test_description='Ensure init creates files with limited permissions' # verifies commit e220a61 test_expect_success 'Files created by init are not readable by other users' \ '$VCSH init foo && - output="$(find "$HOME" -type f -perm /g+rwx,o+rwx)" && - assert "$output" = ""' + find "$HOME" -type f -perm /g+rwx,o+rwx >output && + test_must_be_empty output' test_done diff --git a/t/init.sh b/t/init.sh index e6102343..dd14c988 100755 --- a/t/init.sh +++ b/t/init.sh @@ -23,9 +23,9 @@ test_expect_failure 'Init command takes exactly one parameter' \ test_must_fail $VCSH init a b c' test_expect_success 'Init creates repositories with same toplevel' \ - 'toplevel="$($VCSH run foo git rev-parse --show-toplevel)" && - output="$($VCSH run bar git rev-parse --show-toplevel)" && - assert "$output" = "$toplevel"' + '$VCSH run foo git rev-parse --show-toplevel >output1 && + $VCSH run bar git rev-parse --show-toplevel >output2 && + test_cmp output1 output2' test_expect_success 'Init command respects alternate $VCSH_REPO_D' \ 'mkdir -p repod1 repod2 && @@ -68,8 +68,9 @@ test_expect_success '$XDG_CONFIG_HOME overrides $HOME for init' \ # Too internal to implementation? If another command verifies # vcsh.vcsh, use that instead of git config. test_expect_success 'Init command marks repository with vcsh.vcsh=true' \ - 'output=$($VCSH run foo git config vcsh.vcsh) && - assert "$output" = "true"' + 'echo true >expected && + $VCSH run foo git config vcsh.vcsh >output && + test_cmp expected output' test_expect_success 'Init command adds matching gitignore.d files' \ 'mkdir -p .gitattributes.d .gitignore.d && diff --git a/t/init2.sh b/t/init2.sh index d23007ac..7c33004c 100755 --- a/t/init2.sh +++ b/t/init2.sh @@ -6,14 +6,13 @@ test_description='Init command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Init command creates new Git repository' \ - 'output=$(num_gitrepos "$PWD") && - assert "$output" = "0" && + 'find_gitrepos "$PWD" >output && + test_must_be_empty output && - for i in $(seq 5) - do + for i in $(test_seq 5); do $VCSH init "test$i" && - output=$(num_gitrepos "$PWD") && - assert "$output" = "$i" + find_gitrepos "$PWD" >output && + test_line_count = "$i" output done' test_done diff --git a/t/test-lib.sh b/t/test-lib.sh index 77211c0d..271e0913 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -44,7 +44,7 @@ then exit 1 fi -export PERL_PATH=perl SHELL_PATH=sh +export PERL_PATH=perl SHELL_PATH=sh DIFF=diff # if --tee was passed, write the output not only to the terminal, but # additionally to the file test-results/$BASENAME.out, too. From dd5d302b09661ee40efdebb69f295b3435efbf26 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 6 May 2017 23:45:38 -0500 Subject: [PATCH 054/151] use test_env where needed --- t/init.sh | 40 ++++++++++++++++++++-------------------- t/init3.sh | 6 +++--- t/init4.sh | 2 +- t/init5.sh | 2 +- t/init6.sh | 2 +- t/init7.sh | 2 +- t/init8.sh | 2 +- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/t/init.sh b/t/init.sh index dd14c988..4b2528b7 100755 --- a/t/init.sh +++ b/t/init.sh @@ -29,41 +29,41 @@ test_expect_success 'Init creates repositories with same toplevel' \ test_expect_success 'Init command respects alternate $VCSH_REPO_D' \ 'mkdir -p repod1 repod2 && - VCSH_REPO_D="$PWD/repod1" $VCSH init alt-repo && - VCSH_REPO_D="$PWD/repod2" $VCSH init alt-repo' + test_env VCSH_REPO_D="$PWD/repod1" $VCSH init alt-repo && + test_env VCSH_REPO_D="$PWD/repod2" $VCSH init alt-repo' test_expect_success 'Init command respects alternate $XDG_CONFIG_HOME' \ 'mkdir -p xdg1 xdg2 && - XDG_CONFIG_HOME="$PWD/xdg1" $VCSH init alt-xdg && - XDG_CONFIG_HOME="$PWD/xdg2" $VCSH init alt-xdg' + test_env XDG_CONFIG_HOME="$PWD/xdg1" $VCSH init alt-xdg && + test_env XDG_CONFIG_HOME="$PWD/xdg2" $VCSH init alt-xdg' test_expect_success 'Init command respects alternate $HOME' \ 'mkdir -p home1 home2 && - HOME="$PWD/home1" $VCSH init alt-home && - HOME="$PWD/home2" $VCSH init alt-home' + test_env HOME="$PWD/home1" $VCSH init alt-home && + test_env HOME="$PWD/home2" $VCSH init alt-home' test_expect_success 'Init command fails if directories cannot be created' \ 'mkdir ro && chmod a-w ro && - HOME="$PWD/ro" test_must_fail $VCSH init foo' + test_env HOME="$PWD/ro" test_must_fail $VCSH init foo' test_expect_success '$VCSH_REPO_D overrides $XDG_CONFIG_HOME and $HOME for init' \ 'mkdir -p foo4 bar4 foo4a bar4a over4a over4b && - HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4a" $VCSH init samename && - HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename && - HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename && - HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename && - HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4b" $VCSH init samename && - HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename && - HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename && - HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename' + test_env HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4a" $VCSH init samename && + test_env HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename && + test_env HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename && + test_env HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename && + test_env HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4b" $VCSH init samename && + test_env HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename && + test_env HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename && + test_env HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename' test_expect_success '$XDG_CONFIG_HOME overrides $HOME for init' \ 'mkdir -p foo5 bar5 over5a over5b && - HOME="$PWD/foo5" XDG_CONFIG_HOME="$PWD/over5a" $VCSH init samename && - HOME="$PWD/bar5" XDG_CONFIG_HOME="$PWD/over5a" test_must_fail $VCSH init samename && - HOME="$PWD/foo5" XDG_CONFIG_HOME="$PWD/over5b" $VCSH init samename && - HOME="$PWD/bar5" XDG_CONFIG_HOME="$PWD/over5b" test_must_fail $VCSH init samename' + test_env HOME="$PWD/foo5" XDG_CONFIG_HOME="$PWD/over5a" $VCSH init samename && + test_env HOME="$PWD/bar5" XDG_CONFIG_HOME="$PWD/over5a" test_must_fail $VCSH init samename && + test_env HOME="$PWD/foo5" XDG_CONFIG_HOME="$PWD/over5b" $VCSH init samename && + test_env HOME="$PWD/bar5" XDG_CONFIG_HOME="$PWD/over5b" test_must_fail $VCSH init samename' # Too internal to implementation? If another command verifies # vcsh.vcsh, use that instead of git config. @@ -76,7 +76,7 @@ test_expect_success 'Init command adds matching gitignore.d files' \ 'mkdir -p .gitattributes.d .gitignore.d && touch .gitattributes.d/test1 .gitignore.d/test1 && - VCSH_GITIGNORE=exact $VCSH init test1 && + test_env VCSH_GITIGNORE=exact $VCSH init test1 && $VCSH status test1 | assert_grep -Fx "A .gitignore.d/test1"' test_done diff --git a/t/init3.sh b/t/init3.sh index ccdb9882..7a949dbb 100755 --- a/t/init3.sh +++ b/t/init3.sh @@ -6,8 +6,8 @@ test_description='Init command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'VCSH_GITIGNORE variable is validated' \ - 'VCSH_GITIGNORE=x test_must_fail $VCSH init foo && - VCSH_GITIGNORE=nonsense test_must_fail $VCSH init foo && - VCSH_GITIGNORE=fhqwhgads test_must_fail $VCSH init foo' + 'test_env VCSH_GITIGNORE=x test_must_fail $VCSH init foo && + test_env VCSH_GITIGNORE=nonsense test_must_fail $VCSH init foo && + test_env VCSH_GITIGNORE=fhqwhgads test_must_fail $VCSH init foo' test_done diff --git a/t/init4.sh b/t/init4.sh index 63afc9f2..ca025091 100755 --- a/t/init4.sh +++ b/t/init4.sh @@ -8,7 +8,7 @@ test_description='Init command' # XXX test instead by making sure files are actually excluded, not by # reading config option test_expect_success 'Init command sets core.excludesfile with VCSH_GITIGNORE=exact' \ - 'VCSH_GITIGNORE=exact $VCSH init test1 && + 'test_env VCSH_GITIGNORE=exact $VCSH init test1 && $VCSH run test1 git config core.excludesfile' test_done diff --git a/t/init5.sh b/t/init5.sh index 13390d68..977c6bd0 100755 --- a/t/init5.sh +++ b/t/init5.sh @@ -8,7 +8,7 @@ test_description='Init command' # XXX test instead by making sure files are actually excluded, not by # reading config option test_expect_success 'Init command sets core.excludesfile with VCSH_GITIGNORE=recursive' \ - 'VCSH_GITIGNORE=recursive $VCSH init test1 && + 'test_env VCSH_GITIGNORE=recursive $VCSH init test1 && $VCSH run test1 git config core.excludesfile' test_done diff --git a/t/init6.sh b/t/init6.sh index 69636ade..857d5286 100755 --- a/t/init6.sh +++ b/t/init6.sh @@ -6,7 +6,7 @@ test_description='Init command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Init command does not set core.excludesfile with VCSH_GITIGNORE=none' \ - 'VCSH_GITIGNORE=none $VCSH init test1 && + 'test_env VCSH_GITIGNORE=none $VCSH init test1 && test_must_fail $VCSH run test1 git config core.excludesfile' test_done diff --git a/t/init7.sh b/t/init7.sh index 6ef097b7..000102dd 100755 --- a/t/init7.sh +++ b/t/init7.sh @@ -6,7 +6,7 @@ test_description='Init command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Init command sets core.attributesfile with VCSH_GITATTRIBUTES!=none' \ - 'VCSH_GITATTRIBUTES=whatever $VCSH init test1 && + 'test_env VCSH_GITATTRIBUTES=whatever $VCSH init test1 && $VCSH run test1 git config core.attributesfile' test_done diff --git a/t/init8.sh b/t/init8.sh index a70e9373..663f1c71 100755 --- a/t/init8.sh +++ b/t/init8.sh @@ -6,7 +6,7 @@ test_description='Init command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Init command does not set core.attributesfile with VCSH_GITATTRIBUTES=none' \ - 'VCSH_GITATTRIBUTES=none $VCSH init test1 && + 'test_env VCSH_GITATTRIBUTES=none $VCSH init test1 && test_must_fail $VCSH run test1 git config core.attributesfile' test_done From 01d1e9f3ee4d65ec3d5516cb79a431bc73b6f93b Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 6 May 2017 23:46:41 -0500 Subject: [PATCH 055/151] start converting delete tests --- t/delete1.sh | 11 +++++++++++ t/delete2.sh | 11 +++++++++++ t/delete3.sh | 24 ++++++++++++++++++++++++ t/delete4.sh | 17 +++++++++++++++++ t/delete5.sh | 15 +++++++++++++++ 5 files changed, 78 insertions(+) create mode 100755 t/delete1.sh create mode 100755 t/delete2.sh create mode 100755 t/delete3.sh create mode 100755 t/delete4.sh create mode 100755 t/delete5.sh diff --git a/t/delete1.sh b/t/delete1.sh new file mode 100755 index 00000000..b5a42047 --- /dev/null +++ b/t/delete1.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +test_description='Delete command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Delete requires repo name' \ + 'test_must_fail $VCSH delete' + +test_done diff --git a/t/delete2.sh b/t/delete2.sh new file mode 100755 index 00000000..ebe1a000 --- /dev/null +++ b/t/delete2.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +test_description='Delete command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Repository to be deleted must exist' \ + 'test_must_fail $VCSH delete foo' + +test_done diff --git a/t/delete3.sh b/t/delete3.sh new file mode 100755 index 00000000..d5bc1079 --- /dev/null +++ b/t/delete3.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +test_description='Delete command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Delete requires confirmation' \ + '$VCSH init foo && + echo foo >expected && + + test_must_fail $VCSH delete foo < /dev/null && + $VCSH list >output && + test_cmp expected output && + + echo | test_must_fail $VCSH delete foo && + $VCSH list >output && + test_cmp expected output && + + echo no | test_must_fail $VCSH delete foo && + $VCSH list >output && + test_cmp expected output' + +test_done diff --git a/t/delete4.sh b/t/delete4.sh new file mode 100755 index 00000000..0bbd3a2a --- /dev/null +++ b/t/delete4.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +test_description='Delete command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Deleted repository removed from list' \ + '$VCSH init foo && + $VCSH init bar && + doit | $VCSH delete foo && + + $VCSH list >output && + echo bar >expected && + test_cmp expected output' + +test_done diff --git a/t/delete5.sh b/t/delete5.sh new file mode 100755 index 00000000..8dc595b8 --- /dev/null +++ b/t/delete5.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +test_description='Delete command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Deleted repository not in status' \ + '$VCSH init foo && + doit | $VCSH delete foo && + + $VCSH status >output && + test_line_count = 0 output' + +test_done From 3f0de0fde34ea377f541f436ef1ed2fc5ca7b557 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 8 May 2017 23:18:59 -0500 Subject: [PATCH 056/151] finish converting delete tests --- t/delete.t | 161 --------------------------------------------- t/delete10.sh | 19 ++++++ t/delete11.sh | 24 +++++++ t/delete12.sh | 19 ++++++ t/delete13.sh | 26 ++++++++ t/delete6.sh | 14 ++++ t/delete7.sh | 15 +++++ t/delete8.sh | 18 +++++ t/delete9.sh | 30 +++++++++ t/environment.bash | 5 ++ 10 files changed, 170 insertions(+), 161 deletions(-) delete mode 100755 t/delete.t create mode 100755 t/delete10.sh create mode 100755 t/delete11.sh create mode 100755 t/delete12.sh create mode 100755 t/delete13.sh create mode 100755 t/delete6.sh create mode 100755 t/delete7.sh create mode 100755 t/delete8.sh create mode 100755 t/delete9.sh diff --git a/t/delete.t b/t/delete.t deleted file mode 100755 index c111d673..00000000 --- a/t/delete.t +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/env bats - -load environment - -doit() { - echo "Yes, do as I say" -} - -@test "Delete requires repo name" { - ! $VCSH delete || false -} - -@test "Repository to be deleted must exist" { - ! $VCSH delete foo || false -} - -@test "Delete requires confirmation" { - $VCSH init foo - - ! $VCSH delete foo < /dev/null || false - run $VCSH list - assert "$status" -eq 0 - assert "$output" = "foo" - - ! echo | $VCSH delete foo || false - run $VCSH list - assert "$status" -eq 0 - assert "$output" = "foo" - - ! echo no | $VCSH delete foo || false - run $VCSH list - assert "$status" -eq 0 - assert "$output" = "foo" -} - -@test "Deleted repository removed from list" { - $VCSH init foo - $VCSH init bar - doit | $VCSH delete foo - - run $VCSH list - assert "$status" -eq 0 - assert "$output" = "bar" -} - -@test "Deleted repository not in status" { - $VCSH init foo - doit | $VCSH delete foo - - run $VCSH status - assert "$status" -eq 0 - assert "$output" = "" -} - -@test "Deleted repository cannot be subsequently used" { - $VCSH init foo - doit | $VCSH delete foo - - run $VCSH run foo echo fail - assert "$status" -ne 0 - assert "$output" != "fail" -} - -@test "Delete lists staged files before confirmation" { - $VCSH init foo - touch randomtexttofind - $VCSH foo add randomtexttofind - - : | $VCSH delete foo | assert_grep -F randomtexttofind -} - -@test "Delete lists committed files before confirmation" { - $VCSH init foo - touch randomtexttofind - $VCSH foo add randomtexttofind - $VCSH foo commit -m 'a' - - : | $VCSH delete foo | assert_grep -F randomtexttofind -} - -@test "Delete lists files staged for removal before confirmation" { - skip "do we want this?" - - $VCSH init foo - touch randomtexttofind - $VCSH foo add randomtexttofind - $VCSH foo commit -m 'a' - $VCSH foo rm --cached randomtexttofind - - : | $VCSH delete foo | assert_grep -F randomtexttofind -} - -@test "Delete removes corresponding files" { - $VCSH init foo - $VCSH init bar - - touch a b c d e - $VCSH foo add b e - $VCSH foo commit -m 'b e' - $VCSH bar add a c - $VCSH bar commit -m 'a c' - - doit | $VCSH delete foo - assert_file ! -e b - assert_file ! -e e - assert_file -e a - assert_file -e c - assert_file -e d - - doit | $VCSH delete bar - assert_file ! -e a - assert_file ! -e c - assert_file -e d -} - -@test "Delete handles filenames with spaces properly" { - skip "BUG" - - $VCSH init foo - touch a b 'a b' - $VCSH foo add 'a b' - $VCSH foo commit -m 'a b' - - doit | $VCSH delete foo - assert_file ! -e 'a b' - assert_file -e a - assert_file -e b -} - -@test "Delete handles filenames with wildcard characters properly" { - skip "BUG" - - $VCSH init foo - touch a b '?' - $VCSH foo add '\?' - $VCSH foo commit -m '?' - - doit | $VCSH delete foo - assert_file ! -e '?' - assert_file -e a - assert_file -e b -} - -@test "Delete can be abbreviated (delet, dele, del, de)" { - $VCSH init a - $VCSH init b - $VCSH init c - $VCSH init d - - doit | $VCSH delet a - ! $VCSH list | assert_grep -Fx a || false - - doit | $VCSH dele b - ! $VCSH list | assert_grep -Fx b || false - - doit | $VCSH del c - ! $VCSH list | assert_grep -Fx c || false - - doit | $VCSH de d - ! $VCSH list | assert_grep -Fx d || false -} diff --git a/t/delete10.sh b/t/delete10.sh new file mode 100755 index 00000000..8238aaa2 --- /dev/null +++ b/t/delete10.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +test_description='Delete command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_failure 'Delete handles filenames with spaces properly' \ + '$VCSH init foo && + touch a b "a b" && + $VCSH foo add "a b" && + $VCSH foo commit -m "a b" && + + doit | $VCSH delete foo && + test_path_is_missing "a b" && + test_path_is_file a && + test_path_is_file b' + +test_done diff --git a/t/delete11.sh b/t/delete11.sh new file mode 100755 index 00000000..d5bc1079 --- /dev/null +++ b/t/delete11.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +test_description='Delete command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Delete requires confirmation' \ + '$VCSH init foo && + echo foo >expected && + + test_must_fail $VCSH delete foo < /dev/null && + $VCSH list >output && + test_cmp expected output && + + echo | test_must_fail $VCSH delete foo && + $VCSH list >output && + test_cmp expected output && + + echo no | test_must_fail $VCSH delete foo && + $VCSH list >output && + test_cmp expected output' + +test_done diff --git a/t/delete12.sh b/t/delete12.sh new file mode 100755 index 00000000..c4b392b3 --- /dev/null +++ b/t/delete12.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +test_description='Delete command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_failure 'Delete handles filenames with wildcard characters properly' \ + '$VCSH init foo && + touch a b "?" && + $VCSH foo add '\''\?'\'' && + $VCSH foo commit -m "?" && + + doit | $VCSH delete foo && + test_path_is_missing "?" && + test_path_is_file a && + test_path_is_file b' + +test_done diff --git a/t/delete13.sh b/t/delete13.sh new file mode 100755 index 00000000..a64a36d7 --- /dev/null +++ b/t/delete13.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +test_description='Delete command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Delete can be abbreviated (delet, dele, del, de)' \ + '$VCSH init a && + $VCSH init b && + $VCSH init c && + $VCSH init d && + + doit | $VCSH delet a && + ! $VCSH list | assert_grep -Fx a && + + doit | $VCSH dele b && + ! $VCSH list | assert_grep -Fx b && + + doit | $VCSH del c && + ! $VCSH list | assert_grep -Fx c && + + doit | $VCSH de d && + ! $VCSH list | assert_grep -Fx d' + +test_done diff --git a/t/delete6.sh b/t/delete6.sh new file mode 100755 index 00000000..c3c13c7f --- /dev/null +++ b/t/delete6.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +test_description='Delete command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Deleted repository cannot be subsequently used' \ + '$VCSH init foo && + doit | $VCSH delete foo && + + test_must_fail $VCSH run foo echo fail' + +test_done diff --git a/t/delete7.sh b/t/delete7.sh new file mode 100755 index 00000000..ada41313 --- /dev/null +++ b/t/delete7.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +test_description='Delete command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Delete lists staged files before confirmation' \ + '$VCSH init foo && + touch randomtexttofind && + $VCSH foo add randomtexttofind && + + : | $VCSH delete foo | assert_grep -F randomtexttofind' + +test_done diff --git a/t/delete8.sh b/t/delete8.sh new file mode 100755 index 00000000..7e680474 --- /dev/null +++ b/t/delete8.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +test_description='Delete command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +# Do we actually want this? +test_expect_failure 'Delete lists files staged for removal before confirmation' \ + '$VCSH init foo && + touch randomtexttofind && + $VCSH foo add randomtexttofind && + $VCSH foo commit -m 'a' && + $VCSH foo rm --cached randomtexttofind && + + : | $VCSH delete foo | assert_grep -F randomtexttofind' + +test_done diff --git a/t/delete9.sh b/t/delete9.sh new file mode 100755 index 00000000..d93739ba --- /dev/null +++ b/t/delete9.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +test_description='Delete command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Delete removes corresponding files' \ + '$VCSH init foo && + $VCSH init bar && + + touch a b c d e && + $VCSH foo add b e && + $VCSH foo commit -m "b e" && + $VCSH bar add a c && + $VCSH bar commit -m "a c" && + + doit | $VCSH delete foo && + test_path_is_missing b && + test_path_is_missing e && + test_path_is_file a && + test_path_is_file c && + test_path_is_file d && + + doit | $VCSH delete bar && + test_path_is_missing a && + test_path_is_missing c && + test_path_is_file d' + +test_done diff --git a/t/environment.bash b/t/environment.bash index ab2dd5f3..eddf6852 100644 --- a/t/environment.bash +++ b/t/environment.bash @@ -72,3 +72,8 @@ assert_file() { assert_grep() { tee /dev/stderr | grep "$@" > /dev/null } + +# For delete testing +doit() { + echo "Yes, do as I say" +} From cd93c5e073e1f88d9e3e012ecdac8bc76f33551f Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 8 May 2017 23:40:22 -0500 Subject: [PATCH 057/151] convert list tests --- t/list.t | 98 ----------------------------------------------------- t/list1.sh | 12 +++++++ t/list10.sh | 20 +++++++++++ t/list2.sh | 14 ++++++++ t/list3.sh | 14 ++++++++ t/list4.sh | 18 ++++++++++ t/list5.sh | 20 +++++++++++ t/list6.sh | 20 +++++++++++ t/list7.sh | 16 +++++++++ t/list8.sh | 16 +++++++++ t/list9.sh | 16 +++++++++ 11 files changed, 166 insertions(+), 98 deletions(-) delete mode 100755 t/list.t create mode 100755 t/list1.sh create mode 100755 t/list10.sh create mode 100755 t/list2.sh create mode 100755 t/list3.sh create mode 100755 t/list4.sh create mode 100755 t/list5.sh create mode 100755 t/list6.sh create mode 100755 t/list7.sh create mode 100755 t/list8.sh create mode 100755 t/list9.sh diff --git a/t/list.t b/t/list.t deleted file mode 100755 index 711b500b..00000000 --- a/t/list.t +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env bats - -load environment - -@test "List command correct for no repositories" { - run $VCSH list - assert "$status" -eq 0 - assert "$output" = '' -} - -@test "List command displays inited repository" { - $VCSH init test1 - run $VCSH list - assert "$status" -eq 0 - assert "$output" = 'test1' -} - -@test "List command displays cloned repository" { - $VCSH clone "$TESTREPO" test1 - run $VCSH list - assert "$status" -eq 0 - assert "$output" = 'test1' -} - -@test "List command displays multiple repositories" { - $VCSH init foo - $VCSH init bar - $VCSH init baz - run $VCSH list - assert "$status" -eq 0 - assert "$output" = $'bar\nbaz\nfoo' -} - -@test "List command respects \$VCSH_REPO_D" { - VCSH_REPO_D="$PWD/foo" $VCSH init test1 - VCSH_REPO_D="$PWD/bar" $VCSH init test2 - - VCSH_REPO_D="$PWD/foo" run $VCSH list - assert "$status" -eq 0 - assert "$output" = 'test1' - - VCSH_REPO_D="$PWD/bar" run $VCSH list - assert "$status" -eq 0 - assert "$output" = 'test2' -} - -@test "List command respects \$XDG_CONFIG_HOME" { - XDG_CONFIG_HOME="$PWD/foo" $VCSH init test1 - XDG_CONFIG_HOME="$PWD/bar" $VCSH init test2 - - XDG_CONFIG_HOME="$PWD/foo" run $VCSH list - assert "$status" -eq 0 - assert "$output" = 'test1' - - XDG_CONFIG_HOME="$PWD/bar" run $VCSH list - assert "$status" -eq 0 - assert "$output" = 'test2' -} - -@test "List command respects \$HOME" { - HOME="$PWD/foo" $VCSH init test1 - HOME="$PWD/bar" $VCSH init test2 - - HOME="$PWD/foo" run $VCSH list - assert "$status" -eq 0 - assert "$output" = 'test1' - - HOME="$PWD/bar" run $VCSH list - assert "$status" -eq 0 - assert "$output" = 'test2' -} - -@test "List command prioritizes \$XDG_CONFIG_HOME over \$HOME" { - HOME="$PWD/foo" $VCSH init correct - HOME="$PWD/bar" $VCSH init wrong - - HOME="$PWD/bar" XDG_CONFIG_HOME="$PWD/foo/.config" run $VCSH list - assert "$status" -eq 0 - assert "$output" = 'correct' -} - -@test "List command prioritizes \$VCSH_REPO_D over \$HOME" { - HOME="$PWD/foo" $VCSH init correct - HOME="$PWD/bar" $VCSH init wrong - - HOME="$PWD/bar" VCSH_REPO_D="$PWD/foo/.config/vcsh/repo.d" run $VCSH list - assert "$status" -eq 0 - assert "$output" = 'correct' -} - -@test "List command prioritizes \$VCSH_REPO_D over \$XDG_CONFIG_HOME" { - XDG_CONFIG_HOME="$PWD/foo" $VCSH init correct - XDG_CONFIG_HOME="$PWD/bar" $VCSH init wrong - - XDG_CONFIG_HOME="$PWD/bar" VCSH_REPO_D="$PWD/foo/vcsh/repo.d" run $VCSH list - assert "$status" -eq 0 - assert "$output" = 'correct' -} diff --git a/t/list1.sh b/t/list1.sh new file mode 100755 index 00000000..1825a3a1 --- /dev/null +++ b/t/list1.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='List command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'List command correct for no repositories' \ + '$VCSH list >output && + test_must_be_empty output' + +test_done diff --git a/t/list10.sh b/t/list10.sh new file mode 100755 index 00000000..1da608cc --- /dev/null +++ b/t/list10.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='List command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'List command respects $VCSH_REPO_D' \ + 'test_env VCSH_REPO_D="$PWD/foo" $VCSH init test1 && + test_env VCSH_REPO_D="$PWD/bar" $VCSH init test2 && + + echo test1 >expected && + test_env VCSH_REPO_D="$PWD/foo" $VCSH list >output && + test_cmp expected output && + + echo test2 >expected && + test_env VCSH_REPO_D="$PWD/bar" $VCSH list >output && + test_cmp expected output' + +test_done diff --git a/t/list2.sh b/t/list2.sh new file mode 100755 index 00000000..43a6ab54 --- /dev/null +++ b/t/list2.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +test_description='List command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'List command displays inited repository' \ + '$VCSH init test1 && + echo test1 >expected && + $VCSH list >output && + test_cmp expected output' + +test_done diff --git a/t/list3.sh b/t/list3.sh new file mode 100755 index 00000000..e4fac9c2 --- /dev/null +++ b/t/list3.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +test_description='List command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'List command displays cloned repository' \ + '$VCSH clone "$TESTREPO" test2 && + echo test2 >expected && + $VCSH list >output && + test_cmp expected output' + +test_done diff --git a/t/list4.sh b/t/list4.sh new file mode 100755 index 00000000..69b4e5a4 --- /dev/null +++ b/t/list4.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +test_description='List command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'List command displays multiple repositories' \ + '$VCSH init foo && + $VCSH init bar && + $VCSH init baz && + echo bar >expected && + echo baz >>expected && + echo foo >>expected && + $VCSH list >output && + test_cmp expected output' + +test_done diff --git a/t/list5.sh b/t/list5.sh new file mode 100755 index 00000000..ea94c659 --- /dev/null +++ b/t/list5.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='List command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'List command respects $XDG_CONFIG_HOME' \ + 'test_env XDG_CONFIG_HOME="$PWD/foo" $VCSH init test1 && + test_env XDG_CONFIG_HOME="$PWD/bar" $VCSH init test2 && + + echo test1 >expected && + test_env XDG_CONFIG_HOME="$PWD/foo" $VCSH list >output && + test_cmp expected output && + + echo test2 >expected && + test_env XDG_CONFIG_HOME="$PWD/bar" $VCSH list >output && + test_cmp expected output' + +test_done diff --git a/t/list6.sh b/t/list6.sh new file mode 100755 index 00000000..9e8b6b89 --- /dev/null +++ b/t/list6.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='List command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'List command respects $HOME' \ + 'test_env HOME="$PWD/foo" $VCSH init test1 && + test_env HOME="$PWD/bar" $VCSH init test2 && + + echo test1 >expected && + test_env HOME="$PWD/foo" $VCSH list >output && + test_cmp expected output && + + echo test2 >expected && + test_env HOME="$PWD/bar" $VCSH list >output && + test_cmp expected output' + +test_done diff --git a/t/list7.sh b/t/list7.sh new file mode 100755 index 00000000..f0b2a894 --- /dev/null +++ b/t/list7.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='List command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'List command prioritizes $XDG_CONFIG_HOME over $HOME' \ + 'test_env HOME="$PWD/foo" $VCSH init correct && + test_env HOME="$PWD/bar" $VCSH init wrong && + + echo correct >expected && + test_env HOME="$PWD/bar" XDG_CONFIG_HOME="$PWD/foo/.config" $VCSH list >output && + test_cmp expected output' + +test_done diff --git a/t/list8.sh b/t/list8.sh new file mode 100755 index 00000000..429112d1 --- /dev/null +++ b/t/list8.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='List command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'List command prioritizes $VCSH_REPO_D over $HOME' \ + 'test_env HOME="$PWD/foo" $VCSH init correct && + test_env HOME="$PWD/bar" $VCSH init wrong && + + echo correct >expected && + test_env HOME="$PWD/bar" VCSH_REPO_D="$PWD/foo/.config/vcsh/repo.d" $VCSH list >output && + test_cmp expected output' + +test_done diff --git a/t/list9.sh b/t/list9.sh new file mode 100755 index 00000000..751caac9 --- /dev/null +++ b/t/list9.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='List command' + +. test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'List command prioritizes \$VCSH_REPO_D over \$XDG_CONFIG_HOME' \ + 'test_env XDG_CONFIG_HOME="$PWD/foo" $VCSH init correct && + test_env XDG_CONFIG_HOME="$PWD/bar" $VCSH init wrong && + + echo correct >expected && + test_env XDG_CONFIG_HOME="$PWD/bar" VCSH_REPO_D="$PWD/foo/vcsh/repo.d" $VCSH list >output && + test_cmp expected output' + +test_done From 23fdc17121944396522b959aa63e8bff7dfbc365 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 8 May 2017 23:55:34 -0500 Subject: [PATCH 058/151] back to *.t to distinguish from test-lib.sh --- Makefile | 8 +------- t/Makefile | 6 ++++++ t/{clone1.sh => clone1.t} | 2 +- t/{clone10.sh => clone10.t} | 2 +- t/{clone11.sh => clone11.t} | 2 +- t/{clone2.sh => clone2.t} | 2 +- t/{clone3.sh => clone3.t} | 2 +- t/{clone4.sh => clone4.t} | 2 +- t/{clone5.sh => clone5.t} | 2 +- t/{clone6.sh => clone6.t} | 2 +- t/{clone7.sh => clone7.t} | 2 +- t/{clone8.sh => clone8.t} | 2 +- t/{clone9.sh => clone9.t} | 2 +- t/{delete1.sh => delete1.t} | 2 +- t/{delete10.sh => delete10.t} | 2 +- t/{delete3.sh => delete11.t} | 2 +- t/{delete12.sh => delete12.t} | 2 +- t/{delete13.sh => delete13.t} | 2 +- t/{delete2.sh => delete2.t} | 2 +- t/{delete11.sh => delete3.t} | 2 +- t/{delete4.sh => delete4.t} | 2 +- t/{delete5.sh => delete5.t} | 2 +- t/{delete6.sh => delete6.t} | 2 +- t/{delete7.sh => delete7.t} | 2 +- t/{delete8.sh => delete8.t} | 2 +- t/{delete9.sh => delete9.t} | 2 +- t/{help.sh => help.t} | 2 +- t/{init-umask.sh => init-umask.t} | 2 +- t/{init.sh => init.t} | 2 +- t/{init2.sh => init2.t} | 2 +- t/{init3.sh => init3.t} | 2 +- t/{init4.sh => init4.t} | 2 +- t/{init5.sh => init5.t} | 2 +- t/{init6.sh => init6.t} | 2 +- t/{init7.sh => init7.t} | 2 +- t/{init8.sh => init8.t} | 2 +- t/{list1.sh => list1.t} | 2 +- t/{list10.sh => list10.t} | 2 +- t/{list2.sh => list2.t} | 2 +- t/{list3.sh => list3.t} | 2 +- t/{list4.sh => list4.t} | 2 +- t/{list5.sh => list5.t} | 2 +- t/{list6.sh => list6.t} | 2 +- t/{list7.sh => list7.t} | 2 +- t/{list8.sh => list8.t} | 2 +- t/{list9.sh => list9.t} | 2 +- 46 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 t/Makefile rename t/{clone1.sh => clone1.t} (91%) rename t/{clone10.sh => clone10.t} (94%) rename t/{clone11.sh => clone11.t} (96%) rename t/{clone2.sh => clone2.t} (94%) rename t/{clone3.sh => clone3.t} (94%) rename t/{clone4.sh => clone4.t} (95%) rename t/{clone5.sh => clone5.t} (95%) rename t/{clone6.sh => clone6.t} (95%) rename t/{clone7.sh => clone7.t} (95%) rename t/{clone8.sh => clone8.t} (95%) rename t/{clone9.sh => clone9.t} (95%) rename t/{delete1.sh => delete1.t} (91%) rename t/{delete10.sh => delete10.t} (95%) rename t/{delete3.sh => delete11.t} (96%) rename t/{delete12.sh => delete12.t} (95%) rename t/{delete13.sh => delete13.t} (96%) rename t/{delete2.sh => delete2.t} (92%) rename t/{delete11.sh => delete3.t} (96%) rename t/{delete4.sh => delete4.t} (94%) rename t/{delete5.sh => delete5.t} (94%) rename t/{delete6.sh => delete6.t} (94%) rename t/{delete7.sh => delete7.t} (95%) rename t/{delete8.sh => delete8.t} (96%) rename t/{delete9.sh => delete9.t} (97%) rename t/{help.sh => help.t} (98%) rename t/{init-umask.sh => init-umask.t} (95%) rename t/{init.sh => init.t} (99%) rename t/{init2.sh => init2.t} (95%) rename t/{init3.sh => init3.t} (95%) rename t/{init4.sh => init4.t} (95%) rename t/{init5.sh => init5.t} (95%) rename t/{init6.sh => init6.t} (94%) rename t/{init7.sh => init7.t} (94%) rename t/{init8.sh => init8.t} (95%) rename t/{list1.sh => list1.t} (92%) rename t/{list10.sh => list10.t} (96%) rename t/{list2.sh => list2.t} (94%) rename t/{list3.sh => list3.t} (94%) rename t/{list4.sh => list4.t} (95%) rename t/{list5.sh => list5.t} (96%) rename t/{list6.sh => list6.t} (96%) rename t/{list7.sh => list7.t} (96%) rename t/{list8.sh => list8.t} (96%) rename t/{list9.sh => list9.t} (96%) diff --git a/Makefile b/Makefile index dfeb17e4..d0057054 100644 --- a/Makefile +++ b/Makefile @@ -47,13 +47,7 @@ vcsh_testrepo.git: git clone --mirror https://github.com/djpohly/vcsh_testrepo.git test: | vcsh_testrepo.git - @if ! which git > /dev/null; then echo "'git' not found, exiting..." ; exit 1; fi - @if ! which prove > /dev/null; then echo "'prove' not found; not running tests"; exit 1; fi - @if ! which bats > /dev/null; then echo "'bats' not found; not running tests" ; exit 1; fi - TESTREPO=$(PWD)/vcsh_testrepo.git TESTREPONAME=vcsh_testrepo prove $(filter -j%,$(MAKEFLAGS)) --timer -e bats - -test-%: t/%.t | vcsh_testrepo.git - TESTREPO=$(PWD)/vcsh_testrepo.git TESTREPONAME=vcsh_testrepo bats $< + $(MAKE) -C t/ moo: @which cowsay >/dev/null 2>&1 && cowsay "I hope you're happy now..." diff --git a/t/Makefile b/t/Makefile new file mode 100644 index 00000000..3d9bbc1d --- /dev/null +++ b/t/Makefile @@ -0,0 +1,6 @@ +all: test + +test: + @if ! which git > /dev/null; then echo "'git' not found, exiting..." ; exit 1; fi + @if ! which prove > /dev/null; then echo "'prove' not found; not running tests"; exit 1; fi + TESTREPO=$(PWD)/../vcsh_testrepo.git TESTREPONAME=vcsh_testrepo prove $(filter -j%,$(MAKEFLAGS)) --timer *.t diff --git a/t/clone1.sh b/t/clone1.t similarity index 91% rename from t/clone1.sh rename to t/clone1.t index 5eee3daf..720b032f 100755 --- a/t/clone1.sh +++ b/t/clone1.t @@ -2,7 +2,7 @@ test_description='Clone command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone requires a remote' \ diff --git a/t/clone10.sh b/t/clone10.t similarity index 94% rename from t/clone10.sh rename to t/clone10.t index 496e70cc..c195696a 100755 --- a/t/clone10.sh +++ b/t/clone10.t @@ -2,7 +2,7 @@ test_description='Clone command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone -b option clones only one branch' \ diff --git a/t/clone11.sh b/t/clone11.t similarity index 96% rename from t/clone11.sh rename to t/clone11.t index 4719fbde..b40be922 100755 --- a/t/clone11.sh +++ b/t/clone11.t @@ -2,7 +2,7 @@ test_description='Clone command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone can be abbreviated (clon, clo, cl)' \ diff --git a/t/clone2.sh b/t/clone2.t similarity index 94% rename from t/clone2.sh rename to t/clone2.t index ccc42d81..1a492e69 100755 --- a/t/clone2.sh +++ b/t/clone2.t @@ -2,7 +2,7 @@ test_description='Clone command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone uses existing repo name by default' \ diff --git a/t/clone3.sh b/t/clone3.t similarity index 94% rename from t/clone3.sh rename to t/clone3.t index 9ed2173c..1144df14 100755 --- a/t/clone3.sh +++ b/t/clone3.t @@ -2,7 +2,7 @@ test_description='Clone command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone honors specified repo name' \ diff --git a/t/clone4.sh b/t/clone4.t similarity index 95% rename from t/clone4.sh rename to t/clone4.t index ec8d30a6..c887044c 100755 --- a/t/clone4.sh +++ b/t/clone4.t @@ -2,7 +2,7 @@ test_description='Clone command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone uses given remote HEAD by default' \ diff --git a/t/clone5.sh b/t/clone5.t similarity index 95% rename from t/clone5.sh rename to t/clone5.t index af5297c6..1f518648 100755 --- a/t/clone5.sh +++ b/t/clone5.t @@ -2,7 +2,7 @@ test_description='Clone command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone honors -b option before remote' \ diff --git a/t/clone6.sh b/t/clone6.t similarity index 95% rename from t/clone6.sh rename to t/clone6.t index 7649b11e..143c50ed 100755 --- a/t/clone6.sh +++ b/t/clone6.t @@ -2,7 +2,7 @@ test_description='Clone command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone honors -b option before remote and repo name' \ diff --git a/t/clone7.sh b/t/clone7.t similarity index 95% rename from t/clone7.sh rename to t/clone7.t index 352d4fa2..577a7bf0 100755 --- a/t/clone7.sh +++ b/t/clone7.t @@ -2,7 +2,7 @@ test_description='Clone command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone honors -b option after remote' \ diff --git a/t/clone8.sh b/t/clone8.t similarity index 95% rename from t/clone8.sh rename to t/clone8.t index 2bbfd6aa..9e8938ef 100755 --- a/t/clone8.sh +++ b/t/clone8.t @@ -2,7 +2,7 @@ test_description='Clone command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone honors -b option between remote and repo name' \ diff --git a/t/clone9.sh b/t/clone9.t similarity index 95% rename from t/clone9.sh rename to t/clone9.t index 7e3554b3..54095f52 100755 --- a/t/clone9.sh +++ b/t/clone9.t @@ -2,7 +2,7 @@ test_description='Clone command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone honors -b option after repo name' \ diff --git a/t/delete1.sh b/t/delete1.t similarity index 91% rename from t/delete1.sh rename to t/delete1.t index b5a42047..744dde8b 100755 --- a/t/delete1.sh +++ b/t/delete1.t @@ -2,7 +2,7 @@ test_description='Delete command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Delete requires repo name' \ diff --git a/t/delete10.sh b/t/delete10.t similarity index 95% rename from t/delete10.sh rename to t/delete10.t index 8238aaa2..69999cd5 100755 --- a/t/delete10.sh +++ b/t/delete10.t @@ -2,7 +2,7 @@ test_description='Delete command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_failure 'Delete handles filenames with spaces properly' \ diff --git a/t/delete3.sh b/t/delete11.t similarity index 96% rename from t/delete3.sh rename to t/delete11.t index d5bc1079..5c583b8b 100755 --- a/t/delete3.sh +++ b/t/delete11.t @@ -2,7 +2,7 @@ test_description='Delete command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Delete requires confirmation' \ diff --git a/t/delete12.sh b/t/delete12.t similarity index 95% rename from t/delete12.sh rename to t/delete12.t index c4b392b3..fb28d6f8 100755 --- a/t/delete12.sh +++ b/t/delete12.t @@ -2,7 +2,7 @@ test_description='Delete command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_failure 'Delete handles filenames with wildcard characters properly' \ diff --git a/t/delete13.sh b/t/delete13.t similarity index 96% rename from t/delete13.sh rename to t/delete13.t index a64a36d7..f1d16177 100755 --- a/t/delete13.sh +++ b/t/delete13.t @@ -2,7 +2,7 @@ test_description='Delete command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Delete can be abbreviated (delet, dele, del, de)' \ diff --git a/t/delete2.sh b/t/delete2.t similarity index 92% rename from t/delete2.sh rename to t/delete2.t index ebe1a000..3b53fc10 100755 --- a/t/delete2.sh +++ b/t/delete2.t @@ -2,7 +2,7 @@ test_description='Delete command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Repository to be deleted must exist' \ diff --git a/t/delete11.sh b/t/delete3.t similarity index 96% rename from t/delete11.sh rename to t/delete3.t index d5bc1079..5c583b8b 100755 --- a/t/delete11.sh +++ b/t/delete3.t @@ -2,7 +2,7 @@ test_description='Delete command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Delete requires confirmation' \ diff --git a/t/delete4.sh b/t/delete4.t similarity index 94% rename from t/delete4.sh rename to t/delete4.t index 0bbd3a2a..a5d39a97 100755 --- a/t/delete4.sh +++ b/t/delete4.t @@ -2,7 +2,7 @@ test_description='Delete command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Deleted repository removed from list' \ diff --git a/t/delete5.sh b/t/delete5.t similarity index 94% rename from t/delete5.sh rename to t/delete5.t index 8dc595b8..84178273 100755 --- a/t/delete5.sh +++ b/t/delete5.t @@ -2,7 +2,7 @@ test_description='Delete command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Deleted repository not in status' \ diff --git a/t/delete6.sh b/t/delete6.t similarity index 94% rename from t/delete6.sh rename to t/delete6.t index c3c13c7f..13f41f0e 100755 --- a/t/delete6.sh +++ b/t/delete6.t @@ -2,7 +2,7 @@ test_description='Delete command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Deleted repository cannot be subsequently used' \ diff --git a/t/delete7.sh b/t/delete7.t similarity index 95% rename from t/delete7.sh rename to t/delete7.t index ada41313..cca3cae9 100755 --- a/t/delete7.sh +++ b/t/delete7.t @@ -2,7 +2,7 @@ test_description='Delete command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Delete lists staged files before confirmation' \ diff --git a/t/delete8.sh b/t/delete8.t similarity index 96% rename from t/delete8.sh rename to t/delete8.t index 7e680474..77446c16 100755 --- a/t/delete8.sh +++ b/t/delete8.t @@ -2,7 +2,7 @@ test_description='Delete command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" # Do we actually want this? diff --git a/t/delete9.sh b/t/delete9.t similarity index 97% rename from t/delete9.sh rename to t/delete9.t index d93739ba..911b7b65 100755 --- a/t/delete9.sh +++ b/t/delete9.t @@ -2,7 +2,7 @@ test_description='Delete command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Delete removes corresponding files' \ diff --git a/t/help.sh b/t/help.t similarity index 98% rename from t/help.sh rename to t/help.t index 823b1fd5..86cc6264 100755 --- a/t/help.sh +++ b/t/help.t @@ -2,7 +2,7 @@ test_description='Help command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_failure 'Help command succeeds' \ diff --git a/t/init-umask.sh b/t/init-umask.t similarity index 95% rename from t/init-umask.sh rename to t/init-umask.t index f59ebd68..9c1d77ae 100755 --- a/t/init-umask.sh +++ b/t/init-umask.t @@ -2,7 +2,7 @@ test_description='Ensure init creates files with limited permissions' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" # verifies commit e220a61 diff --git a/t/init.sh b/t/init.t similarity index 99% rename from t/init.sh rename to t/init.t index 4b2528b7..ae825b27 100755 --- a/t/init.sh +++ b/t/init.t @@ -2,7 +2,7 @@ test_description='Init command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Init command succeeds' \ diff --git a/t/init2.sh b/t/init2.t similarity index 95% rename from t/init2.sh rename to t/init2.t index 7c33004c..5659556e 100755 --- a/t/init2.sh +++ b/t/init2.t @@ -2,7 +2,7 @@ test_description='Init command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Init command creates new Git repository' \ diff --git a/t/init3.sh b/t/init3.t similarity index 95% rename from t/init3.sh rename to t/init3.t index 7a949dbb..4f5141a3 100755 --- a/t/init3.sh +++ b/t/init3.t @@ -2,7 +2,7 @@ test_description='Init command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'VCSH_GITIGNORE variable is validated' \ diff --git a/t/init4.sh b/t/init4.t similarity index 95% rename from t/init4.sh rename to t/init4.t index ca025091..fffa0c5a 100755 --- a/t/init4.sh +++ b/t/init4.t @@ -2,7 +2,7 @@ test_description='Init command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" # XXX test instead by making sure files are actually excluded, not by diff --git a/t/init5.sh b/t/init5.t similarity index 95% rename from t/init5.sh rename to t/init5.t index 977c6bd0..e6865dc4 100755 --- a/t/init5.sh +++ b/t/init5.t @@ -2,7 +2,7 @@ test_description='Init command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" # XXX test instead by making sure files are actually excluded, not by diff --git a/t/init6.sh b/t/init6.t similarity index 94% rename from t/init6.sh rename to t/init6.t index 857d5286..5d35e581 100755 --- a/t/init6.sh +++ b/t/init6.t @@ -2,7 +2,7 @@ test_description='Init command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Init command does not set core.excludesfile with VCSH_GITIGNORE=none' \ diff --git a/t/init7.sh b/t/init7.t similarity index 94% rename from t/init7.sh rename to t/init7.t index 000102dd..797aa197 100755 --- a/t/init7.sh +++ b/t/init7.t @@ -2,7 +2,7 @@ test_description='Init command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Init command sets core.attributesfile with VCSH_GITATTRIBUTES!=none' \ diff --git a/t/init8.sh b/t/init8.t similarity index 95% rename from t/init8.sh rename to t/init8.t index 663f1c71..7127ae57 100755 --- a/t/init8.sh +++ b/t/init8.t @@ -2,7 +2,7 @@ test_description='Init command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Init command does not set core.attributesfile with VCSH_GITATTRIBUTES=none' \ diff --git a/t/list1.sh b/t/list1.t similarity index 92% rename from t/list1.sh rename to t/list1.t index 1825a3a1..6423d8c5 100755 --- a/t/list1.sh +++ b/t/list1.t @@ -2,7 +2,7 @@ test_description='List command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'List command correct for no repositories' \ diff --git a/t/list10.sh b/t/list10.t similarity index 96% rename from t/list10.sh rename to t/list10.t index 1da608cc..d20be3ca 100755 --- a/t/list10.sh +++ b/t/list10.t @@ -2,7 +2,7 @@ test_description='List command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'List command respects $VCSH_REPO_D' \ diff --git a/t/list2.sh b/t/list2.t similarity index 94% rename from t/list2.sh rename to t/list2.t index 43a6ab54..e5291d2a 100755 --- a/t/list2.sh +++ b/t/list2.t @@ -2,7 +2,7 @@ test_description='List command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'List command displays inited repository' \ diff --git a/t/list3.sh b/t/list3.t similarity index 94% rename from t/list3.sh rename to t/list3.t index e4fac9c2..b6ab1a06 100755 --- a/t/list3.sh +++ b/t/list3.t @@ -2,7 +2,7 @@ test_description='List command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'List command displays cloned repository' \ diff --git a/t/list4.sh b/t/list4.t similarity index 95% rename from t/list4.sh rename to t/list4.t index 69b4e5a4..3518124f 100755 --- a/t/list4.sh +++ b/t/list4.t @@ -2,7 +2,7 @@ test_description='List command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'List command displays multiple repositories' \ diff --git a/t/list5.sh b/t/list5.t similarity index 96% rename from t/list5.sh rename to t/list5.t index ea94c659..8073a3c4 100755 --- a/t/list5.sh +++ b/t/list5.t @@ -2,7 +2,7 @@ test_description='List command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'List command respects $XDG_CONFIG_HOME' \ diff --git a/t/list6.sh b/t/list6.t similarity index 96% rename from t/list6.sh rename to t/list6.t index 9e8b6b89..a89a1302 100755 --- a/t/list6.sh +++ b/t/list6.t @@ -2,7 +2,7 @@ test_description='List command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'List command respects $HOME' \ diff --git a/t/list7.sh b/t/list7.t similarity index 96% rename from t/list7.sh rename to t/list7.t index f0b2a894..11c89414 100755 --- a/t/list7.sh +++ b/t/list7.t @@ -2,7 +2,7 @@ test_description='List command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'List command prioritizes $XDG_CONFIG_HOME over $HOME' \ diff --git a/t/list8.sh b/t/list8.t similarity index 96% rename from t/list8.sh rename to t/list8.t index 429112d1..78ae5504 100755 --- a/t/list8.sh +++ b/t/list8.t @@ -2,7 +2,7 @@ test_description='List command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'List command prioritizes $VCSH_REPO_D over $HOME' \ diff --git a/t/list9.sh b/t/list9.t similarity index 96% rename from t/list9.sh rename to t/list9.t index 751caac9..7e8b0d90 100755 --- a/t/list9.sh +++ b/t/list9.t @@ -2,7 +2,7 @@ test_description='List command' -. test-lib.sh +. ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" test_expect_success 'List command prioritizes \$VCSH_REPO_D over \$XDG_CONFIG_HOME' \ From 648dc7f227f0cd784628796f16261238fa20f0b0 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 9 May 2017 13:04:13 -0500 Subject: [PATCH 059/151] move bats tests to *.bats --- t/{commit.t => commit.bats} | 0 t/{debug.t => debug.bats} | 0 t/{foreach.t => foreach.bats} | 0 t/{list-tracked.t => list-tracked.bats} | 0 t/{prove.t => prove.bats} | 0 t/{pull.t => pull.bats} | 0 t/{push.t => push.bats} | 0 t/{rename.t => rename.bats} | 0 t/{run-enter.t => run-enter.bats} | 0 t/{status.t => status.bats} | 0 t/{version.t => version.bats} | 0 t/{which.t => which.bats} | 0 12 files changed, 0 insertions(+), 0 deletions(-) rename t/{commit.t => commit.bats} (100%) rename t/{debug.t => debug.bats} (100%) rename t/{foreach.t => foreach.bats} (100%) rename t/{list-tracked.t => list-tracked.bats} (100%) rename t/{prove.t => prove.bats} (100%) rename t/{pull.t => pull.bats} (100%) rename t/{push.t => push.bats} (100%) rename t/{rename.t => rename.bats} (100%) rename t/{run-enter.t => run-enter.bats} (100%) rename t/{status.t => status.bats} (100%) rename t/{version.t => version.bats} (100%) rename t/{which.t => which.bats} (100%) diff --git a/t/commit.t b/t/commit.bats similarity index 100% rename from t/commit.t rename to t/commit.bats diff --git a/t/debug.t b/t/debug.bats similarity index 100% rename from t/debug.t rename to t/debug.bats diff --git a/t/foreach.t b/t/foreach.bats similarity index 100% rename from t/foreach.t rename to t/foreach.bats diff --git a/t/list-tracked.t b/t/list-tracked.bats similarity index 100% rename from t/list-tracked.t rename to t/list-tracked.bats diff --git a/t/prove.t b/t/prove.bats similarity index 100% rename from t/prove.t rename to t/prove.bats diff --git a/t/pull.t b/t/pull.bats similarity index 100% rename from t/pull.t rename to t/pull.bats diff --git a/t/push.t b/t/push.bats similarity index 100% rename from t/push.t rename to t/push.bats diff --git a/t/rename.t b/t/rename.bats similarity index 100% rename from t/rename.t rename to t/rename.bats diff --git a/t/run-enter.t b/t/run-enter.bats similarity index 100% rename from t/run-enter.t rename to t/run-enter.bats diff --git a/t/status.t b/t/status.bats similarity index 100% rename from t/status.t rename to t/status.bats diff --git a/t/version.t b/t/version.bats similarity index 100% rename from t/version.t rename to t/version.bats diff --git a/t/which.t b/t/which.bats similarity index 100% rename from t/which.t rename to t/which.bats From 3e720b7c23f2801185b936cb9056343658b9444e Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 9 May 2017 13:15:05 -0500 Subject: [PATCH 060/151] fix `make test' --- Makefile | 2 +- t/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d0057054..733704d6 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ vcsh_testrepo.git: git clone --mirror https://github.com/djpohly/vcsh_testrepo.git test: | vcsh_testrepo.git - $(MAKE) -C t/ + $(MAKE) -C t/ VCSH_TESTREPO="$(PWD)/vcsh_testrepo.git" VCSH_TESTREPONAME="vcsh_testrepo" moo: @which cowsay >/dev/null 2>&1 && cowsay "I hope you're happy now..." diff --git a/t/Makefile b/t/Makefile index 3d9bbc1d..178e521b 100644 --- a/t/Makefile +++ b/t/Makefile @@ -3,4 +3,4 @@ all: test test: @if ! which git > /dev/null; then echo "'git' not found, exiting..." ; exit 1; fi @if ! which prove > /dev/null; then echo "'prove' not found; not running tests"; exit 1; fi - TESTREPO=$(PWD)/../vcsh_testrepo.git TESTREPONAME=vcsh_testrepo prove $(filter -j%,$(MAKEFLAGS)) --timer *.t + prove $(filter -j%,$(MAKEFLAGS)) --timer *.t From 6feeb0b8262f1e9f71bff3cb6336a49761a1a795 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 9 May 2017 13:51:10 -0500 Subject: [PATCH 061/151] remove git-specific environment vars --- t/test-lib.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index 271e0913..8ae5c381 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -761,11 +761,7 @@ test_done () { GIT_EXEC_PATH=$(git --exec-path) || error "Cannot run git." PATH=$GIT_BUILD_DIR:$PATH - -GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt -GIT_CONFIG_NOSYSTEM=1 -GIT_ATTR_NOSYSTEM=1 -export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM +export PATH GIT_EXEC_PATH if test -z "$GIT_TEST_CMP" then From 1038fbb1f7e3ae7248290a99cb1dd30f07dad739 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 9 May 2017 13:59:06 -0500 Subject: [PATCH 062/151] fix trash directory names --- t/test-lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index 8ae5c381..2a50a33a 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -777,7 +777,7 @@ GITPERLLIB="$GIT_BUILD_DIR"/perl/blib/lib:"$GIT_BUILD_DIR"/perl/blib/arch/auto/G export GITPERLLIB # Test repository -TRASH_DIRECTORY="trash directory.$(basename "$0" .sh)" +TRASH_DIRECTORY="trash directory.$(basename "$0" .t)" test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY" case "$TRASH_DIRECTORY" in /*) ;; # absolute path is good From b200d0fb0c5b59797defcf7d1a5191bfd0c6a854 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 9 May 2017 13:27:48 -0500 Subject: [PATCH 063/151] exclude ./output from find in init-umask --- t/init-umask.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/init-umask.t b/t/init-umask.t index 9c1d77ae..5996e6c9 100755 --- a/t/init-umask.t +++ b/t/init-umask.t @@ -8,7 +8,7 @@ test_description='Ensure init creates files with limited permissions' # verifies commit e220a61 test_expect_success 'Files created by init are not readable by other users' \ '$VCSH init foo && - find "$HOME" -type f -perm /g+rwx,o+rwx >output && + find "$HOME" -type f -perm /g+rwx,o+rwx ! -path "$HOME/output" >output && test_must_be_empty output' test_done From 529f4915501286047afa2619421dfa7bfba653ec Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 9 May 2017 14:01:01 -0500 Subject: [PATCH 064/151] Makefile cleanup (phony, prereqs target) --- Makefile | 2 ++ t/Makefile | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 733704d6..dfcec01a 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,8 @@ DOCDIR=$(DOCDIR_PREFIX)/$(self) ZSHDIR=$(PREFIX)/share/zsh/vendor-completions RONN ?= ronn +.PHONY: all install manpages clean uninstall purge test moo + self=vcsh manpages=$(self).1 all=test manpages diff --git a/t/Makefile b/t/Makefile index 178e521b..cccf7c63 100644 --- a/t/Makefile +++ b/t/Makefile @@ -1,6 +1,10 @@ +.PHONY: all test test-prereq + all: test -test: +test-prereq: @if ! which git > /dev/null; then echo "'git' not found, exiting..." ; exit 1; fi @if ! which prove > /dev/null; then echo "'prove' not found; not running tests"; exit 1; fi + +test: test-prereq prove $(filter -j%,$(MAKEFLAGS)) --timer *.t From 3d71f4312d4ab1fd1eb4df28716638160176ccfe Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 9 May 2017 14:34:33 -0500 Subject: [PATCH 065/151] this branch no longer uses bats --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index c92ebc5d..cc818eda 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,6 @@ sudo: false language: bash -install: - - git clone --depth 1 https://github.com/sstephenson/bats - - bats/install.sh "$HOME/.local" before_script: - - export PATH="$HOME/.local/bin:$PATH" - echo '-v' > "$HOME/.proverc" script: - make test From bf658df3f40a979014c49d955968859e1a014844 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Wed, 10 May 2017 00:37:58 -0500 Subject: [PATCH 066/151] convert remaining old test --- t/prove.bats | 19 ------------------- t/prove.t | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 19 deletions(-) delete mode 100755 t/prove.bats create mode 100755 t/prove.t diff --git a/t/prove.bats b/t/prove.bats deleted file mode 100755 index 37bf954a..00000000 --- a/t/prove.bats +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bats - -load environment - -@test "300-add.t" { - $VCSH init test1 - $VCSH init test2 - - touch 'a' - $VCSH test2 add 'a' - - run $VCSH status - assert "$status" -eq 0 - assert "$output" = $'test1:\n\ntest2:\nA a' - - run $VCSH status --terse - assert "$status" -eq 0 - assert "$output" = $'test2:\nA a' -} diff --git a/t/prove.t b/t/prove.t new file mode 100755 index 00000000..51dc3d81 --- /dev/null +++ b/t/prove.t @@ -0,0 +1,28 @@ +#!/bin/bash + +test_description='Old tests' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success '300-add.t' \ + '$VCSH init test1 && + $VCSH init test2 && + + touch a && + $VCSH test2 add a && + + echo "test1:" >expected && + echo "" >>expected && + echo "test2:" >>expected && + echo "A a" >>expected && + echo "" >>expected && + $VCSH status >output && + test_cmp expected output && + + echo "test2:" >expected && + echo "A a" >>expected && + $VCSH status --terse >output && + test_cmp expected output' + +test_done From f5c5e6d7044b1135d9e0d116037f5391786a96d6 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Wed, 10 May 2017 01:04:41 -0500 Subject: [PATCH 067/151] convert status tests --- t/status.bats | 141 -------------------------------------------------- t/status0.t | 11 ++++ t/status1.t | 12 +++++ t/status10.t | 26 ++++++++++ t/status11.t | 20 +++++++ t/status2.t | 16 ++++++ t/status3.t | 19 +++++++ t/status4.t | 14 +++++ t/status5.t | 15 ++++++ t/status6.t | 59 +++++++++++++++++++++ t/status7.t | 12 +++++ t/status8.t | 12 +++++ t/status9.t | 12 +++++ 13 files changed, 228 insertions(+), 141 deletions(-) delete mode 100755 t/status.bats create mode 100755 t/status0.t create mode 100755 t/status1.t create mode 100755 t/status10.t create mode 100755 t/status11.t create mode 100755 t/status2.t create mode 100755 t/status3.t create mode 100755 t/status4.t create mode 100755 t/status5.t create mode 100755 t/status6.t create mode 100755 t/status7.t create mode 100755 t/status8.t create mode 100755 t/status9.t diff --git a/t/status.bats b/t/status.bats deleted file mode 100755 index 1d4aea76..00000000 --- a/t/status.bats +++ /dev/null @@ -1,141 +0,0 @@ -#!/usr/bin/env bats - -load environment - -@test "Status argument if any must be a repo" { - ! $VCSH status nope || false -} - -@test "Status command correct for no repos" { - run $VCSH status - assert "$status" -eq 0 - assert "$output" = '' -} - -@test "Status command correct for empty repo" { - $VCSH init foo - - run $VCSH status - assert "$status" -eq 0 - assert "$output" = 'foo:' -} - -@test "Status command correct for multiple empty repos" { - $VCSH init foo - $VCSH init bar - - run $VCSH status - assert "$status" -eq 0 - assert "$output" = $'bar:\n\nfoo:' -} - -@test "Terse status correct for empty repo" { - $VCSH init foo - - run $VCSH status --terse - assert "$status" -eq 0 - assert "$output" = '' -} - -@test "Terse status correct for multiple empty repos" { - $VCSH init foo - $VCSH init bar - - run $VCSH status --terse - assert "$status" -eq 0 - assert "$output" = '' -} - -@test "Status shows added/modified/moved/deleted files" { - $VCSH init foo - - for f in 00 0M 0D M0 MM MD A0 AM AD D0 R0x RMx RDx oo; do - echo "$f" > "$f" - done - $VCSH foo add 00 0M 0D M0 MM MD D0 R0x RMx RDx - $VCSH foo commit -m 'commit' - - # Modified in index - for f in M?; do - echo changed > $f - done - $VCSH foo add M? - - # Added to index - $VCSH foo add A? - - # Deleted in index - $VCSH foo rm -q --cached D? - - # Renamed in index - for f in R?x; do - $VCSH foo mv "$f" "${f%x}" - done - - # Modified locally - for f in ?M; do - echo localchanged > $f - done - - # Deleted locally - rm ?D - - run $VCSH status - assert "$status" -eq 0 - assert "$output" = "$(printf '%s\n' \ - 'foo:' \ - ' D 0D' \ - ' M 0M' \ - 'A A0' \ - 'AD AD' \ - 'AM AM' \ - 'D D0' \ - 'M M0' \ - 'MD MD' \ - 'MM MM' \ - 'R R0x -> R0' \ - 'RD RDx -> RD' \ - 'RM RMx -> RM')" -} - -@test "Status shows commits behind upstream" { - skip "Test not yet implemented" -} - -@test "Status shows commits ahead of upstream" { - skip "Test not yet implemented" -} - -@test "Status shows commits behind and ahead of upstream" { - skip "Test not yet implemented" -} - -@test "Status colored when output to tty" { - which socat || skip "socat required to create pseudo-tty" - - $VCSH init foo - touch a - $VCSH run foo git add a - $VCSH run foo git config --local color.status.added green - - # Ensure terminal is something Git will attempt to color - TERM=vt100 - export TERM - run socat -u exec:"$VCSH status foo",pty,rawer stdio - assert "$output" = $'\e[32mA\e[m a' -} - -@test "Status can be abbreviated (statu, stat, sta, st)" { - $VCSH init foo - touch a - $VCSH foo add a - - run $VCSH status - expected=$output - - for cmd in statu stat sta st; do - run $VCSH $cmd - assert "$status" -eq 0 - assert "$output" = "$expected" - done -} diff --git a/t/status0.t b/t/status0.t new file mode 100755 index 00000000..3e7300a8 --- /dev/null +++ b/t/status0.t @@ -0,0 +1,11 @@ +#!/bin/bash + +test_description='Status command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Status argument if any must be a repo' \ + 'test_must_fail $VCSH status nope' + +test_done diff --git a/t/status1.t b/t/status1.t new file mode 100755 index 00000000..f4ca892c --- /dev/null +++ b/t/status1.t @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='Status command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Status command correct for no repos' \ + '$VCSH status >output && + test_must_be_empty output' + +test_done diff --git a/t/status10.t b/t/status10.t new file mode 100755 index 00000000..d951861d --- /dev/null +++ b/t/status10.t @@ -0,0 +1,26 @@ +#!/bin/bash + +test_description='Status command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Check for socat (needed for pseudo-tty)' \ + 'if which socat; then + test_set_prereq SOCAT + fi' + +test_expect_success SOCAT 'Status colored when output to tty' \ + '$VCSH init foo && + touch a && + $VCSH run foo git add a && + $VCSH run foo git config --local color.status.added green && + + # Ensure terminal is something Git will attempt to color + TERM=vt100 && + export TERM && + printf "\\e[32mA\\e[m a\n" >expected && + socat -u exec:"$VCSH status foo",pty,rawer stdio >output && + test_cmp expected output' + +test_done diff --git a/t/status11.t b/t/status11.t new file mode 100755 index 00000000..e80c88a8 --- /dev/null +++ b/t/status11.t @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='Status command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Status can be abbreviated (statu, stat, sta, st)' \ + '$VCSH init foo && + touch a && + $VCSH foo add a && + + $VCSH status >expected && + + for cmd in statu stat sta st; do + $VCSH $cmd >output && + test_cmp expected output + done' + +test_done diff --git a/t/status2.t b/t/status2.t new file mode 100755 index 00000000..f46f54d0 --- /dev/null +++ b/t/status2.t @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='Status command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Status command correct for empty repo' \ + '$VCSH init foo && + + echo "foo:" >expected && + echo "" >>expected && + $VCSH status >output && + test_cmp expected output' + +test_done diff --git a/t/status3.t b/t/status3.t new file mode 100755 index 00000000..b4338e61 --- /dev/null +++ b/t/status3.t @@ -0,0 +1,19 @@ +#!/bin/bash + +test_description='Status command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Status command correct for multiple empty repos' \ + '$VCSH init foo && + $VCSH init bar && + + echo "bar:" >expected && + echo "" >>expected && + echo "foo:" >>expected && + echo "" >>expected && + $VCSH status >output && + test_cmp expected output' + +test_done diff --git a/t/status4.t b/t/status4.t new file mode 100755 index 00000000..09c3b383 --- /dev/null +++ b/t/status4.t @@ -0,0 +1,14 @@ +#!/bin/bash + +test_description='Status command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Terse status correct for empty repo' \ + '$VCSH init foo && + + $VCSH status --terse >output && + test_must_be_empty output' + +test_done diff --git a/t/status5.t b/t/status5.t new file mode 100755 index 00000000..a783cd31 --- /dev/null +++ b/t/status5.t @@ -0,0 +1,15 @@ +#!/bin/bash + +test_description='Status command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Terse status correct for multiple empty repos' \ + '$VCSH init foo && + $VCSH init bar && + + $VCSH status --terse >output && + test_must_be_empty output' + +test_done diff --git a/t/status6.t b/t/status6.t new file mode 100755 index 00000000..d2877141 --- /dev/null +++ b/t/status6.t @@ -0,0 +1,59 @@ +#!/bin/bash + +test_description='Status command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Status shows added/modified/moved/deleted files' \ + '$VCSH init foo && + + for f in 00 0M 0D M0 MM MD A0 AM AD D0 R0x RMx RDx oo; do + echo "$f" > "$f" + done && + $VCSH foo add 00 0M 0D M0 MM MD D0 R0x RMx RDx && + $VCSH foo commit -m "commit" && + + # Modified in index + for f in M?; do + echo changed > $f + done && + $VCSH foo add M? && + + # Added to index + $VCSH foo add A? && + + # Deleted in index + $VCSH foo rm -q --cached D? && + + # Renamed in index + for f in R?x; do + $VCSH foo mv "$f" "${f%x}" + done && + + # Modified locally + for f in ?M; do + echo localchanged > $f + done && + + # Deleted locally + rm ?D && + + echo "foo:" >expected && + echo " D 0D" >>expected && + echo " M 0M" >>expected && + echo "A A0" >>expected && + echo "AD AD" >>expected && + echo "AM AM" >>expected && + echo "D D0" >>expected && + echo "M M0" >>expected && + echo "MD MD" >>expected && + echo "MM MM" >>expected && + echo "R R0x -> R0" >>expected && + echo "RD RDx -> RD" >>expected && + echo "RM RMx -> RM" >>expected && + echo "" >>expected && + $VCSH status >output && + test_cmp expected output' + +test_done diff --git a/t/status7.t b/t/status7.t new file mode 100755 index 00000000..0cd83780 --- /dev/null +++ b/t/status7.t @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='Status command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_failure 'Status shows commits behind upstream' \ + '# Test not yet implemented + false' + +test_done diff --git a/t/status8.t b/t/status8.t new file mode 100755 index 00000000..429eefd9 --- /dev/null +++ b/t/status8.t @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='Status command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_failure 'Status shows commits ahead of upstream' \ + '# Test not yet implemented + false' + +test_done diff --git a/t/status9.t b/t/status9.t new file mode 100755 index 00000000..b85fae2c --- /dev/null +++ b/t/status9.t @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='Status command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_failure 'Status shows commits behind and ahead of upstream' \ + '# Test not yet implemented + false' + +test_done From 3eca9f520ae055a8cd8c23b55ff1c8c47928d49f Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 12 May 2017 00:10:10 -0500 Subject: [PATCH 068/151] update rename tests --- t/rename.bats | 75 --------------------------------------------------- t/rename0.t | 12 +++++++++ t/rename1.t | 11 ++++++++ t/rename2.t | 14 ++++++++++ t/rename3.t | 16 +++++++++++ t/rename4.t | 16 +++++++++++ t/rename5.t | 19 +++++++++++++ t/rename6.t | 19 +++++++++++++ t/rename7.t | 20 ++++++++++++++ 9 files changed, 127 insertions(+), 75 deletions(-) delete mode 100755 t/rename.bats create mode 100755 t/rename0.t create mode 100755 t/rename1.t create mode 100755 t/rename2.t create mode 100755 t/rename3.t create mode 100755 t/rename4.t create mode 100755 t/rename5.t create mode 100755 t/rename6.t create mode 100755 t/rename7.t diff --git a/t/rename.bats b/t/rename.bats deleted file mode 100755 index a04a22f7..00000000 --- a/t/rename.bats +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env bats - -load environment - -@test "Rename requires two arguments" { - ! $VCSH rename || false - ! $VCSH rename foo || false -} - -@test "Repository to be renamed must exist" { - ! $VCSH rename foo bar || false -} - -@test "Target of rename must not already exist" { - $VCSH init foo - $VCSH init bar - - ! $VCSH rename foo bar || false -} - -@test "Rename works on empty repository" { - $VCSH init foo - $VCSH rename foo bar - - run $VCSH list - assert "$status" -eq 0 - assert "$output" = 'bar' -} - -@test "Rename works on repository with files/commits" { - $VCSH clone -b "$TESTBR1" "$TESTREPO" foo - rev=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) - - $VCSH rename foo bar - run $VCSH bar rev-parse HEAD - assert "$status" -eq 0 - assert "$output" = "$rev" -} - -@test "Rename adopts existing .gitignore.d files under new name (bug?)" { - $VCSH init foo - - mkdir -p .gitignore.d - echo test > .gitignore.d/bar - - $VCSH rename foo bar - run $VCSH bar ls-files - assert "$status" -eq 0 - assert "$output" = ".gitignore.d/bar" -} - -@test "Rename adopts existing .gitattributes.d files under new name (bug?)" { - $VCSH init foo - - mkdir -p .gitattributes.d - echo '* whitespace' > .gitattributes.d/bar - - $VCSH rename foo bar - run $VCSH bar ls-files - assert "$status" -eq 0 - assert "$output" = ".gitattributes.d/bar" -} - -@test "Rename can be abbreviated (renam, rena, ren, re)" { - $VCSH init foo - - $VCSH renam foo bar - $VCSH rena bar baz - $VCSH ren baz bat - $VCSH re bat quux - - run $VCSH list - assert "$status" -eq 0 - assert "$output" = "quux" -} diff --git a/t/rename0.t b/t/rename0.t new file mode 100755 index 00000000..61302fba --- /dev/null +++ b/t/rename0.t @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='Rename command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Rename requires two arguments' \ + 'test_must_fail $VCSH rename && + test_must_fail $VCSH rename foo' + +test_done diff --git a/t/rename1.t b/t/rename1.t new file mode 100755 index 00000000..874b4e3a --- /dev/null +++ b/t/rename1.t @@ -0,0 +1,11 @@ +#!/bin/bash + +test_description='Rename command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Repository to be renamed must exist' \ + 'test_must_fail $VCSH rename foo bar' + +test_done diff --git a/t/rename2.t b/t/rename2.t new file mode 100755 index 00000000..9d132d94 --- /dev/null +++ b/t/rename2.t @@ -0,0 +1,14 @@ +#!/bin/bash + +test_description='Rename command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Target of rename must not already exist' \ + '$VCSH init foo && + $VCSH init bar && + + test_must_fail $VCSH rename foo bar' + +test_done diff --git a/t/rename3.t b/t/rename3.t new file mode 100755 index 00000000..d7feea77 --- /dev/null +++ b/t/rename3.t @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='Rename command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Rename works on empty repository' \ + '$VCSH init foo && + $VCSH rename foo bar && + + echo bar >expected && + $VCSH list >output && + test_cmp expected output' + +test_done diff --git a/t/rename4.t b/t/rename4.t new file mode 100755 index 00000000..97ebdb8e --- /dev/null +++ b/t/rename4.t @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='Rename command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Rename works on repository with files/commits' \ + '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && + git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 >expected && + + $VCSH rename foo bar && + $VCSH bar rev-parse HEAD >output && + test_cmp expected output' + +test_done diff --git a/t/rename5.t b/t/rename5.t new file mode 100755 index 00000000..83b790ea --- /dev/null +++ b/t/rename5.t @@ -0,0 +1,19 @@ +#!/bin/bash + +test_description='Rename command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Rename adopts existing .gitignore.d files under new name (bug?)' \ + '$VCSH init foo && + + mkdir -p .gitignore.d && + echo test > .gitignore.d/bar && + + $VCSH rename foo bar && + echo ".gitignore.d/bar" >expected && + $VCSH bar ls-files >output && + test_cmp expected output' + +test_done diff --git a/t/rename6.t b/t/rename6.t new file mode 100755 index 00000000..49402222 --- /dev/null +++ b/t/rename6.t @@ -0,0 +1,19 @@ +#!/bin/bash + +test_description='Rename command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Rename adopts existing .gitattributes.d files under new name (bug?)' \ + '$VCSH init foo && + + mkdir -p .gitattributes.d && + echo "* whitespace" > .gitattributes.d/bar && + + $VCSH rename foo bar && + echo ".gitattributes.d/bar" >expected && + $VCSH bar ls-files >output && + test_cmp expected output' + +test_done diff --git a/t/rename7.t b/t/rename7.t new file mode 100755 index 00000000..d98e0116 --- /dev/null +++ b/t/rename7.t @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='Rename command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Rename can be abbreviated (renam, rena, ren, re)' \ + '$VCSH init foo && + + $VCSH renam foo bar && + $VCSH rena bar baz && + $VCSH ren baz bat && + $VCSH re bat quux && + + echo quux >expected && + $VCSH list >output && + test_cmp expected output' + +test_done From 6432a5cad62713ec5b0e61ce0fcccf05bdc6048b Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 12 May 2017 00:15:21 -0500 Subject: [PATCH 069/151] convert version tests --- t/version.bats | 24 ------------------------ t/version0.t | 11 +++++++++++ t/version1.t | 13 +++++++++++++ t/version2.t | 16 ++++++++++++++++ 4 files changed, 40 insertions(+), 24 deletions(-) delete mode 100755 t/version.bats create mode 100755 t/version0.t create mode 100755 t/version1.t create mode 100755 t/version2.t diff --git a/t/version.bats b/t/version.bats deleted file mode 100755 index 15d28b21..00000000 --- a/t/version.bats +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bats - -load environment - -@test "Version command succeeds" { - $VCSH version -} - -@test "Version command prints vcsh and git versions" { - run $VCSH version - echo "${lines[0]}" | assert_grep '^vcsh [0-9]' - echo "${lines[1]}" | assert_grep '^git version [0-9]' -} - -@test "Version can be abbreviated (versio, versi, vers, ver, ve)" { - run $VCSH version - expected=$output - - for cmd in versio versi vers ver ve; do - run $VCSH $cmd - assert "$status" -eq 0 - assert "$output" = "$expected" - done -} diff --git a/t/version0.t b/t/version0.t new file mode 100755 index 00000000..49600769 --- /dev/null +++ b/t/version0.t @@ -0,0 +1,11 @@ +#!/bin/bash + +test_description='Version command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Version command succeeds' \ + '$VCSH version' + +test_done diff --git a/t/version1.t b/t/version1.t new file mode 100755 index 00000000..28ca45cb --- /dev/null +++ b/t/version1.t @@ -0,0 +1,13 @@ +#!/bin/bash + +test_description='Version command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Version command prints vcsh and git versions' \ + '$VCSH version >output && + sed -n 1p output | assert_grep "^vcsh [0-9]" && + sed -n 2p output | assert_grep "^git version [0-9]"' + +test_done diff --git a/t/version2.t b/t/version2.t new file mode 100755 index 00000000..7b8b2aa6 --- /dev/null +++ b/t/version2.t @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='Version command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Version can be abbreviated (versio, versi, vers, ver, ve)' \ + '$VCSH version >expected && + + for cmd in versio versi vers ver ve; do + $VCSH $cmd >output && + test_cmp expected output + done' + +test_done From 08b9632e515c0c9e7e034cc71e4f373528920a76 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 12 May 2017 00:16:31 -0500 Subject: [PATCH 070/151] combine version tests --- t/{version2.t => version.t} | 8 ++++++++ t/version0.t | 11 ----------- t/version1.t | 13 ------------- 3 files changed, 8 insertions(+), 24 deletions(-) rename t/{version2.t => version.t} (54%) delete mode 100755 t/version0.t delete mode 100755 t/version1.t diff --git a/t/version2.t b/t/version.t similarity index 54% rename from t/version2.t rename to t/version.t index 7b8b2aa6..cb85eae1 100755 --- a/t/version2.t +++ b/t/version.t @@ -5,6 +5,14 @@ test_description='Version command' . ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" +test_expect_success 'Version command succeeds' \ + '$VCSH version' + +test_expect_success 'Version command prints vcsh and git versions' \ + '$VCSH version >output && + sed -n 1p output | assert_grep "^vcsh [0-9]" && + sed -n 2p output | assert_grep "^git version [0-9]"' + test_expect_success 'Version can be abbreviated (versio, versi, vers, ver, ve)' \ '$VCSH version >expected && diff --git a/t/version0.t b/t/version0.t deleted file mode 100755 index 49600769..00000000 --- a/t/version0.t +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -test_description='Version command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Version command succeeds' \ - '$VCSH version' - -test_done diff --git a/t/version1.t b/t/version1.t deleted file mode 100755 index 28ca45cb..00000000 --- a/t/version1.t +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -test_description='Version command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Version command prints vcsh and git versions' \ - '$VCSH version >output && - sed -n 1p output | assert_grep "^vcsh [0-9]" && - sed -n 2p output | assert_grep "^git version [0-9]"' - -test_done From 5a028880b290167f33948abc40d6924fa522031c Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 12 May 2017 00:28:07 -0500 Subject: [PATCH 071/151] convert which tests --- t/which.bats | 134 --------------------------------------------------- t/which0.t | 12 +++++ t/which1.t | 11 +++++ t/which10.t | 21 ++++++++ t/which11.t | 28 +++++++++++ t/which2.t | 11 +++++ t/which3.t | 17 +++++++ t/which4.t | 19 ++++++++ t/which5.t | 20 ++++++++ t/which6.t | 20 ++++++++ t/which7.t | 20 ++++++++ t/which8.t | 20 ++++++++ t/which9.t | 20 ++++++++ 13 files changed, 219 insertions(+), 134 deletions(-) delete mode 100755 t/which.bats create mode 100755 t/which0.t create mode 100755 t/which1.t create mode 100755 t/which10.t create mode 100755 t/which11.t create mode 100755 t/which2.t create mode 100755 t/which3.t create mode 100755 t/which4.t create mode 100755 t/which5.t create mode 100755 t/which6.t create mode 100755 t/which7.t create mode 100755 t/which8.t create mode 100755 t/which9.t diff --git a/t/which.bats b/t/which.bats deleted file mode 100755 index c575388c..00000000 --- a/t/which.bats +++ /dev/null @@ -1,134 +0,0 @@ -#!/usr/bin/env bats - -load environment - -@test "Which command requires exactly one parameter" { - ! $VCSH which || false - ! $VCSH which foo bar || false -} - -@test "Which command does not accept an empty parameter" { - ! $VCSH which '' || false -} - -@test "Which command fails if no repositories" { - ! $VCSH which nope || false -} - -@test "Which command fails if pattern not found" { - $VCSH init foo - - touch a - $VCSH foo add a - $VCSH foo commit -m 'a' - - ! $VCSH which nope || false -} - -@test "Which command matches exact filename" { - $VCSH init foo - - touch hello testfile - $VCSH foo add hello testfile - $VCSH foo commit -m 'testfile' - - run $VCSH which testfile - assert "$status" -eq 0 - assert "$output" = "foo: testfile" -} - -@test "Which command matches entire path" { - $VCSH init foo - - mkdir -p dir - touch hello dir/testfile - $VCSH foo add hello dir/testfile - $VCSH foo commit -m 'dir/testfile' - - run $VCSH which dir/testfile - assert "$status" -eq 0 - assert "$output" = "foo: dir/testfile" -} - -@test "Which command matches filename within subdirectory" { - $VCSH init foo - - mkdir -p dir - touch hello dir/testfile - $VCSH foo add hello dir/testfile - $VCSH foo commit -m 'dir/testfile' - - run $VCSH which testfile - assert "$status" -eq 0 - assert "$output" = "foo: dir/testfile" -} - -@test "Which command matches directory path component" { - $VCSH init foo - - mkdir -p dir/subd - touch hello dir/subd/testfile - $VCSH foo add hello dir/subd/testfile - $VCSH foo commit -m 'dir/subd/testfile' - - run $VCSH which subd - assert "$status" -eq 0 - assert "$output" = "foo: dir/subd/testfile" -} - -@test "Which command matches partial filename" { - $VCSH init foo - - mkdir -p dir/subd - touch hello dir/subd/testfile - $VCSH foo add hello dir/subd/testfile - $VCSH foo commit -m 'dir/subd/testfile' - - run $VCSH which estf - assert "$status" -eq 0 - assert "$output" = "foo: dir/subd/testfile" -} - -@test "Which command matches partial path component across slash" { - $VCSH init foo - - mkdir -p dir/subd - touch hello dir/subd/testfile - $VCSH foo add hello dir/subd/testfile - $VCSH foo commit -m 'dir/subd/testfile' - - run $VCSH which bd/te - assert "$status" -eq 0 - assert "$output" = "foo: dir/subd/testfile" -} - -@test "Which command matches using POSIX BRE" { - $VCSH init foo - - touch calor color colour 'colou?r' - $VCSH foo add * - $VCSH foo commit -m 'color' - - run $VCSH which 'c.lou\?r' - assert "$status" -eq 0 - assert "$output" = "$(printf 'foo: calor\nfoo: color\nfoo: colour')" -} - -@test "Which command searches all repos" { - $VCSH init foo - $VCSH init bar - $VCSH init baz - - mkdir -p a b c - touch {a,b,c}/{hello,goodbye} - $VCSH foo add a - $VCSH foo commit -m 'hello' - $VCSH bar add b - $VCSH bar commit -m 'hello' - $VCSH baz add c - $VCSH baz commit -m 'hello' - - run $VCSH which hello - assert "$status" -eq 0 - assert "$output" = "$(printf 'bar: b/hello\nbaz: c/hello\nfoo: a/hello')" -} diff --git a/t/which0.t b/t/which0.t new file mode 100755 index 00000000..e097eb1d --- /dev/null +++ b/t/which0.t @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='Which command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Which command requires exactly one parameter' \ + 'test_must_fail $VCSH which && + test_must_fail $VCSH which foo bar' + +test_done diff --git a/t/which1.t b/t/which1.t new file mode 100755 index 00000000..2eee1de5 --- /dev/null +++ b/t/which1.t @@ -0,0 +1,11 @@ +#!/bin/bash + +test_description='Which command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Which command does not accept an empty parameter' \ + 'test_must_fail $VCSH which ""' + +test_done diff --git a/t/which10.t b/t/which10.t new file mode 100755 index 00000000..7489209d --- /dev/null +++ b/t/which10.t @@ -0,0 +1,21 @@ +#!/bin/bash + +test_description='Which command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Which command matches using POSIX BRE' \ + '$VCSH init foo && + + touch calor color colour 'colou?r' && + $VCSH foo add * && + $VCSH foo commit -m 'color' && + + echo "foo: calor" >expected && + echo "foo: color" >>expected && + echo "foo: colour" >>expected && + $VCSH which "c.lou\\?r" >output && + test_cmp expected output' + +test_done diff --git a/t/which11.t b/t/which11.t new file mode 100755 index 00000000..9d01af64 --- /dev/null +++ b/t/which11.t @@ -0,0 +1,28 @@ +#!/bin/bash + +test_description='Which command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Which command searches all repos' \ + '$VCSH init foo && + $VCSH init bar && + $VCSH init baz && + + mkdir -p a b c && + touch {a,b,c}/{hello,goodbye} && + $VCSH foo add a && + $VCSH foo commit -m "hello" && + $VCSH bar add b && + $VCSH bar commit -m "hello" && + $VCSH baz add c && + $VCSH baz commit -m "hello" && + + echo "bar: b/hello" >expected && + echo "baz: c/hello" >>expected && + echo "foo: a/hello" >>expected && + $VCSH which hello >output && + test_cmp expected output' + +test_done diff --git a/t/which2.t b/t/which2.t new file mode 100755 index 00000000..60d7e303 --- /dev/null +++ b/t/which2.t @@ -0,0 +1,11 @@ +#!/bin/bash + +test_description='Which command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Which command fails if no repositories' \ + 'test_must_fail $VCSH which nope' + +test_done diff --git a/t/which3.t b/t/which3.t new file mode 100755 index 00000000..f926d758 --- /dev/null +++ b/t/which3.t @@ -0,0 +1,17 @@ +#!/bin/bash + +test_description='Which command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Which command fails if pattern not found' \ + '$VCSH init foo && + + touch a && + $VCSH foo add a && + $VCSH foo commit -m "a" && + + test_must_fail $VCSH which nope' + +test_done diff --git a/t/which4.t b/t/which4.t new file mode 100755 index 00000000..e2c23fd7 --- /dev/null +++ b/t/which4.t @@ -0,0 +1,19 @@ +#!/bin/bash + +test_description='Which command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Which command matches exact filename' \ + '$VCSH init foo && + + touch hello testfile && + $VCSH foo add hello testfile && + $VCSH foo commit -m "testfile" && + + echo "foo: testfile" >expected && + $VCSH which testfile >output && + test_cmp expected output' + +test_done diff --git a/t/which5.t b/t/which5.t new file mode 100755 index 00000000..3cf1b6cf --- /dev/null +++ b/t/which5.t @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='Which command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Which command matches entire path' \ + '$VCSH init foo && + + mkdir -p dir && + touch hello dir/testfile && + $VCSH foo add hello dir/testfile && + $VCSH foo commit -m 'dir/testfile' && + + echo "foo: dir/testfile" >expected && + $VCSH which dir/testfile >output && + test_cmp expected output' + +test_done diff --git a/t/which6.t b/t/which6.t new file mode 100755 index 00000000..289b428e --- /dev/null +++ b/t/which6.t @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='Which command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Which command matches filename within subdirectory' \ + '$VCSH init foo && + + mkdir -p dir && + touch hello dir/testfile && + $VCSH foo add hello dir/testfile && + $VCSH foo commit -m "dir/testfile" && + + echo "foo: dir/testfile" >expected && + $VCSH which testfile >output && + test_cmp expected output' + +test_done diff --git a/t/which7.t b/t/which7.t new file mode 100755 index 00000000..1ad37896 --- /dev/null +++ b/t/which7.t @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='Which command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Which command matches directory path component' \ + '$VCSH init foo && + + mkdir -p dir/subd && + touch hello dir/subd/testfile && + $VCSH foo add hello dir/subd/testfile && + $VCSH foo commit -m "dir/subd/testfile" && + + echo "foo: dir/subd/testfile" >expected && + $VCSH which subd >output && + test_cmp expected output' + +test_done diff --git a/t/which8.t b/t/which8.t new file mode 100755 index 00000000..8b1e8b4e --- /dev/null +++ b/t/which8.t @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='Which command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Which command matches partial filename' \ + '$VCSH init foo && + + mkdir -p dir/subd && + touch hello dir/subd/testfile && + $VCSH foo add hello dir/subd/testfile && + $VCSH foo commit -m "dir/subd/testfile" && + + echo "foo: dir/subd/testfile" >expected && + $VCSH which estf >output && + test_cmp expected output' + +test_done diff --git a/t/which9.t b/t/which9.t new file mode 100755 index 00000000..6f4e14ea --- /dev/null +++ b/t/which9.t @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='Which command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Which command matches partial path component across slash' \ + '$VCSH init foo && + + mkdir -p dir/subd && + touch hello dir/subd/testfile && + $VCSH foo add hello dir/subd/testfile && + $VCSH foo commit -m 'dir/subd/testfile' && + + echo "foo: dir/subd/testfile" >expected && + $VCSH which bd/te >output && + test_cmp expected output' + +test_done From f8fc9a4eadfe3f058c5fdba147a040d803ff822a Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 12 May 2017 00:43:17 -0500 Subject: [PATCH 072/151] convert commit tests --- t/commit.bats | 90 --------------------------------------------------- t/commit0.t | 12 +++++++ t/commit1.t | 23 +++++++++++++ t/commit2.t | 26 +++++++++++++++ t/commit3.t | 26 +++++++++++++++ t/commit4.t | 23 +++++++++++++ t/commit5.t | 14 ++++++++ 7 files changed, 124 insertions(+), 90 deletions(-) delete mode 100755 t/commit.bats create mode 100755 t/commit0.t create mode 100755 t/commit1.t create mode 100755 t/commit2.t create mode 100755 t/commit3.t create mode 100755 t/commit4.t create mode 100755 t/commit5.t diff --git a/t/commit.bats b/t/commit.bats deleted file mode 100755 index d1ad56d0..00000000 --- a/t/commit.bats +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env bats - -load environment - -@test "commit works with no repos" { - run $VCSH commit - assert "$status" -eq 0 - assert "$output" = "" -} - -@test "commit works with single repo" { - skip "BUG: commit is broken" - - $VCSH init foo - - touch a - $VCSH foo add a - run $VCSH commit -m 'a' - assert "$status" -eq 0 - # XXX Is printing a trailing space really intended? - assert "$output" = "foo: " - - run $VCSH foo rev-list HEAD --count - assert "$status" -eq 0 - assert "$output" = "1" -} - -@test "commit works with multiple repos" { - skip "BUG: commit is broken" - - $VCSH init foo - $VCSH init bar - - touch a b - $VCSH foo add a - $VCSH bar add b - run $VCSH commit -m 'ab' - assert "$status" -eq 0 - # XXX Is printing a trailing space and blank line really intended? - assert "$output" = "$(printf 'bar: \n\nfoo: ')" - - $VCSH foo log --oneline | assert_grep -x '....... ab' - $VCSH bar log --oneline | assert_grep -x '....... ab' -} - -@test "commit can handle arguments with spaces" { - skip "BUG: commit is broken" - - $VCSH init foo - $VCSH init bar - - touch a b - $VCSH foo add a - $VCSH bar add b - run $VCSH commit -m 'log message' - assert "$status" -eq 0 - # XXX Is printing a trailing space and blank line really intended? - assert "$output" = "$(printf 'bar: \n\nfoo: ')" - - $VCSH foo log --oneline | assert_grep -x '....... log message' - $VCSH bar log --oneline | assert_grep -x '....... log message' -} - -@test "commit works even if not all repos have changes" { - skip "BUG: commit is broken" - - $VCSH init foo - $VCSH init bar - - touch a b - $VCSH foo add a - $VCSH commit -m 'part1' - - $VCSH bar add b - $VCSH commit -m 'part2' - - $VCSH foo log --oneline | assert_grep -x '....... part1' - $VCSH bar log --oneline | assert_grep -x '....... part2' -} - -@test "commit not affected by existing \$VCSH_COMMAND_RETURN_CODE" { - skip "BUG" - - VCSH_COMMAND_RETURN_CODE=1 - export VCSH_COMMAND_RETURN_CODE - - run $VCSH commit - assert "$status" -eq 0 - assert "$output" = "" -} diff --git a/t/commit0.t b/t/commit0.t new file mode 100755 index 00000000..37c47ccf --- /dev/null +++ b/t/commit0.t @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='Commit command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'commit works with no repos' \ + '$VCSH commit >output && + test_must_be_empty output' + +test_done diff --git a/t/commit1.t b/t/commit1.t new file mode 100755 index 00000000..b515fd4a --- /dev/null +++ b/t/commit1.t @@ -0,0 +1,23 @@ +#!/bin/bash + +test_description='Commit command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +# Commit is broken +test_expect_failure 'commit works with single repo' \ + '$VCSH init foo && + + touch a && + $VCSH foo add a && + # XXX Is printing a trailing space really intended? + echo "foo: " >expected && + $VCSH commit -m a >output && + test_cmp expected output && + + echo 1 >expected && + $VCSH foo rev-list HEAD --count >output && + test_cmp expected output' + +test_done diff --git a/t/commit2.t b/t/commit2.t new file mode 100755 index 00000000..889995c9 --- /dev/null +++ b/t/commit2.t @@ -0,0 +1,26 @@ +#!/bin/bash + +test_description='Commit command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +# Commit is broken +test_expect_failure 'commit works with multiple repos' \ + '$VCSH init foo && + $VCSH init bar && + + touch a b && + $VCSH foo add a && + $VCSH bar add b && + # XXX Is printing a trailing space and blank line really intended? + echo "bar: " >expected && + echo "" >>expected && + echo "foo: " >>expected && + $VCSH commit -m "ab" >output && + test_cmp expected output && + + $VCSH foo log --oneline | assert_grep -x "....... ab" && + $VCSH bar log --oneline | assert_grep -x "....... ab"' + +test_done diff --git a/t/commit3.t b/t/commit3.t new file mode 100755 index 00000000..d52e3414 --- /dev/null +++ b/t/commit3.t @@ -0,0 +1,26 @@ +#!/bin/bash + +test_description='Commit command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +# Commit is broken +test_expect_failure 'commit can handle arguments with spaces' \ + '$VCSH init foo && + $VCSH init bar && + + touch a b && + $VCSH foo add a && + $VCSH bar add b && + # XXX Is printing a trailing space and blank line really intended? + echo "bar: " >expected && + echo "" >>expected && + echo "foo: " >>expected && + $VCSH commit -m "log message" && + test_cmp expected output && + + $VCSH foo log --oneline | assert_grep -x "....... log message" && + $VCSH bar log --oneline | assert_grep -x "....... log message"' + +test_done diff --git a/t/commit4.t b/t/commit4.t new file mode 100755 index 00000000..00991ae6 --- /dev/null +++ b/t/commit4.t @@ -0,0 +1,23 @@ +#!/bin/bash + +test_description='Commit command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +# Commit is broken +test_expect_failure 'commit works even if not all repos have changes' \ + '$VCSH init foo && + $VCSH init bar && + + touch a b && + $VCSH foo add a && + $VCSH commit -m "part1" && + + $VCSH bar add b && + $VCSH commit -m "part2" && + + $VCSH foo log --oneline | assert_grep -x "....... part1" && + $VCSH bar log --oneline | assert_grep -x "....... part2"' + +test_done diff --git a/t/commit5.t b/t/commit5.t new file mode 100755 index 00000000..d81b7ea2 --- /dev/null +++ b/t/commit5.t @@ -0,0 +1,14 @@ +#!/bin/bash + +test_description='Commit command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +# Known bug +test_expect_failure 'commit not affected by existing \$VCSH_COMMAND_RETURN_CODE' \ + 'VCSH_COMMAND_RETURN_CODE=1 && + export VCSH_COMMAND_RETURN_CODE && + $VCSH commit' + +test_done From fa952f096af3535b99ac5f55572064199b5ee041 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 12 May 2017 00:48:14 -0500 Subject: [PATCH 073/151] add some writemes to remember --- t/configfiles.t | 10 ++++++ t/external-vars.t | 77 +++++++++++++++++++++++++++++++++++++++++++++++ t/hooks.t | 10 ++++++ 3 files changed, 97 insertions(+) create mode 100755 t/configfiles.t create mode 100755 t/external-vars.t create mode 100755 t/hooks.t diff --git a/t/configfiles.t b/t/configfiles.t new file mode 100755 index 00000000..215ec665 --- /dev/null +++ b/t/configfiles.t @@ -0,0 +1,10 @@ +#!/bin/bash + +test_description='Configuration files' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +# XXX writeme + +test_done diff --git a/t/external-vars.t b/t/external-vars.t new file mode 100755 index 00000000..5ef4cb99 --- /dev/null +++ b/t/external-vars.t @@ -0,0 +1,77 @@ +#!/bin/bash + +test_description='External environment variables' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +# XXX writeme + +# All of the following variables are used in vcsh. Make sure that having +# cockamamie values for any of the ones that aren't supposed to affect the +# behavior of vcsh... doesn't. +# +# COLORING +# GIT_DIR +# GIT_DIR_NEW +# GIT_REMOTE +# GIT_VERSION +# GIT_VERSION_MAJOR +# GIT_VERSION_MINOR +# IFS +# OLDIFS +# OPTARG +# PATH +# PWD +# SELF +# SHELL +# STATUS +# TMPDIR +# VCSH_BASE +# VCSH_BRANCH +# VCSH_COMMAND +# VCSH_COMMAND_PARAMETER +# VCSH_COMMAND_RETURN_CODE +# VCSH_CONFLICT +# VCSH_DEBUG +# VCSH_GITATTRIBUTES +# VCSH_GITIGNORE +# VCSH_GIT_OPTIONS +# VCSH_HOOK_D +# VCSH_OPTION_CONFIG +# VCSH_OVERLAY_D +# VCSH_REPO_D +# VCSH_REPO_NAME +# VCSH_REPO_NAME_NEW +# VCSH_STATUS_TERSE +# VCSH_VERBOSE +# VCSH_WORKTREE +# VERSION +# XDG_CONFIG_HOME +# answer +# check_directory +# command_prefix +# commits_ahead +# commits_behind +# directory_component +# directory_opt +# exclude_standard_opt +# file +# files +# gitignore +# gitignores +# hook +# line +# new +# object +# output +# overlay +# ran_once +# remote_tracking_branch +# repo +# temp_file_others +# temp_file_untracked +# temp_file_untracked_copy +# tempfile + +test_done diff --git a/t/hooks.t b/t/hooks.t new file mode 100755 index 00000000..161c28a4 --- /dev/null +++ b/t/hooks.t @@ -0,0 +1,10 @@ +#!/bin/bash + +test_description='Hooks and overlays' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +# XXX writeme + +test_done From b4ceabcc9a942c1e29065d0846cb1768a86ab9bf Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 12 May 2017 00:51:00 -0500 Subject: [PATCH 074/151] convert debug test --- t/debug.bats | 9 --------- t/debug.t | 13 +++++++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) delete mode 100755 t/debug.bats create mode 100755 t/debug.t diff --git a/t/debug.bats b/t/debug.bats deleted file mode 100755 index 5b8f8f43..00000000 --- a/t/debug.bats +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bats - -load environment - -@test "Debug output includes git version" { - $VCSH -d init foo |& assert_grep 'git version [0-9]' - $VCSH -d list |& assert_grep 'git version [0-9]' - # XXX add more? -} diff --git a/t/debug.t b/t/debug.t new file mode 100755 index 00000000..b9c2059c --- /dev/null +++ b/t/debug.t @@ -0,0 +1,13 @@ +#!/bin/bash + +test_description='Debug mode' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +# XXX add more? +test_expect_success 'Debug output includes git version' \ + '$VCSH -d init foo |& assert_grep "git version [0-9]" && + $VCSH -d list |& assert_grep "git version [0-9]"' + +test_done From 2ac65aee89b2fd1cce84730650f4f9c40a582a8f Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 12 May 2017 16:38:02 -0500 Subject: [PATCH 075/151] convert foreach tests --- t/foreach.bats | 37 ------------------------------------- t/foreach0.t | 11 +++++++++++ t/foreach1.t | 12 ++++++++++++ t/foreach2.t | 22 ++++++++++++++++++++++ t/foreach3.t | 22 ++++++++++++++++++++++ 5 files changed, 67 insertions(+), 37 deletions(-) delete mode 100755 t/foreach.bats create mode 100755 t/foreach0.t create mode 100755 t/foreach1.t create mode 100755 t/foreach2.t create mode 100755 t/foreach3.t diff --git a/t/foreach.bats b/t/foreach.bats deleted file mode 100755 index 740a4ada..00000000 --- a/t/foreach.bats +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bats - -load environment - -@test "Foreach requires an argument" { - ! $VCSH foreach || false -} - -@test "Foreach does nothing if no repositories exist" { - run $VCSH foreach version - assert "$status" -eq 0 - assert "$output" = "" -} - -@test "Foreach executes Git command inside each repository" { - $VCSH clone -b "$TESTBR1" "$TESTREPO" foo - $VCSH clone -b "$TESTBR2" "$TESTREPO" bar - - rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) - rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) - - run $VCSH foreach rev-parse HEAD - assert "$status" -eq 0 - assert "$output" = $'bar:\n'"$rev2"$'\nfoo:\n'"$rev1" -} - -@test "Foreach supports -g for non-Git commands" { - $VCSH clone -b "$TESTBR1" "$TESTREPO" foo - $VCSH clone -b "$TESTBR2" "$TESTREPO" bar - - rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) - rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) - - run $VCSH foreach -g echo test-output - assert "$status" -eq 0 - assert "$output" = $'bar:\ntest-output\nfoo:\ntest-output' -} diff --git a/t/foreach0.t b/t/foreach0.t new file mode 100755 index 00000000..d51de00e --- /dev/null +++ b/t/foreach0.t @@ -0,0 +1,11 @@ +#!/bin/bash + +test_description='Foreach command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Foreach requires an argument' \ + 'test_must_fail $VCSH foreach' + +test_done diff --git a/t/foreach1.t b/t/foreach1.t new file mode 100755 index 00000000..ac413491 --- /dev/null +++ b/t/foreach1.t @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='Foreach command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Foreach does nothing if no repositories exist' \ + '$VCSH foreach version >output && + test_must_be_empty output' + +test_done diff --git a/t/foreach2.t b/t/foreach2.t new file mode 100755 index 00000000..a33dd5dc --- /dev/null +++ b/t/foreach2.t @@ -0,0 +1,22 @@ +#!/bin/bash + +test_description='Foreach command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Foreach executes Git command inside each repository' \ + '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && + $VCSH clone -b "$TESTBR2" "$TESTREPO" bar && + + { + echo "bar:" && + git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1 && + echo "foo:" && + git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 + } >expected && + + $VCSH foreach rev-parse HEAD >output && + test_cmp expected output' + +test_done diff --git a/t/foreach3.t b/t/foreach3.t new file mode 100755 index 00000000..dffaa4d1 --- /dev/null +++ b/t/foreach3.t @@ -0,0 +1,22 @@ +#!/bin/bash + +test_description='Foreach command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Foreach supports -g for non-Git commands' \ + '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && + $VCSH clone -b "$TESTBR2" "$TESTREPO" bar && + + { + echo "bar:" && + echo "test-output" && + echo "foo:" && + echo "test-output" + } >expected && + + $VCSH foreach -g echo test-output >output && + test_cmp expected output' + +test_done From e1bb0205febc07097d1b5c93a96967e6e5b5cf12 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 12 May 2017 16:54:57 -0500 Subject: [PATCH 076/151] convert run/enter tests --- t/run-enter.bats | 121 ----------------------------------------------- t/run-enter0.t | 20 ++++++++ t/run-enter1.t | 20 ++++++++ t/run-enter2.t | 15 ++++++ t/run-enter3.t | 15 ++++++ t/run-enter4.t | 20 ++++++++ t/run-enter5.t | 15 ++++++ t/run-enter6.t | 20 ++++++++ t/run-enter7.t | 16 +++++++ t/run-enter8.t | 22 +++++++++ 10 files changed, 163 insertions(+), 121 deletions(-) delete mode 100755 t/run-enter.bats create mode 100755 t/run-enter0.t create mode 100755 t/run-enter1.t create mode 100755 t/run-enter2.t create mode 100755 t/run-enter3.t create mode 100755 t/run-enter4.t create mode 100755 t/run-enter5.t create mode 100755 t/run-enter6.t create mode 100755 t/run-enter7.t create mode 100755 t/run-enter8.t diff --git a/t/run-enter.bats b/t/run-enter.bats deleted file mode 100755 index b2187d8c..00000000 --- a/t/run-enter.bats +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/env bats - -load environment - -@test "Run executes command inside specific repository" { - $VCSH clone -b "$TESTBR1" "$TESTREPO" foo - $VCSH clone -b "$TESTBR2" "$TESTREPO" bar - - rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) - rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) - - run $VCSH run foo git rev-parse HEAD - assert "$status" -eq 0 - assert "$output" = "$rev1" - - run $VCSH run bar git rev-parse HEAD - assert "$status" -eq 0 - assert "$output" = "$rev2" -} - -@test "Run implied if no explicit command specified" { - $VCSH clone -b "$TESTBR1" "$TESTREPO" foo - $VCSH clone -b "$TESTBR2" "$TESTREPO" bar - - rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) - rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) - - run $VCSH foo rev-parse HEAD - assert "$status" -eq 0 - assert "$output" = "$rev1" - - run $VCSH bar rev-parse HEAD - assert "$status" -eq 0 - assert "$output" = "$rev2" -} - -@test "Run can be abbreviated (ru)" { - $VCSH clone -b "$TESTBR1" "$TESTREPO" foo - - rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) - - run $VCSH ru foo git rev-parse HEAD - assert "$status" -eq 0 - assert "$output" = "$rev1" -} - -@test "Run returns exit status of subcommand" { - $VCSH init foo - - run $VCSH run foo sh -c 'exit 104' - assert "$status" -eq 104 - - run $VCSH run foo sh -c 'exit 42' - assert "$status" -eq 42 - - run $VCSH run foo sh -c 'exit 93' - assert "$status" -eq 93 -} - -@test "Enter executes inside specific repository" { - $VCSH clone -b "$TESTBR1" "$TESTREPO" foo - $VCSH clone -b "$TESTBR2" "$TESTREPO" bar - - rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) - rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) - - echo 'git rev-parse HEAD > rev' | SHELL=/bin/sh $VCSH enter foo - assert "$(cat rev)" = "$rev1" - - echo 'git rev-parse HEAD > rev' | SHELL=/bin/sh $VCSH enter bar - assert "$(cat rev)" = "$rev2" -} - -@test "Enter executes \$SHELL inside repository" { - $VCSH clone -b "$TESTBR1" "$TESTREPO" foo - - rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) - SHELL='git rev-parse HEAD' run $VCSH enter foo - assert "$status" -eq 0 - assert "$output" = "$rev1" -} - -@test "Enter implied for single non-command argument" { - $VCSH clone -b "$TESTBR1" "$TESTREPO" foo - $VCSH clone -b "$TESTBR2" "$TESTREPO" bar - - rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) - rev2=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1) - - echo 'git rev-parse HEAD > rev' | SHELL=/bin/sh $VCSH foo - assert "$(cat rev)" = "$rev1" - - echo 'git rev-parse HEAD > rev' | SHELL=/bin/sh $VCSH bar - assert "$(cat rev)" = "$rev2" -} - -@test "Enter returns exit status of subshell" { - skip "BUG: enter does not pass on subshell's exit status" - $VCSH init foo - - echo 'exit 104' | SHELL=/bin/sh $VCSH enter foo - assert "$?" -eq 104 - - echo 'exit 42' | SHELL=/bin/sh $VCSH enter foo - assert "$?" -eq 42 - - echo 'exit 93' | SHELL=/bin/sh $VCSH enter foo - assert "$?" -eq 93 -} - -@test "Enter can be abbreviated (ente, ent, en)" { - $VCSH clone -b "$TESTBR1" "$TESTREPO" foo - - rev1=$(git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1) - - echo 'git rev-parse HEAD >> output' | SHELL=/bin/sh $VCSH ente foo - echo 'git rev-parse HEAD >> output' | SHELL=/bin/sh $VCSH ent foo - echo 'git rev-parse HEAD >> output' | SHELL=/bin/sh $VCSH en foo - - assert "$(cat output)" = "$(printf '%s\n%s\n%s' "$rev1" "$rev1" "$rev1")" -} diff --git a/t/run-enter0.t b/t/run-enter0.t new file mode 100755 index 00000000..dcb4db02 --- /dev/null +++ b/t/run-enter0.t @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='Run/enter commands' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Run executes command inside specific repository' \ + '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && + $VCSH clone -b "$TESTBR2" "$TESTREPO" bar && + + git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 >expected && + $VCSH run foo git rev-parse HEAD >output && + test_cmp expected output && + + git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1 >expected && + $VCSH run bar git rev-parse HEAD >output && + test_cmp expected output' + +test_done diff --git a/t/run-enter1.t b/t/run-enter1.t new file mode 100755 index 00000000..22751cd3 --- /dev/null +++ b/t/run-enter1.t @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='Run/enter commands' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Run implied if no explicit command specified' \ + '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && + $VCSH clone -b "$TESTBR2" "$TESTREPO" bar && + + git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 >expected && + $VCSH foo rev-parse HEAD >output && + test_cmp expected output && + + git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1 >expected && + $VCSH bar rev-parse HEAD >output && + test_cmp expected output' + +test_done diff --git a/t/run-enter2.t b/t/run-enter2.t new file mode 100755 index 00000000..0de048ef --- /dev/null +++ b/t/run-enter2.t @@ -0,0 +1,15 @@ +#!/bin/bash + +test_description='Run/enter commands' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Run can be abbreviated (ru)' \ + '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && + + git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 >expected && + $VCSH ru foo git rev-parse HEAD >output && + test_cmp expected output' + +test_done diff --git a/t/run-enter3.t b/t/run-enter3.t new file mode 100755 index 00000000..21ffb6ef --- /dev/null +++ b/t/run-enter3.t @@ -0,0 +1,15 @@ +#!/bin/bash + +test_description='Run/enter commands' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Run returns exit status of subcommand' \ + '$VCSH init foo && + + test_expect_code 104 $VCSH run foo sh -c "exit 104" && + test_expect_code 42 $VCSH run foo sh -c "exit 42" && + test_expect_code 93 $VCSH run foo sh -c "exit 93"' + +test_done diff --git a/t/run-enter4.t b/t/run-enter4.t new file mode 100755 index 00000000..3391edd2 --- /dev/null +++ b/t/run-enter4.t @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='Run/enter commands' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Enter executes inside specific repository' \ + '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && + $VCSH clone -b "$TESTBR2" "$TESTREPO" bar && + + git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 >expected && + echo "git rev-parse HEAD" | test_env SHELL=/bin/sh $VCSH enter foo >output && + test_cmp expected output && + + git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1 >expected && + echo "git rev-parse HEAD" | test_env SHELL=/bin/sh $VCSH enter bar >output && + test_cmp expected output' + +test_done diff --git a/t/run-enter5.t b/t/run-enter5.t new file mode 100755 index 00000000..7c62db04 --- /dev/null +++ b/t/run-enter5.t @@ -0,0 +1,15 @@ +#!/bin/bash + +test_description='Run/enter commands' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Enter executes $SHELL inside repository' \ + '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && + + git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 >expected && + SHELL="git rev-parse HEAD" $VCSH enter foo >output && + test_cmp expected output' + +test_done diff --git a/t/run-enter6.t b/t/run-enter6.t new file mode 100755 index 00000000..72eed430 --- /dev/null +++ b/t/run-enter6.t @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='Run/enter commands' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Enter implied for single non-command argument' \ + '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && + $VCSH clone -b "$TESTBR2" "$TESTREPO" bar && + + git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 >expected && + echo "git rev-parse HEAD" | test_env SHELL=/bin/sh $VCSH foo >output && + test_cmp expected output && + + git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1 >expected && + echo "git rev-parse HEAD" | test_env SHELL=/bin/sh $VCSH bar >output && + test_cmp expected output' + +test_done diff --git a/t/run-enter7.t b/t/run-enter7.t new file mode 100755 index 00000000..9f552925 --- /dev/null +++ b/t/run-enter7.t @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='Run/enter commands' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +# BUG: enter does not pass on subshell's exit status +test_expect_failure 'Enter returns exit status of subshell' \ + '$VCSH init foo && + + echo "exit 104" | test_expect_code 104 test_env SHELL=/bin/sh $VCSH enter foo && + echo "exit 42" | test_expect_code 42 test_env SHELL=/bin/sh $VCSH enter foo && + echo "exit 93" | test_expect_code 93 test_env SHELL=/bin/sh $VCSH enter foo' + +test_done diff --git a/t/run-enter8.t b/t/run-enter8.t new file mode 100755 index 00000000..64de1f11 --- /dev/null +++ b/t/run-enter8.t @@ -0,0 +1,22 @@ +#!/bin/bash + +test_description='Run/enter commands' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Enter can be abbreviated (ente, ent, en)' \ + '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && + + # sed to repeat three times + git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 | sed "p;p" >expected && + + { + echo "git rev-parse HEAD" | SHELL=/bin/sh $VCSH ente foo && + echo "git rev-parse HEAD" | SHELL=/bin/sh $VCSH ent foo && + echo "git rev-parse HEAD" | SHELL=/bin/sh $VCSH en foo + } >output && + + test_cmp expected output' + +test_done From ead5a89bd0c30fff81339838b0683fd6b485de37 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 13 May 2017 01:09:34 -0500 Subject: [PATCH 077/151] convert pull tests --- t/pull.bats | 85 ----------------------------------------------------- t/pull0.t | 12 ++++++++ t/pull1.t | 16 ++++++++++ t/pull2.t | 19 ++++++++++++ t/pull3.t | 29 ++++++++++++++++++ t/pull4.t | 20 +++++++++++++ t/pull5.t | 20 +++++++++++++ 7 files changed, 116 insertions(+), 85 deletions(-) delete mode 100755 t/pull.bats create mode 100755 t/pull0.t create mode 100755 t/pull1.t create mode 100755 t/pull2.t create mode 100755 t/pull3.t create mode 100755 t/pull4.t create mode 100755 t/pull5.t diff --git a/t/pull.bats b/t/pull.bats deleted file mode 100755 index 03afd83f..00000000 --- a/t/pull.bats +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env bats - -load environment - -@test "pull works with no repositories" { - run $VCSH pull - assert "$status" -eq 0 - assert "$output" = "" -} - -@test "pull succeeds if up-to-date" { - git clone "$TESTREPO" upstream - - $VCSH clone upstream foo - run $VCSH pull - assert "$status" -eq 0 - assert "$output" = "foo: Already up-to-date." -} - -@test "pull works with one repository" { - git clone "$TESTREPO" upstream - - $VCSH clone upstream foo - git -C upstream commit --allow-empty -m 'empty' - run git -C upstream rev-parse HEAD - rev=$output - - $VCSH pull - run $VCSH foo rev-parse HEAD - assert "$status" -eq 0 - assert "$output" = "$rev" -} - -@test "pull works with multiple repositories" { - git clone -b "$TESTBR1" "$TESTREPO" upstream1 - git clone -b "$TESTBR2" "$TESTREPO" upstream2 - - $VCSH clone -b "$TESTBR1" upstream1 foo - $VCSH clone -b "$TESTBR2" upstream2 bar - - git -C upstream1 commit --allow-empty -m 'empty' - run git -C upstream1 rev-parse HEAD - rev1=$output - - git -C upstream2 commit --allow-empty -m 'empty' - run git -C upstream2 rev-parse HEAD - rev2=$output - - $VCSH pull - - run $VCSH foo rev-parse HEAD - assert "$status" -eq 0 - assert "$output" = "$rev1" - run $VCSH bar rev-parse HEAD - assert "$status" -eq 0 - assert "$output" = "$rev2" -} - -@test "pull fails if first pull fails" { - skip "BUG" - - git clone -b "$TESTBR1" "$TESTREPO" upstream1 - git clone -b "$TESTBR2" "$TESTREPO" upstream2 - - $VCSH clone -b "$TESTBR1" upstream1 a - $VCSH clone -b "$TESTBR2" upstream2 b - - rm -rf upstream1 - git -C upstream2 commit --allow-empty -m 'empty' - - ! $VCSH pull || false -} - -@test "pull fails if last pull fails" { - git clone -b "$TESTBR1" "$TESTREPO" upstream1 - git clone -b "$TESTBR2" "$TESTREPO" upstream2 - - $VCSH clone -b "$TESTBR1" upstream1 a - $VCSH clone -b "$TESTBR2" upstream2 b - - git -C upstream1 commit --allow-empty -m 'empty' - rm -rf upstream2 - - ! $VCSH pull || false -} diff --git a/t/pull0.t b/t/pull0.t new file mode 100755 index 00000000..68541057 --- /dev/null +++ b/t/pull0.t @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='Pull command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'pull works with no repositories' \ + '$VCSH pull >output && + test_must_be_empty output' + +test_done diff --git a/t/pull1.t b/t/pull1.t new file mode 100755 index 00000000..456cd7b2 --- /dev/null +++ b/t/pull1.t @@ -0,0 +1,16 @@ +#!/bin/bash + +test_description='Pull command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'pull succeeds if up-to-date' \ + 'git clone "$TESTREPO" upstream && + $VCSH clone upstream foo && + + echo -e "foo: Already up-to-date.\\n" >expected && + $VCSH pull >output && + test_cmp expected output' + +test_done diff --git a/t/pull2.t b/t/pull2.t new file mode 100755 index 00000000..28d9545d --- /dev/null +++ b/t/pull2.t @@ -0,0 +1,19 @@ +#!/bin/bash + +test_description='Pull command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'pull works with one repository' \ + 'git clone "$TESTREPO" upstream && + $VCSH clone upstream foo && + + git -C upstream commit --allow-empty -m "empty" && + git -C upstream rev-parse HEAD >expected && + + $VCSH pull && + $VCSH foo rev-parse HEAD >output && + test_cmp expected output' + +test_done diff --git a/t/pull3.t b/t/pull3.t new file mode 100755 index 00000000..54c56c4e --- /dev/null +++ b/t/pull3.t @@ -0,0 +1,29 @@ +#!/bin/bash + +test_description='Pull command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'pull works with multiple repositories' \ + 'git clone -b "$TESTBR1" "$TESTREPO" upstream1 && + git clone -b "$TESTBR2" "$TESTREPO" upstream2 && + + $VCSH clone -b "$TESTBR1" upstream1 foo && + $VCSH clone -b "$TESTBR2" upstream2 bar && + + git -C upstream1 commit --allow-empty -m "empty" && + git -C upstream1 rev-parse HEAD >expected && + + $VCSH pull && + $VCSH foo rev-parse HEAD >output && + test_cmp expected output && + + git -C upstream2 commit --allow-empty -m "empty2" && + git -C upstream2 rev-parse HEAD >expected && + + $VCSH pull && + $VCSH bar rev-parse HEAD >output && + test_cmp expected output' + +test_done diff --git a/t/pull4.t b/t/pull4.t new file mode 100755 index 00000000..66362fd1 --- /dev/null +++ b/t/pull4.t @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='Pull command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_failure 'pull fails if first pull fails' \ + 'git clone -b "$TESTBR1" "$TESTREPO" upstream1 && + git clone -b "$TESTBR2" "$TESTREPO" upstream2 && + + $VCSH clone -b "$TESTBR1" upstream1 a && + $VCSH clone -b "$TESTBR2" upstream2 b && + + rm -rf upstream1 && + git -C upstream2 commit --allow-empty -m "empty" && + + test_must_fail $VCSH pull' + +test_done diff --git a/t/pull5.t b/t/pull5.t new file mode 100755 index 00000000..21ec311a --- /dev/null +++ b/t/pull5.t @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='Pull command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'pull fails if last pull fails' \ + 'git clone -b "$TESTBR1" "$TESTREPO" upstream1 && + git clone -b "$TESTBR2" "$TESTREPO" upstream2 && + + $VCSH clone -b "$TESTBR1" upstream1 a && + $VCSH clone -b "$TESTBR2" upstream2 b && + + git -C upstream1 commit --allow-empty -m "empty" && + rm -rf upstream2 && + + test_must_fail $VCSH pull' + +test_done From 19604e72eb87cef4555fdb21dc3c22d854c1c387 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 13 May 2017 01:15:49 -0500 Subject: [PATCH 078/151] convert push tests --- t/push.bats | 94 ----------------------------------------------------- t/push0.t | 12 +++++++ t/push1.t | 18 ++++++++++ t/push2.t | 20 ++++++++++++ t/push3.t | 29 +++++++++++++++++ t/push4.t | 22 +++++++++++++ t/push5.t | 22 +++++++++++++ 7 files changed, 123 insertions(+), 94 deletions(-) delete mode 100755 t/push.bats create mode 100755 t/push0.t create mode 100755 t/push1.t create mode 100755 t/push2.t create mode 100755 t/push3.t create mode 100755 t/push4.t create mode 100755 t/push5.t diff --git a/t/push.bats b/t/push.bats deleted file mode 100755 index 2d0eb942..00000000 --- a/t/push.bats +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env bats - -load environment - -@test "push works with no repositories" { - run $VCSH push - assert "$status" -eq 0 - assert "$output" = "" -} - -@test "push succeeds if up-to-date" { - git clone --bare "$TESTREPO" upstream.git - - $VCSH clone upstream.git foo - $VCSH foo config push.default simple - run $VCSH push - assert "$status" -eq 0 - assert "$output" = "foo: Everything up-to-date" -} - -@test "push works with one repository" { - git clone --bare "$TESTREPO" upstream.git - - $VCSH clone upstream.git foo - $VCSH foo config push.default simple - $VCSH foo commit --allow-empty -m 'empty' - run $VCSH foo rev-parse HEAD - rev=$output - - $VCSH push - - run git -C upstream.git rev-parse HEAD - assert "$status" -eq 0 - assert "$output" = "$rev" -} - -@test "push works with multiple repositories" { - git clone --bare -b "$TESTBR1" "$TESTREPO" upstream1.git - git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git - - $VCSH clone -b "$TESTBR1" upstream1.git foo - $VCSH foo config push.default simple - $VCSH clone -b "$TESTBR2" upstream2.git bar - $VCSH bar config push.default simple - - $VCSH foo commit --allow-empty -m 'empty' - run $VCSH foo rev-parse HEAD - rev1=$output - - $VCSH bar commit --allow-empty -m 'empty' - run $VCSH bar rev-parse HEAD - rev2=$output - - $VCSH push - - run git -C upstream1.git rev-parse HEAD - assert "$status" -eq 0 - assert "$output" = "$rev1" - run git -C upstream2.git rev-parse HEAD - assert "$status" -eq 0 - assert "$output" = "$rev2" -} - -@test "push fails if first push fails" { - skip "BUG" - - git clone --bare -b "$TESTBR1" "$TESTREPO" upstream1.git - git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git - - $VCSH clone -b "$TESTBR1" upstream1.git a - $VCSH foo config push.default simple - $VCSH clone -b "$TESTBR2" upstream2.git b - $VCSH bar config push.default simple - - rm -rf upstream1.git - $VCSH b commit --allow-empty -m 'empty' - - ! $VCSH push || false -} - -@test "push fails if last push fails" { - git clone --bare -b "$TESTBR1" "$TESTREPO" upstream1.git - git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git - - $VCSH clone -b "$TESTBR1" upstream1.git a - $VCSH a config push.default simple - $VCSH clone -b "$TESTBR2" upstream2.git b - $VCSH b config push.default simple - - $VCSH a commit --allow-empty -m 'empty' - rm -rf upstream2.git - - ! $VCSH push || false -} diff --git a/t/push0.t b/t/push0.t new file mode 100755 index 00000000..4815fbcb --- /dev/null +++ b/t/push0.t @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='Push command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'push works with no repositories' \ + '$VCSH push &>output && + test_must_be_empty output' + +test_done diff --git a/t/push1.t b/t/push1.t new file mode 100755 index 00000000..2a2ee12b --- /dev/null +++ b/t/push1.t @@ -0,0 +1,18 @@ +#!/bin/bash + +test_description='Push command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'push succeeds if up-to-date' \ + 'git clone --bare "$TESTREPO" upstream.git && + + $VCSH clone upstream.git foo && + $VCSH foo config push.default simple && + + echo -e "foo: Everything up-to-date\\n" >expected && + $VCSH push &>output && + test_cmp expected output' + +test_done diff --git a/t/push2.t b/t/push2.t new file mode 100755 index 00000000..695385e3 --- /dev/null +++ b/t/push2.t @@ -0,0 +1,20 @@ +#!/bin/bash + +test_description='Push command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'push works with one repository' \ + 'git clone --bare "$TESTREPO" upstream.git && + + $VCSH clone upstream.git foo && + $VCSH foo config push.default simple && + $VCSH foo commit --allow-empty -m 'empty' && + $VCSH foo rev-parse HEAD >expected && + + $VCSH push && + git -C upstream.git rev-parse HEAD >output && + test_cmp expected output' + +test_done diff --git a/t/push3.t b/t/push3.t new file mode 100755 index 00000000..dd182c17 --- /dev/null +++ b/t/push3.t @@ -0,0 +1,29 @@ +#!/bin/bash + +test_description='Push command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'push works with multiple repositories' \ + 'git clone --bare -b "$TESTBR1" "$TESTREPO" upstream1.git && + git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git && + + $VCSH clone -b "$TESTBR1" upstream1.git foo && + $VCSH foo config push.default simple && + $VCSH clone -b "$TESTBR2" upstream2.git bar && + $VCSH bar config push.default simple && + + $VCSH foo commit --allow-empty -m 'empty' && + $VCSH bar commit --allow-empty -m 'empty' && + $VCSH push && + + $VCSH foo rev-parse HEAD >expected && + git -C upstream1.git rev-parse HEAD >output && + test_cmp expected output && + + $VCSH bar rev-parse HEAD >expected && + git -C upstream2.git rev-parse HEAD >output && + test_cmp expected output' + +test_done diff --git a/t/push4.t b/t/push4.t new file mode 100755 index 00000000..a0aa9b57 --- /dev/null +++ b/t/push4.t @@ -0,0 +1,22 @@ +#!/bin/bash + +test_description='Push command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_failure 'push fails if first push fails' \ + 'git clone --bare -b "$TESTBR1" "$TESTREPO" upstream1.git && + git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git && + + $VCSH clone -b "$TESTBR1" upstream1.git a && + $VCSH foo config push.default simple && + $VCSH clone -b "$TESTBR2" upstream2.git b && + $VCSH bar config push.default simple && + + rm -rf upstream1.git && + $VCSH b commit --allow-empty -m 'empty' && + + test_must_fail $VCSH push' + +test_done diff --git a/t/push5.t b/t/push5.t new file mode 100755 index 00000000..d47ed477 --- /dev/null +++ b/t/push5.t @@ -0,0 +1,22 @@ +#!/bin/bash + +test_description='Push command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'push fails if last push fails' \ + 'git clone --bare -b "$TESTBR1" "$TESTREPO" upstream1.git && + git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git && + + $VCSH clone -b "$TESTBR1" upstream1.git a && + $VCSH a config push.default simple && + $VCSH clone -b "$TESTBR2" upstream2.git b && + $VCSH b config push.default simple && + + $VCSH a commit --allow-empty -m 'empty' && + rm -rf upstream2.git && + + test_must_fail $VCSH push' + +test_done From 29c7ba428e65490d52b88d4ca2c6dbdf06e70721 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 13 May 2017 01:18:30 -0500 Subject: [PATCH 079/151] only list-untracked test so far --- t/list-untracked0.t | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100755 t/list-untracked0.t diff --git a/t/list-untracked0.t b/t/list-untracked0.t new file mode 100755 index 00000000..8db58da7 --- /dev/null +++ b/t/list-untracked0.t @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='List-untracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'list-untracked works with no repos' \ + '$VCSH list-untracked &>output && + test_must_be_empty output' + +test_done From fa58893eb1daa7af4482c88cb872265ccaeba6e7 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 13 May 2017 01:33:47 -0500 Subject: [PATCH 080/151] update list-tracked tests --- t/list-tracked.bats | 156 -------------------------------------------- t/list-tracked0.t | 12 ++++ t/list-tracked1.t | 14 ++++ t/list-tracked10.t | 11 ++++ t/list-tracked11.t | 11 ++++ t/list-tracked12.t | 32 +++++++++ t/list-tracked2.t | 11 ++++ t/list-tracked3.t | 15 +++++ t/list-tracked4.t | 22 +++++++ t/list-tracked5.t | 27 ++++++++ t/list-tracked6.t | 32 +++++++++ t/list-tracked7.t | 27 ++++++++ t/list-tracked8.t | 25 +++++++ t/list-tracked9.t | 29 ++++++++ 14 files changed, 268 insertions(+), 156 deletions(-) delete mode 100755 t/list-tracked.bats create mode 100755 t/list-tracked0.t create mode 100755 t/list-tracked1.t create mode 100755 t/list-tracked10.t create mode 100755 t/list-tracked11.t create mode 100755 t/list-tracked12.t create mode 100755 t/list-tracked2.t create mode 100755 t/list-tracked3.t create mode 100755 t/list-tracked4.t create mode 100755 t/list-tracked5.t create mode 100755 t/list-tracked6.t create mode 100755 t/list-tracked7.t create mode 100755 t/list-tracked8.t create mode 100755 t/list-tracked9.t diff --git a/t/list-tracked.bats b/t/list-tracked.bats deleted file mode 100755 index 28500c1e..00000000 --- a/t/list-tracked.bats +++ /dev/null @@ -1,156 +0,0 @@ -#!/usr/bin/env bats - -load environment - -@test "list-tracked works with no repos" { - run $VCSH list-tracked - assert "$status" -eq 0 - assert "$output" = "" -} - -@test "list-tracked command works with no repos and untracked files" { - touch a b c d e - - run $VCSH list-tracked - assert "$status" -eq 0 - assert "$output" = "" -} - -@test "list-tracked fails if argument is not a repo" { - skip "BUG" - - ! $VCSH list-tracked nope || false -} - -@test "list-tracked works on empty repo" { - touch a b c d e - - $VCSH init foo - run $VCSH list-tracked - assert "$status" -eq 0 - assert "$output" = "" -} - -@test "list-tracked lists files from one repo" { - $VCSH init foo - - touch a b c d e - $VCSH foo add a d - $VCSH foo commit -m 'a d' - - run $VCSH list-tracked - assert "$status" -eq 0 - assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/d")" -} - -@test "list-tracked lists files from two repos" { - $VCSH init foo - $VCSH init bar - - touch a b c d e - $VCSH foo add a b - $VCSH foo commit -m 'a b' - $VCSH bar add c d - $VCSH bar commit -m 'c d' - - run $VCSH list-tracked - assert "$status" -eq 0 - assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b" "$HOME/c" "$HOME/d")" -} - -@test "list-tracked lists files from specified repo" { - $VCSH init foo - $VCSH init bar - - touch a b c d e - $VCSH foo add a b - $VCSH foo commit -m 'a b' - $VCSH bar add c d - $VCSH bar commit -m 'c d' - - run $VCSH list-tracked foo - assert "$status" -eq 0 - assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" - - run $VCSH list-tracked bar - assert "$status" -eq 0 - assert "$output" = "$(printf '%s\n' "$HOME/c" "$HOME/d")" -} - -@test "list-tracked orders files by path" { - $VCSH init foo - $VCSH init bar - - touch a b c d e - $VCSH foo add a d - $VCSH foo commit -m 'a d' - $VCSH bar add b e - $VCSH bar commit -m 'b e' - - run $VCSH list-tracked - assert "$status" -eq 0 - assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b" "$HOME/d" "$HOME/e")" -} - -@test "list-tracked does not repeat multiple-tracked files" { - $VCSH init foo - $VCSH init bar - - touch a b - $VCSH foo add a b - $VCSH foo commit -m 'a b' - $VCSH bar add a b - $VCSH bar commit -m 'a b' - - run $VCSH list-tracked - assert "$status" -eq 0 - assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" -} - -@test "list-tracked accepts each repo for multiple-tracked files" { - $VCSH init foo - $VCSH init bar - - touch a b - $VCSH foo add a b - $VCSH foo commit -m 'a b' - $VCSH bar add a b - $VCSH bar commit -m 'a b' - - run $VCSH list-tracked foo - assert "$status" -eq 0 - assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" - - run $VCSH list-tracked bar - assert "$status" -eq 0 - assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" -} - -@test "list-tracked-by requires an argument" { - ! $VCSH list-tracked-by || false -} - -@test "list-tracked-by fails if argument is not a repo" { - skip "BUG" - - ! $VCSH list-tracked-by nope || false -} - -@test "list-tracked-by lists files from specified repo" { - $VCSH init foo - $VCSH init bar - - touch a b c d e - $VCSH foo add a b - $VCSH foo commit -m 'a b' - $VCSH bar add c d - $VCSH bar commit -m 'c d' - - run $VCSH list-tracked-by foo - assert "$status" -eq 0 - assert "$output" = "$(printf '%s\n' "$HOME/a" "$HOME/b")" - - run $VCSH list-tracked-by bar - assert "$status" -eq 0 - assert "$output" = "$(printf '%s\n' "$HOME/c" "$HOME/d")" -} diff --git a/t/list-tracked0.t b/t/list-tracked0.t new file mode 100755 index 00000000..abfae37e --- /dev/null +++ b/t/list-tracked0.t @@ -0,0 +1,12 @@ +#!/bin/bash + +test_description='List-tracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'list-tracked works with no repos' \ + '$VCSH list-tracked &>output && + test_must_be_empty output' + +test_done diff --git a/t/list-tracked1.t b/t/list-tracked1.t new file mode 100755 index 00000000..b69f244a --- /dev/null +++ b/t/list-tracked1.t @@ -0,0 +1,14 @@ +#!/bin/bash + +test_description='List-tracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'list-tracked command works with no repos and untracked files' \ + 'touch a b c d e && + + $VCSH list-tracked >output && + test_must_be_empty output' + +test_done diff --git a/t/list-tracked10.t b/t/list-tracked10.t new file mode 100755 index 00000000..d7c0688a --- /dev/null +++ b/t/list-tracked10.t @@ -0,0 +1,11 @@ +#!/bin/bash + +test_description='List-tracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'list-tracked-by requires an argument' \ + 'test_must_fail $VCSH list-tracked-by' + +test_done diff --git a/t/list-tracked11.t b/t/list-tracked11.t new file mode 100755 index 00000000..f5940e22 --- /dev/null +++ b/t/list-tracked11.t @@ -0,0 +1,11 @@ +#!/bin/bash + +test_description='List-tracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_failure 'list-tracked-by fails if argument is not a repo' \ + 'test_must_fail $VCSH list-tracked-by nope' + +test_done diff --git a/t/list-tracked12.t b/t/list-tracked12.t new file mode 100755 index 00000000..b683fb19 --- /dev/null +++ b/t/list-tracked12.t @@ -0,0 +1,32 @@ +#!/bin/bash + +test_description='List-tracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'list-tracked-by lists files from specified repo' \ + '$VCSH init foo && + $VCSH init bar && + + touch a b c d e && + $VCSH foo add a b && + $VCSH foo commit -m "a b" && + $VCSH bar add c d && + $VCSH bar commit -m "c d" && + + { + echo "$HOME/a" && + echo "$HOME/b" + } >expected && + $VCSH list-tracked-by foo >output && + test_cmp expected output && + + { + echo "$HOME/c" && + echo "$HOME/d" + } >expected && + $VCSH list-tracked-by bar >output && + test_cmp expected output' + +test_done diff --git a/t/list-tracked2.t b/t/list-tracked2.t new file mode 100755 index 00000000..4c023d97 --- /dev/null +++ b/t/list-tracked2.t @@ -0,0 +1,11 @@ +#!/bin/bash + +test_description='List-tracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_failure 'list-tracked fails if argument is not a repo' \ + 'test_must_fail $VCSH list-tracked nope' + +test_done diff --git a/t/list-tracked3.t b/t/list-tracked3.t new file mode 100755 index 00000000..d543026d --- /dev/null +++ b/t/list-tracked3.t @@ -0,0 +1,15 @@ +#!/bin/bash + +test_description='List-tracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'list-tracked works on empty repo' \ + 'touch a b c d e && + + $VCSH init foo && + $VCSH list-tracked >output && + test_must_be_empty output' + +test_done diff --git a/t/list-tracked4.t b/t/list-tracked4.t new file mode 100755 index 00000000..4545f74b --- /dev/null +++ b/t/list-tracked4.t @@ -0,0 +1,22 @@ +#!/bin/bash + +test_description='List-tracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'list-tracked lists files from one repo' \ + '$VCSH init foo && + + touch a b c d e && + $VCSH foo add a d && + $VCSH foo commit -m "a d" && + + { + echo "$HOME/a" && + echo "$HOME/d" + } >expected && + $VCSH list-tracked >output && + test_cmp expected output' + +test_done diff --git a/t/list-tracked5.t b/t/list-tracked5.t new file mode 100755 index 00000000..a7d17499 --- /dev/null +++ b/t/list-tracked5.t @@ -0,0 +1,27 @@ +#!/bin/bash + +test_description='List-tracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'list-tracked lists files from two repos' \ + '$VCSH init foo && + $VCSH init bar && + + touch a b c d e && + $VCSH foo add a b && + $VCSH foo commit -m "a b" && + $VCSH bar add c d && + $VCSH bar commit -m "c d" && + + { + echo "$HOME/a" && + echo "$HOME/b" && + echo "$HOME/c" && + echo "$HOME/d" + } >expected && + $VCSH list-tracked >output && + test_cmp expected output' + +test_done diff --git a/t/list-tracked6.t b/t/list-tracked6.t new file mode 100755 index 00000000..af40d958 --- /dev/null +++ b/t/list-tracked6.t @@ -0,0 +1,32 @@ +#!/bin/bash + +test_description='List-tracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'list-tracked lists files from specified repo' \ + '$VCSH init foo && + $VCSH init bar && + + touch a b c d e && + $VCSH foo add a b && + $VCSH foo commit -m "a b" && + $VCSH bar add c d && + $VCSH bar commit -m "c d" && + + { + echo "$HOME/a" && + echo "$HOME/b" + } >expected && + $VCSH list-tracked foo >output && + test_cmp expected output && + + { + echo "$HOME/c" && + echo "$HOME/d" + } >expected && + $VCSH list-tracked bar >output && + test_cmp expected output' + +test_done diff --git a/t/list-tracked7.t b/t/list-tracked7.t new file mode 100755 index 00000000..653373ec --- /dev/null +++ b/t/list-tracked7.t @@ -0,0 +1,27 @@ +#!/bin/bash + +test_description='List-tracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'list-tracked orders files by path' \ + '$VCSH init foo && + $VCSH init bar && + + touch a b c d e && + $VCSH foo add a d && + $VCSH foo commit -m "a d" && + $VCSH bar add b e && + $VCSH bar commit -m "b e" && + + { + echo "$HOME/a" && + echo "$HOME/b" && + echo "$HOME/d" && + echo "$HOME/e" + } >expected && + $VCSH list-tracked >output && + test_cmp expected output' + +test_done diff --git a/t/list-tracked8.t b/t/list-tracked8.t new file mode 100755 index 00000000..0665e40d --- /dev/null +++ b/t/list-tracked8.t @@ -0,0 +1,25 @@ +#!/bin/bash + +test_description='List-tracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'list-tracked does not repeat multiple-tracked files' \ + '$VCSH init foo && + $VCSH init bar && + + touch a b && + $VCSH foo add a b && + $VCSH foo commit -m "a b" && + $VCSH bar add a b && + $VCSH bar commit -m "a b" && + + { + echo "$HOME/a" && + echo "$HOME/b" + } >expected && + $VCSH list-tracked >output && + test_cmp expected output' + +test_done diff --git a/t/list-tracked9.t b/t/list-tracked9.t new file mode 100755 index 00000000..65eb50f3 --- /dev/null +++ b/t/list-tracked9.t @@ -0,0 +1,29 @@ +#!/bin/bash + +test_description='List-tracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'list-tracked accepts each repo for multiple-tracked files' \ + '$VCSH init foo && + $VCSH init bar && + + touch a b && + $VCSH foo add a b && + $VCSH foo commit -m "a b" && + $VCSH bar add a b && + $VCSH bar commit -m "a b" && + + { + echo "$HOME/a" && + echo "$HOME/b" + } >expected && + + $VCSH list-tracked foo >output && + test_cmp expected output && + + $VCSH list-tracked bar >output && + test_cmp expected output' + +test_done From 31245c269d047967dd0e99e790a9de3928af325e Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 15 May 2017 11:03:26 -0500 Subject: [PATCH 081/151] fix commit test #3 --- t/commit.t | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/t/commit.t b/t/commit.t index d1ad56d0..46f429b8 100755 --- a/t/commit.t +++ b/t/commit.t @@ -52,10 +52,7 @@ load environment touch a b $VCSH foo add a $VCSH bar add b - run $VCSH commit -m 'log message' - assert "$status" -eq 0 - # XXX Is printing a trailing space and blank line really intended? - assert "$output" = "$(printf 'bar: \n\nfoo: ')" + $VCSH commit -m 'log message' $VCSH foo log --oneline | assert_grep -x '....... log message' $VCSH bar log --oneline | assert_grep -x '....... log message' From 9241d646eeaea06440fb39da2e10ca932ce3328e Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 15 May 2017 11:08:41 -0500 Subject: [PATCH 082/151] use test-lib idiom for help abbrev test --- t/help.t | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/t/help.t b/t/help.t index 86cc6264..715507ea 100755 --- a/t/help.t +++ b/t/help.t @@ -18,11 +18,11 @@ test_expect_success 'Help command prints usage on first line' \ assert_grep "^usage: "' test_expect_failure 'Help command can be abbreviated (hel, he)' \ - 'good="$($VCSH help 2>&1)" && - output1=$($VCSH hel 2>&1)" && - assert "$output1" = "$good" && - output2=$($VCSH he 2>&1)" && - assert "$output2" = "$good"' + '$VCSH help >expected 2>&1 && + $VCSH hel >output 2>&1 && + test_cmp expected output && + $VCSH he >output 2>&1 && + test_cmp expected output' # Help should explain each non-deprecated command. (Note: adjust this if the # format of help output changes.) From 46621d2633ff64a68e950f560784e41ba46094f4 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 15 May 2017 11:10:05 -0500 Subject: [PATCH 083/151] fix expected output on commit tests --- t/commit1.t | 1 + t/commit2.t | 1 + 2 files changed, 2 insertions(+) diff --git a/t/commit1.t b/t/commit1.t index b515fd4a..b40dc4f2 100755 --- a/t/commit1.t +++ b/t/commit1.t @@ -13,6 +13,7 @@ test_expect_failure 'commit works with single repo' \ $VCSH foo add a && # XXX Is printing a trailing space really intended? echo "foo: " >expected && + echo "" >>expected && $VCSH commit -m a >output && test_cmp expected output && diff --git a/t/commit2.t b/t/commit2.t index 889995c9..ce0248e5 100755 --- a/t/commit2.t +++ b/t/commit2.t @@ -17,6 +17,7 @@ test_expect_failure 'commit works with multiple repos' \ echo "bar: " >expected && echo "" >>expected && echo "foo: " >>expected && + echo "" >>expected && $VCSH commit -m "ab" >output && test_cmp expected output && From 74b631b8e1a318a088835afe5e2839d5ef60fe52 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 15 May 2017 16:32:30 -0500 Subject: [PATCH 084/151] remove remaining \$ in test descriptions --- t/commit5.t | 2 +- t/list9.t | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/t/commit5.t b/t/commit5.t index d81b7ea2..b42b0e3b 100755 --- a/t/commit5.t +++ b/t/commit5.t @@ -6,7 +6,7 @@ test_description='Commit command' . "$TEST_DIRECTORY/environment.bash" # Known bug -test_expect_failure 'commit not affected by existing \$VCSH_COMMAND_RETURN_CODE' \ +test_expect_failure 'commit not affected by existing $VCSH_COMMAND_RETURN_CODE' \ 'VCSH_COMMAND_RETURN_CODE=1 && export VCSH_COMMAND_RETURN_CODE && $VCSH commit' diff --git a/t/list9.t b/t/list9.t index 7e8b0d90..1fb39eb2 100755 --- a/t/list9.t +++ b/t/list9.t @@ -5,7 +5,7 @@ test_description='List command' . ./test-lib.sh . "$TEST_DIRECTORY/environment.bash" -test_expect_success 'List command prioritizes \$VCSH_REPO_D over \$XDG_CONFIG_HOME' \ +test_expect_success 'List command prioritizes $VCSH_REPO_D over $XDG_CONFIG_HOME' \ 'test_env XDG_CONFIG_HOME="$PWD/foo" $VCSH init correct && test_env XDG_CONFIG_HOME="$PWD/bar" $VCSH init wrong && From 59c131aa31e1240b6ca31dea2ebc5baaa82c36c7 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 15 May 2017 16:55:46 -0500 Subject: [PATCH 085/151] fix testing for failed pushes --- t/push4.t | 7 ++++--- t/push5.t | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/t/push4.t b/t/push4.t index a0aa9b57..904c2b42 100755 --- a/t/push4.t +++ b/t/push4.t @@ -10,13 +10,14 @@ test_expect_failure 'push fails if first push fails' \ git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git && $VCSH clone -b "$TESTBR1" upstream1.git a && - $VCSH foo config push.default simple && + $VCSH a config push.default simple && $VCSH clone -b "$TESTBR2" upstream2.git b && - $VCSH bar config push.default simple && + $VCSH b config push.default simple && - rm -rf upstream1.git && + $VCSH a commit --allow-empty -m 'empty' && $VCSH b commit --allow-empty -m 'empty' && + rm -rf upstream1.git && test_must_fail $VCSH push' test_done diff --git a/t/push5.t b/t/push5.t index d47ed477..7b906903 100755 --- a/t/push5.t +++ b/t/push5.t @@ -15,8 +15,9 @@ test_expect_success 'push fails if last push fails' \ $VCSH b config push.default simple && $VCSH a commit --allow-empty -m 'empty' && - rm -rf upstream2.git && + $VCSH b commit --allow-empty -m 'empty' && + rm -rf upstream2.git && test_must_fail $VCSH push' test_done From 4d196836950f8c4e50858678527e26800fe5140f Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 15 May 2017 17:06:02 -0500 Subject: [PATCH 086/151] finish switching .sh to .t in test-lib.sh --- t/test-lib.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index 2a50a33a..e2a58410 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -54,7 +54,7 @@ done,*) ;; *' --tee '*|*' --va'*|*' --verbose-log '*) mkdir -p "$TEST_OUTPUT_DIRECTORY/test-results" - BASE="$TEST_OUTPUT_DIRECTORY/test-results/$(basename "$0" .sh)" + BASE="$TEST_OUTPUT_DIRECTORY/test-results/$(basename "$0" .t)" # Make this filename available to the sub-process in case it is using # --verbose-log. @@ -693,7 +693,7 @@ test_done () { test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results" mkdir -p "$test_results_dir" base=${0##*/} - test_results_path="$test_results_dir/${base%.sh}.counts" + test_results_path="$test_results_dir/${base%.t}.counts" cat >"$test_results_path" <<-EOF total $test_count From d9cbd2944013c235a38e19b334e3bb9b5e31c185 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 15 May 2017 17:06:14 -0500 Subject: [PATCH 087/151] allow `make test TEST_ARGS=...' --- t/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/Makefile b/t/Makefile index cccf7c63..a3ff8ec7 100644 --- a/t/Makefile +++ b/t/Makefile @@ -7,4 +7,4 @@ test-prereq: @if ! which prove > /dev/null; then echo "'prove' not found; not running tests"; exit 1; fi test: test-prereq - prove $(filter -j%,$(MAKEFLAGS)) --timer *.t + prove $(filter -j%,$(MAKEFLAGS)) --timer *.t :: $(TEST_ARGS) From eceaf4572d60e737703e79236058eae9e4070509 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 16 May 2017 00:27:43 -0500 Subject: [PATCH 088/151] remove extra templates argument in test-lib --- t/test-lib-functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 5ee12433..6f77d307 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -791,7 +791,7 @@ test_create_repo () { mkdir -p "$repo" ( cd "$repo" || error "Cannot setup test environment" - "$GIT_EXEC_PATH/git-init" "--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 || + "$GIT_EXEC_PATH/git-init" >&3 2>&4 || error "cannot run git init -- have you built things yet?" mv .git/hooks .git/hooks-disabled ) || exit From 66f64cc5e365bf35de3d9cc14fdb734645682e95 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 16 May 2017 00:29:37 -0500 Subject: [PATCH 089/151] touch-ups to test-lib --- t/test-lib.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index e2a58410..7e54d1ea 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -40,7 +40,7 @@ GIT_BUILD_DIR="$TEST_DIRECTORY"/.. # It appears that people try to run tests without building... if ! test -x "$GIT_BUILD_DIR/vcsh" then - echo >&2 'error: you do not seem to have built git yet.' + echo >&2 'error: you do not seem to have vcsh here.' exit 1 fi @@ -773,9 +773,6 @@ then fi fi -GITPERLLIB="$GIT_BUILD_DIR"/perl/blib/lib:"$GIT_BUILD_DIR"/perl/blib/arch/auto/Git -export GITPERLLIB - # Test repository TRASH_DIRECTORY="trash directory.$(basename "$0" .t)" test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY" From 0cd5916841e56f09e775ab2aab87e119db1c8b87 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 16 May 2017 00:32:54 -0500 Subject: [PATCH 090/151] rename4: remove dependency on TESTREPO --- t/rename4.t | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/t/rename4.t b/t/rename4.t index 97ebdb8e..6c59238e 100755 --- a/t/rename4.t +++ b/t/rename4.t @@ -6,9 +6,12 @@ test_description='Rename command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Rename works on repository with files/commits' \ - '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && - git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 >expected && + 'test_create_repo repo && + test_commit -C repo A && + test_commit -C repo B && + git -C repo rev-parse HEAD >expected && + $VCSH clone ./repo foo && $VCSH rename foo bar && $VCSH bar rev-parse HEAD >output && test_cmp expected output' From 440ffcb2872a63e41e259599b2fed7919b937adc Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 16 May 2017 00:34:30 -0500 Subject: [PATCH 091/151] list3: remove dependency on TESTREPO --- t/list3.t | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/t/list3.t b/t/list3.t index b6ab1a06..988dd3ee 100755 --- a/t/list3.t +++ b/t/list3.t @@ -6,8 +6,12 @@ test_description='List command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'List command displays cloned repository' \ - '$VCSH clone "$TESTREPO" test2 && - echo test2 >expected && + 'test_create_repo repo && + test_commit -C repo A && + test_commit -C repo B && + + $VCSH clone ./repo foo && + echo foo >expected && $VCSH list >output && test_cmp expected output' From 8fb934d6383e8b06b04c94c246949ca52480b7b1 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 16 May 2017 00:48:21 -0500 Subject: [PATCH 092/151] recombine run-enter, remove TESTREPO dependency --- t/run-enter.t | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ t/run-enter0.t | 20 ------------ t/run-enter1.t | 20 ------------ t/run-enter2.t | 15 --------- t/run-enter3.t | 15 --------- t/run-enter4.t | 20 ------------ t/run-enter5.t | 15 --------- t/run-enter6.t | 20 ------------ t/run-enter7.t | 16 ---------- t/run-enter8.t | 22 ------------- 10 files changed, 85 insertions(+), 163 deletions(-) create mode 100755 t/run-enter.t delete mode 100755 t/run-enter0.t delete mode 100755 t/run-enter1.t delete mode 100755 t/run-enter2.t delete mode 100755 t/run-enter3.t delete mode 100755 t/run-enter4.t delete mode 100755 t/run-enter5.t delete mode 100755 t/run-enter6.t delete mode 100755 t/run-enter7.t delete mode 100755 t/run-enter8.t diff --git a/t/run-enter.t b/t/run-enter.t new file mode 100755 index 00000000..bfd2e317 --- /dev/null +++ b/t/run-enter.t @@ -0,0 +1,85 @@ +#!/bin/bash + +test_description='Run/enter commands' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Setup' \ + 'test_create_repo repo1 && + test_create_repo repo2 && + test_commit -C repo1 A && + test_commit -C repo2 B && + + $VCSH clone ./repo1 foo && + $VCSH clone ./repo2 bar' + +test_expect_success 'Run executes command inside specific repository' \ + 'git -C repo1 rev-parse HEAD >expected && + $VCSH run foo git rev-parse HEAD >output && + test_cmp expected output && + + git -C repo2 rev-parse HEAD >expected && + $VCSH run bar git rev-parse HEAD >output && + test_cmp expected output' + +test_expect_success 'Run implied if no explicit command specified' \ + 'git -C repo1 rev-parse HEAD >expected && + $VCSH foo rev-parse HEAD >output && + test_cmp expected output && + + git -C repo2 rev-parse HEAD >expected && + $VCSH bar rev-parse HEAD >output && + test_cmp expected output' + +test_expect_success 'Run can be abbreviated (ru)' \ + 'git -C repo1 rev-parse HEAD >expected && + $VCSH ru foo git rev-parse HEAD >output && + test_cmp expected output' + +test_expect_success 'Run returns exit status of subcommand' \ + 'test_expect_code 104 $VCSH run foo sh -c "exit 104" && + test_expect_code 42 $VCSH run foo sh -c "exit 42" && + test_expect_code 93 $VCSH run foo sh -c "exit 93"' + +test_expect_success 'Enter executes inside specific repository' \ + 'git -C repo1 rev-parse HEAD >expected && + echo "git rev-parse HEAD" | test_env SHELL=/bin/sh $VCSH enter foo >output && + test_cmp expected output && + + git -C repo2 rev-parse HEAD >expected && + echo "git rev-parse HEAD" | test_env SHELL=/bin/sh $VCSH enter bar >output && + test_cmp expected output' + +test_expect_success 'Enter executes $SHELL inside repository' \ + 'git -C repo1 rev-parse HEAD >expected && + SHELL="git rev-parse HEAD" $VCSH enter foo >output && + test_cmp expected output' + +test_expect_success 'Enter implied for single non-command argument' \ + 'git -C repo1 rev-parse HEAD >expected && + echo "git rev-parse HEAD" | test_env SHELL=/bin/sh $VCSH foo >output && + test_cmp expected output && + + git -C repo2 rev-parse HEAD >expected && + echo "git rev-parse HEAD" | test_env SHELL=/bin/sh $VCSH bar >output && + test_cmp expected output' + +# BUG: enter does not pass on subshell's exit status +test_expect_failure 'Enter returns exit status of subshell' \ + 'echo "exit 104" | test_expect_code 104 test_env SHELL=/bin/sh $VCSH enter foo && + echo "exit 42" | test_expect_code 42 test_env SHELL=/bin/sh $VCSH enter foo && + echo "exit 93" | test_expect_code 93 test_env SHELL=/bin/sh $VCSH enter foo' + +test_expect_success 'Enter can be abbreviated (ente, ent, en)' \ + 'git -C repo1 rev-parse HEAD HEAD HEAD >expected && + + { + echo "git rev-parse HEAD" | SHELL=/bin/sh $VCSH ente foo && + echo "git rev-parse HEAD" | SHELL=/bin/sh $VCSH ent foo && + echo "git rev-parse HEAD" | SHELL=/bin/sh $VCSH en foo + } >output && + + test_cmp expected output' + +test_done diff --git a/t/run-enter0.t b/t/run-enter0.t deleted file mode 100755 index dcb4db02..00000000 --- a/t/run-enter0.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Run/enter commands' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Run executes command inside specific repository' \ - '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && - $VCSH clone -b "$TESTBR2" "$TESTREPO" bar && - - git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 >expected && - $VCSH run foo git rev-parse HEAD >output && - test_cmp expected output && - - git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1 >expected && - $VCSH run bar git rev-parse HEAD >output && - test_cmp expected output' - -test_done diff --git a/t/run-enter1.t b/t/run-enter1.t deleted file mode 100755 index 22751cd3..00000000 --- a/t/run-enter1.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Run/enter commands' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Run implied if no explicit command specified' \ - '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && - $VCSH clone -b "$TESTBR2" "$TESTREPO" bar && - - git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 >expected && - $VCSH foo rev-parse HEAD >output && - test_cmp expected output && - - git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1 >expected && - $VCSH bar rev-parse HEAD >output && - test_cmp expected output' - -test_done diff --git a/t/run-enter2.t b/t/run-enter2.t deleted file mode 100755 index 0de048ef..00000000 --- a/t/run-enter2.t +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -test_description='Run/enter commands' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Run can be abbreviated (ru)' \ - '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && - - git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 >expected && - $VCSH ru foo git rev-parse HEAD >output && - test_cmp expected output' - -test_done diff --git a/t/run-enter3.t b/t/run-enter3.t deleted file mode 100755 index 21ffb6ef..00000000 --- a/t/run-enter3.t +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -test_description='Run/enter commands' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Run returns exit status of subcommand' \ - '$VCSH init foo && - - test_expect_code 104 $VCSH run foo sh -c "exit 104" && - test_expect_code 42 $VCSH run foo sh -c "exit 42" && - test_expect_code 93 $VCSH run foo sh -c "exit 93"' - -test_done diff --git a/t/run-enter4.t b/t/run-enter4.t deleted file mode 100755 index 3391edd2..00000000 --- a/t/run-enter4.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Run/enter commands' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Enter executes inside specific repository' \ - '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && - $VCSH clone -b "$TESTBR2" "$TESTREPO" bar && - - git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 >expected && - echo "git rev-parse HEAD" | test_env SHELL=/bin/sh $VCSH enter foo >output && - test_cmp expected output && - - git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1 >expected && - echo "git rev-parse HEAD" | test_env SHELL=/bin/sh $VCSH enter bar >output && - test_cmp expected output' - -test_done diff --git a/t/run-enter5.t b/t/run-enter5.t deleted file mode 100755 index 7c62db04..00000000 --- a/t/run-enter5.t +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -test_description='Run/enter commands' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Enter executes $SHELL inside repository' \ - '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && - - git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 >expected && - SHELL="git rev-parse HEAD" $VCSH enter foo >output && - test_cmp expected output' - -test_done diff --git a/t/run-enter6.t b/t/run-enter6.t deleted file mode 100755 index 72eed430..00000000 --- a/t/run-enter6.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Run/enter commands' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Enter implied for single non-command argument' \ - '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && - $VCSH clone -b "$TESTBR2" "$TESTREPO" bar && - - git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 >expected && - echo "git rev-parse HEAD" | test_env SHELL=/bin/sh $VCSH foo >output && - test_cmp expected output && - - git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1 >expected && - echo "git rev-parse HEAD" | test_env SHELL=/bin/sh $VCSH bar >output && - test_cmp expected output' - -test_done diff --git a/t/run-enter7.t b/t/run-enter7.t deleted file mode 100755 index 9f552925..00000000 --- a/t/run-enter7.t +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -test_description='Run/enter commands' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -# BUG: enter does not pass on subshell's exit status -test_expect_failure 'Enter returns exit status of subshell' \ - '$VCSH init foo && - - echo "exit 104" | test_expect_code 104 test_env SHELL=/bin/sh $VCSH enter foo && - echo "exit 42" | test_expect_code 42 test_env SHELL=/bin/sh $VCSH enter foo && - echo "exit 93" | test_expect_code 93 test_env SHELL=/bin/sh $VCSH enter foo' - -test_done diff --git a/t/run-enter8.t b/t/run-enter8.t deleted file mode 100755 index 64de1f11..00000000 --- a/t/run-enter8.t +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -test_description='Run/enter commands' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Enter can be abbreviated (ente, ent, en)' \ - '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && - - # sed to repeat three times - git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 | sed "p;p" >expected && - - { - echo "git rev-parse HEAD" | SHELL=/bin/sh $VCSH ente foo && - echo "git rev-parse HEAD" | SHELL=/bin/sh $VCSH ent foo && - echo "git rev-parse HEAD" | SHELL=/bin/sh $VCSH en foo - } >output && - - test_cmp expected output' - -test_done From d6f6fc74ce3cc5942a2de2be805f735cdb3e7847 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 16 May 2017 00:59:54 -0500 Subject: [PATCH 093/151] condense status tests --- t/status.t | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++ t/status0.t | 11 ----- t/status1.t | 12 ----- t/status10.t | 26 ----------- t/status11.t | 20 --------- t/status2.t | 16 ------- t/status3.t | 19 -------- t/status4.t | 14 ------ t/status5.t | 15 ------- t/status6.t | 59 ------------------------ t/status7.t | 12 ----- t/status8.t | 12 ----- t/status9.t | 12 ----- 13 files changed, 125 insertions(+), 228 deletions(-) create mode 100755 t/status.t delete mode 100755 t/status0.t delete mode 100755 t/status1.t delete mode 100755 t/status10.t delete mode 100755 t/status11.t delete mode 100755 t/status2.t delete mode 100755 t/status3.t delete mode 100755 t/status4.t delete mode 100755 t/status5.t delete mode 100755 t/status6.t delete mode 100755 t/status7.t delete mode 100755 t/status8.t delete mode 100755 t/status9.t diff --git a/t/status.t b/t/status.t new file mode 100755 index 00000000..af77bf45 --- /dev/null +++ b/t/status.t @@ -0,0 +1,125 @@ +#!/bin/bash + +test_description='Status command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Status argument if any must be a repo' \ + 'test_must_fail $VCSH status nope' + +test_expect_success 'Status command correct for no repos' \ + '$VCSH status >output && + test_must_be_empty output' + +test_expect_success 'Status command correct for empty repo' \ + '$VCSH init foo && + + echo "foo:" >expected && + echo "" >>expected && + $VCSH status >output && + test_cmp expected output' + +test_expect_success 'Terse status correct for empty repo' \ + '$VCSH status --terse >output && + test_must_be_empty output' + +test_expect_success 'Check for socat (needed for pseudo-tty)' \ + 'if which socat; then + test_set_prereq SOCAT + fi' + +test_expect_success SOCAT 'Status colored when output to tty' \ + 'touch a && + $VCSH run foo git add a && + $VCSH run foo git config --local color.status.added green && + + # Ensure terminal is something Git will attempt to color + TERM=vt100 && + export TERM && + printf "\\e[32mA\\e[m a\n" >expected && + socat -u exec:"$VCSH status foo",pty,rawer stdio >output && + test_cmp expected output' + +test_expect_success 'Delete/recreate repository' \ + 'doit | $VCSH delete foo && + $VCSH init foo' + +test_expect_success 'Status command correct for multiple empty repos' \ + '$VCSH init bar && + + echo "bar:" >expected && + echo "" >>expected && + echo "foo:" >>expected && + echo "" >>expected && + $VCSH status >output && + test_cmp expected output' + +test_expect_success 'Terse status correct for multiple empty repos' \ + '$VCSH status --terse >output && + test_must_be_empty output' + +test_expect_success 'Status shows added/modified/moved/deleted files' \ + 'for f in 00 0M 0D M0 MM MD A0 AM AD D0 R0x RMx RDx oo; do + echo "$f" > "$f" + done && + $VCSH foo add 00 0M 0D M0 MM MD D0 R0x RMx RDx && + $VCSH foo commit -m "commit" && + + # Modified in index + for f in M?; do + echo changed > $f + done && + $VCSH foo add M? && + + # Added to index + $VCSH foo add A? && + + # Deleted in index + $VCSH foo rm -q --cached D? && + + # Renamed in index + for f in R?x; do + $VCSH foo mv "$f" "${f%x}" + done && + + # Modified locally + for f in ?M; do + echo localchanged > $f + done && + + # Deleted locally + rm ?D && + + echo "bar:" >expected && + echo "" >>expected && + echo "foo:" >>expected && + echo " D 0D" >>expected && + echo " M 0M" >>expected && + echo "A A0" >>expected && + echo "AD AD" >>expected && + echo "AM AM" >>expected && + echo "D D0" >>expected && + echo "M M0" >>expected && + echo "MD MD" >>expected && + echo "MM MM" >>expected && + echo "R R0x -> R0" >>expected && + echo "RD RDx -> RD" >>expected && + echo "RM RMx -> RM" >>expected && + echo "" >>expected && + $VCSH status >output && + test_cmp expected output' + +test_expect_success 'Status can be abbreviated (statu, stat, sta, st)' \ + '$VCSH status >expected && + + for cmd in statu stat sta st; do + $VCSH $cmd >output && + test_cmp expected output + done' + +#test_expect_success 'Status shows commits behind upstream' +#test_expect_success 'Status shows commits ahead of upstream' +#test_expect_success 'Status shows commits behind and ahead of upstream' + +test_done diff --git a/t/status0.t b/t/status0.t deleted file mode 100755 index 3e7300a8..00000000 --- a/t/status0.t +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -test_description='Status command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Status argument if any must be a repo' \ - 'test_must_fail $VCSH status nope' - -test_done diff --git a/t/status1.t b/t/status1.t deleted file mode 100755 index f4ca892c..00000000 --- a/t/status1.t +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -test_description='Status command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Status command correct for no repos' \ - '$VCSH status >output && - test_must_be_empty output' - -test_done diff --git a/t/status10.t b/t/status10.t deleted file mode 100755 index d951861d..00000000 --- a/t/status10.t +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -test_description='Status command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Check for socat (needed for pseudo-tty)' \ - 'if which socat; then - test_set_prereq SOCAT - fi' - -test_expect_success SOCAT 'Status colored when output to tty' \ - '$VCSH init foo && - touch a && - $VCSH run foo git add a && - $VCSH run foo git config --local color.status.added green && - - # Ensure terminal is something Git will attempt to color - TERM=vt100 && - export TERM && - printf "\\e[32mA\\e[m a\n" >expected && - socat -u exec:"$VCSH status foo",pty,rawer stdio >output && - test_cmp expected output' - -test_done diff --git a/t/status11.t b/t/status11.t deleted file mode 100755 index e80c88a8..00000000 --- a/t/status11.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Status command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Status can be abbreviated (statu, stat, sta, st)' \ - '$VCSH init foo && - touch a && - $VCSH foo add a && - - $VCSH status >expected && - - for cmd in statu stat sta st; do - $VCSH $cmd >output && - test_cmp expected output - done' - -test_done diff --git a/t/status2.t b/t/status2.t deleted file mode 100755 index f46f54d0..00000000 --- a/t/status2.t +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -test_description='Status command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Status command correct for empty repo' \ - '$VCSH init foo && - - echo "foo:" >expected && - echo "" >>expected && - $VCSH status >output && - test_cmp expected output' - -test_done diff --git a/t/status3.t b/t/status3.t deleted file mode 100755 index b4338e61..00000000 --- a/t/status3.t +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -test_description='Status command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Status command correct for multiple empty repos' \ - '$VCSH init foo && - $VCSH init bar && - - echo "bar:" >expected && - echo "" >>expected && - echo "foo:" >>expected && - echo "" >>expected && - $VCSH status >output && - test_cmp expected output' - -test_done diff --git a/t/status4.t b/t/status4.t deleted file mode 100755 index 09c3b383..00000000 --- a/t/status4.t +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -test_description='Status command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Terse status correct for empty repo' \ - '$VCSH init foo && - - $VCSH status --terse >output && - test_must_be_empty output' - -test_done diff --git a/t/status5.t b/t/status5.t deleted file mode 100755 index a783cd31..00000000 --- a/t/status5.t +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -test_description='Status command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Terse status correct for multiple empty repos' \ - '$VCSH init foo && - $VCSH init bar && - - $VCSH status --terse >output && - test_must_be_empty output' - -test_done diff --git a/t/status6.t b/t/status6.t deleted file mode 100755 index d2877141..00000000 --- a/t/status6.t +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -test_description='Status command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Status shows added/modified/moved/deleted files' \ - '$VCSH init foo && - - for f in 00 0M 0D M0 MM MD A0 AM AD D0 R0x RMx RDx oo; do - echo "$f" > "$f" - done && - $VCSH foo add 00 0M 0D M0 MM MD D0 R0x RMx RDx && - $VCSH foo commit -m "commit" && - - # Modified in index - for f in M?; do - echo changed > $f - done && - $VCSH foo add M? && - - # Added to index - $VCSH foo add A? && - - # Deleted in index - $VCSH foo rm -q --cached D? && - - # Renamed in index - for f in R?x; do - $VCSH foo mv "$f" "${f%x}" - done && - - # Modified locally - for f in ?M; do - echo localchanged > $f - done && - - # Deleted locally - rm ?D && - - echo "foo:" >expected && - echo " D 0D" >>expected && - echo " M 0M" >>expected && - echo "A A0" >>expected && - echo "AD AD" >>expected && - echo "AM AM" >>expected && - echo "D D0" >>expected && - echo "M M0" >>expected && - echo "MD MD" >>expected && - echo "MM MM" >>expected && - echo "R R0x -> R0" >>expected && - echo "RD RDx -> RD" >>expected && - echo "RM RMx -> RM" >>expected && - echo "" >>expected && - $VCSH status >output && - test_cmp expected output' - -test_done diff --git a/t/status7.t b/t/status7.t deleted file mode 100755 index 0cd83780..00000000 --- a/t/status7.t +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -test_description='Status command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_failure 'Status shows commits behind upstream' \ - '# Test not yet implemented - false' - -test_done diff --git a/t/status8.t b/t/status8.t deleted file mode 100755 index 429eefd9..00000000 --- a/t/status8.t +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -test_description='Status command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_failure 'Status shows commits ahead of upstream' \ - '# Test not yet implemented - false' - -test_done diff --git a/t/status9.t b/t/status9.t deleted file mode 100755 index b85fae2c..00000000 --- a/t/status9.t +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -test_description='Status command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_failure 'Status shows commits behind and ahead of upstream' \ - '# Test not yet implemented - false' - -test_done From 4013942db0cd9f15d610d2bc6acd8096012a4b6e Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Wed, 17 May 2017 03:17:47 -0500 Subject: [PATCH 094/151] remove foreach dependency on TESTREPO --- t/foreach2.t | 12 ++++++++---- t/foreach3.t | 8 ++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/t/foreach2.t b/t/foreach2.t index a33dd5dc..74184eec 100755 --- a/t/foreach2.t +++ b/t/foreach2.t @@ -6,14 +6,18 @@ test_description='Foreach command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Foreach executes Git command inside each repository' \ - '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && - $VCSH clone -b "$TESTBR2" "$TESTREPO" bar && + 'test_create_repo repo1 && + test_commit -C repo1 A && + test_create_repo repo2 && + test_commit -C repo2 B && + $VCSH clone ./repo1 foo && + $VCSH clone ./repo2 bar && { echo "bar:" && - git ls-remote "$TESTREPO" "refs/heads/$TESTBR2" | cut -f 1 && + git -C repo2 rev-parse HEAD && echo "foo:" && - git ls-remote "$TESTREPO" "refs/heads/$TESTBR1" | cut -f 1 + git -C repo1 rev-parse HEAD } >expected && $VCSH foreach rev-parse HEAD >output && diff --git a/t/foreach3.t b/t/foreach3.t index dffaa4d1..a9b9f8ce 100755 --- a/t/foreach3.t +++ b/t/foreach3.t @@ -6,8 +6,12 @@ test_description='Foreach command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Foreach supports -g for non-Git commands' \ - '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && - $VCSH clone -b "$TESTBR2" "$TESTREPO" bar && + 'test_create_repo repo1 && + test_commit -C repo1 A && + test_create_repo repo2 && + test_commit -C repo2 B && + $VCSH clone ./repo1 foo && + $VCSH clone ./repo2 bar && { echo "bar:" && From d714f07a681152ab51ad031d24cd5416739a9f2f Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Wed, 17 May 2017 03:26:02 -0500 Subject: [PATCH 095/151] remove push dependency on TESTREPO --- t/push1.t | 6 ++++-- t/push2.t | 10 ++++++---- t/push3.t | 22 +++++++++++++--------- t/push4.t | 18 +++++++++++------- t/push5.t | 18 +++++++++++------- 5 files changed, 45 insertions(+), 29 deletions(-) diff --git a/t/push1.t b/t/push1.t index 2a2ee12b..97b59535 100755 --- a/t/push1.t +++ b/t/push1.t @@ -6,9 +6,11 @@ test_description='Push command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'push succeeds if up-to-date' \ - 'git clone --bare "$TESTREPO" upstream.git && + 'test_create_repo repo && + test_commit -C repo A && + git clone --bare ./repo repo.git && - $VCSH clone upstream.git foo && + $VCSH clone ./repo.git foo && $VCSH foo config push.default simple && echo -e "foo: Everything up-to-date\\n" >expected && diff --git a/t/push2.t b/t/push2.t index 695385e3..472365cc 100755 --- a/t/push2.t +++ b/t/push2.t @@ -6,15 +6,17 @@ test_description='Push command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'push works with one repository' \ - 'git clone --bare "$TESTREPO" upstream.git && + 'test_create_repo repo && + test_commit -C repo A && + git clone --bare ./repo repo.git && - $VCSH clone upstream.git foo && + $VCSH clone ./repo.git foo && $VCSH foo config push.default simple && - $VCSH foo commit --allow-empty -m 'empty' && + $VCSH foo commit --allow-empty -m "empty" && $VCSH foo rev-parse HEAD >expected && $VCSH push && - git -C upstream.git rev-parse HEAD >output && + git -C ./repo.git rev-parse HEAD >output && test_cmp expected output' test_done diff --git a/t/push3.t b/t/push3.t index dd182c17..a456a043 100755 --- a/t/push3.t +++ b/t/push3.t @@ -6,24 +6,28 @@ test_description='Push command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'push works with multiple repositories' \ - 'git clone --bare -b "$TESTBR1" "$TESTREPO" upstream1.git && - git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git && - - $VCSH clone -b "$TESTBR1" upstream1.git foo && + 'test_create_repo repo1 && + test_create_repo repo2 && + test_commit -C repo1 A && + test_commit -C repo2 B && + git clone --bare ./repo1 repo1.git && + git clone --bare ./repo2 repo2.git && + + $VCSH clone repo1.git foo && $VCSH foo config push.default simple && - $VCSH clone -b "$TESTBR2" upstream2.git bar && + $VCSH clone repo2.git bar && $VCSH bar config push.default simple && - $VCSH foo commit --allow-empty -m 'empty' && - $VCSH bar commit --allow-empty -m 'empty' && + $VCSH foo commit --allow-empty -m "empty" && + $VCSH bar commit --allow-empty -m "empty" && $VCSH push && $VCSH foo rev-parse HEAD >expected && - git -C upstream1.git rev-parse HEAD >output && + git -C repo1.git rev-parse HEAD >output && test_cmp expected output && $VCSH bar rev-parse HEAD >expected && - git -C upstream2.git rev-parse HEAD >output && + git -C repo2.git rev-parse HEAD >output && test_cmp expected output' test_done diff --git a/t/push4.t b/t/push4.t index 904c2b42..8918348d 100755 --- a/t/push4.t +++ b/t/push4.t @@ -6,18 +6,22 @@ test_description='Push command' . "$TEST_DIRECTORY/environment.bash" test_expect_failure 'push fails if first push fails' \ - 'git clone --bare -b "$TESTBR1" "$TESTREPO" upstream1.git && - git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git && + 'test_create_repo repo1 && + test_create_repo repo2 && + test_commit -C repo1 A && + test_commit -C repo2 B && + git clone --bare ./repo1 repo1.git && + git clone --bare ./repo2 repo2.git && - $VCSH clone -b "$TESTBR1" upstream1.git a && + $VCSH clone repo1.git a && $VCSH a config push.default simple && - $VCSH clone -b "$TESTBR2" upstream2.git b && + $VCSH clone repo2.git b && $VCSH b config push.default simple && - $VCSH a commit --allow-empty -m 'empty' && - $VCSH b commit --allow-empty -m 'empty' && + $VCSH a commit --allow-empty -m "empty" && + $VCSH b commit --allow-empty -m "empty" && - rm -rf upstream1.git && + rm -rf repo1.git && test_must_fail $VCSH push' test_done diff --git a/t/push5.t b/t/push5.t index 7b906903..c4822837 100755 --- a/t/push5.t +++ b/t/push5.t @@ -6,18 +6,22 @@ test_description='Push command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'push fails if last push fails' \ - 'git clone --bare -b "$TESTBR1" "$TESTREPO" upstream1.git && - git clone --bare -b "$TESTBR2" "$TESTREPO" upstream2.git && + 'test_create_repo repo1 && + test_create_repo repo2 && + test_commit -C repo1 A && + test_commit -C repo2 B && + git clone --bare ./repo1 repo1.git && + git clone --bare ./repo2 repo2.git && - $VCSH clone -b "$TESTBR1" upstream1.git a && + $VCSH clone repo1.git a && $VCSH a config push.default simple && - $VCSH clone -b "$TESTBR2" upstream2.git b && + $VCSH clone repo2.git b && $VCSH b config push.default simple && - $VCSH a commit --allow-empty -m 'empty' && - $VCSH b commit --allow-empty -m 'empty' && + $VCSH a commit --allow-empty -m "empty" && + $VCSH b commit --allow-empty -m "empty" && - rm -rf upstream2.git && + rm -rf repo2.git && test_must_fail $VCSH push' test_done From 9cd857eba7484dca0df2725e42830c8d81cc49a4 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Wed, 17 May 2017 03:30:26 -0500 Subject: [PATCH 096/151] remove pull dependency on TESTREPO --- t/pull1.t | 5 +++-- t/pull2.t | 9 +++++---- t/pull3.t | 19 ++++++++++--------- t/pull4.t | 15 ++++++++------- t/pull5.t | 15 ++++++++------- 5 files changed, 34 insertions(+), 29 deletions(-) diff --git a/t/pull1.t b/t/pull1.t index 456cd7b2..6f6829f2 100755 --- a/t/pull1.t +++ b/t/pull1.t @@ -6,8 +6,9 @@ test_description='Pull command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'pull succeeds if up-to-date' \ - 'git clone "$TESTREPO" upstream && - $VCSH clone upstream foo && + 'test_create_repo repo && + test_commit -C repo A && + $VCSH clone ./repo foo && echo -e "foo: Already up-to-date.\\n" >expected && $VCSH pull >output && diff --git a/t/pull2.t b/t/pull2.t index 28d9545d..dca449a2 100755 --- a/t/pull2.t +++ b/t/pull2.t @@ -6,11 +6,12 @@ test_description='Pull command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'pull works with one repository' \ - 'git clone "$TESTREPO" upstream && - $VCSH clone upstream foo && + 'test_create_repo repo && + test_commit -C repo A && + $VCSH clone ./repo foo && - git -C upstream commit --allow-empty -m "empty" && - git -C upstream rev-parse HEAD >expected && + test_commit -C repo B && + git -C repo rev-parse HEAD >expected && $VCSH pull && $VCSH foo rev-parse HEAD >output && diff --git a/t/pull3.t b/t/pull3.t index 54c56c4e..10e3b37f 100755 --- a/t/pull3.t +++ b/t/pull3.t @@ -6,21 +6,22 @@ test_description='Pull command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'pull works with multiple repositories' \ - 'git clone -b "$TESTBR1" "$TESTREPO" upstream1 && - git clone -b "$TESTBR2" "$TESTREPO" upstream2 && + 'test_create_repo repo1 && + test_create_repo repo2 && + test_commit -C repo1 A && + test_commit -C repo2 B && + $VCSH clone ./repo1 foo && + $VCSH clone ./repo2 bar && - $VCSH clone -b "$TESTBR1" upstream1 foo && - $VCSH clone -b "$TESTBR2" upstream2 bar && - - git -C upstream1 commit --allow-empty -m "empty" && - git -C upstream1 rev-parse HEAD >expected && + test_commit -C repo1 X && + git -C repo1 rev-parse HEAD >expected && $VCSH pull && $VCSH foo rev-parse HEAD >output && test_cmp expected output && - git -C upstream2 commit --allow-empty -m "empty2" && - git -C upstream2 rev-parse HEAD >expected && + test_commit -C repo2 Y && + git -C repo2 rev-parse HEAD >expected && $VCSH pull && $VCSH bar rev-parse HEAD >output && diff --git a/t/pull4.t b/t/pull4.t index 66362fd1..3bb9db9c 100755 --- a/t/pull4.t +++ b/t/pull4.t @@ -6,14 +6,15 @@ test_description='Pull command' . "$TEST_DIRECTORY/environment.bash" test_expect_failure 'pull fails if first pull fails' \ - 'git clone -b "$TESTBR1" "$TESTREPO" upstream1 && - git clone -b "$TESTBR2" "$TESTREPO" upstream2 && + 'test_create_repo repo1 && + test_create_repo repo2 && + test_commit -C repo1 A && + test_commit -C repo2 B && + $VCSH clone ./repo1 a && + $VCSH clone ./repo2 b && - $VCSH clone -b "$TESTBR1" upstream1 a && - $VCSH clone -b "$TESTBR2" upstream2 b && - - rm -rf upstream1 && - git -C upstream2 commit --allow-empty -m "empty" && + rm -rf repo1 && + test_commit -C repo2 X && test_must_fail $VCSH pull' diff --git a/t/pull5.t b/t/pull5.t index 21ec311a..fead2a94 100755 --- a/t/pull5.t +++ b/t/pull5.t @@ -6,14 +6,15 @@ test_description='Pull command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'pull fails if last pull fails' \ - 'git clone -b "$TESTBR1" "$TESTREPO" upstream1 && - git clone -b "$TESTBR2" "$TESTREPO" upstream2 && + 'test_create_repo repo1 && + test_create_repo repo2 && + test_commit -C repo1 A && + test_commit -C repo2 B && + $VCSH clone ./repo1 a && + $VCSH clone ./repo2 b && - $VCSH clone -b "$TESTBR1" upstream1 a && - $VCSH clone -b "$TESTBR2" upstream2 b && - - git -C upstream1 commit --allow-empty -m "empty" && - rm -rf upstream2 && + test_commit -C repo1 X && + rm -rf repo2 && test_must_fail $VCSH pull' From c2bc53531ebdb32b45edeb8acceb0f5818519d30 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Wed, 17 May 2017 03:53:40 -0500 Subject: [PATCH 097/151] remove last of TESTREPO dependencies --- Makefile | 2 +- t/clone10.t | 10 ++++++++-- t/clone11.t | 16 +++++++++++++--- t/clone2.t | 14 ++++++++++++-- t/clone3.t | 5 ++++- t/clone4.t | 9 +++++---- t/clone5.t | 12 ++++++++---- t/clone6.t | 12 ++++++++---- t/clone7.t | 12 ++++++++---- t/clone8.t | 12 ++++++++---- t/clone9.t | 12 ++++++++---- t/environment.bash | 11 ----------- 12 files changed, 83 insertions(+), 44 deletions(-) diff --git a/Makefile b/Makefile index dfcec01a..9e568e81 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,7 @@ vcsh_testrepo.git: git clone --mirror https://github.com/djpohly/vcsh_testrepo.git test: | vcsh_testrepo.git - $(MAKE) -C t/ VCSH_TESTREPO="$(PWD)/vcsh_testrepo.git" VCSH_TESTREPONAME="vcsh_testrepo" + $(MAKE) -C t/ moo: @which cowsay >/dev/null 2>&1 && cowsay "I hope you're happy now..." diff --git a/t/clone10.t b/t/clone10.t index c195696a..8433f7f9 100755 --- a/t/clone10.t +++ b/t/clone10.t @@ -6,8 +6,14 @@ test_description='Clone command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone -b option clones only one branch' \ - '$VCSH clone -b "$TESTBR1" "$TESTREPO" && - $VCSH run "$TESTREPONAME" git branch >output && + 'test_create_repo repo && + test_commit -C repo A && + git -C repo checkout -b branchb && + test_commit -C repo B && + git -C repo checkout master && + + $VCSH clone -b branchb ./repo foo && + $VCSH foo show-ref --heads >output && test_line_count = 1 output' test_done diff --git a/t/clone11.t b/t/clone11.t index b40be922..2f46baab 100755 --- a/t/clone11.t +++ b/t/clone11.t @@ -6,9 +6,19 @@ test_description='Clone command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone can be abbreviated (clon, clo, cl)' \ - '$VCSH clon "$TESTREPO" a && - $VCSH clo -b "$TESTBR1" "$TESTREPO" b && - $VCSH cl -b "$TESTBR2" "$TESTREPO" c && + 'test_create_repo repo && + test_commit -C repo A && + git -C repo checkout --orphan branchb && + git -C repo rm -rf . && + test_commit -C repo B && + git -C repo checkout --orphan branchc && + git -C repo rm -rf . && + test_commit -C repo C && + git -C repo checkout master && + + $VCSH clon ./repo a && + $VCSH clo -b branchb ./repo b && + $VCSH cl -b branchc ./repo c && echo a > expected && echo b >> expected && diff --git a/t/clone2.t b/t/clone2.t index 1a492e69..1cdd9eed 100755 --- a/t/clone2.t +++ b/t/clone2.t @@ -6,8 +6,18 @@ test_description='Clone command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone uses existing repo name by default' \ - '$VCSH clone "$TESTREPO" && - echo "$TESTREPONAME" >expected && + 'test_create_repo repo1 && + test_create_repo repo2 && + test_commit -C repo1 A && + test_commit -C repo2 B && + git clone --bare repo2 repo3.git && + + $VCSH clone ./repo && + echo "repo" >expected && + $VCSH list >output && + + $VCSH clone ./repo3.git && + echo "repo3" >>expected && $VCSH list >output && test_cmp expected output' diff --git a/t/clone3.t b/t/clone3.t index 1144df14..e4e639c4 100755 --- a/t/clone3.t +++ b/t/clone3.t @@ -6,7 +6,10 @@ test_description='Clone command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone honors specified repo name' \ - '$VCSH clone "$TESTREPO" foo && + 'test_create_repo repo && + test_commit -C repo A && + + $VCSH clone ./repo foo && echo foo >expected && $VCSH list >output && test_cmp expected output' diff --git a/t/clone4.t b/t/clone4.t index c887044c..7a4a696f 100755 --- a/t/clone4.t +++ b/t/clone4.t @@ -6,11 +6,12 @@ test_description='Clone command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone uses given remote HEAD by default' \ - '$VCSH clone "$TESTREPO" && - git ls-remote "$TESTREPO" HEAD | head -c40 >expected && - echo >>expected && + 'test_create_repo repo && + test_commit -C repo A && + $VCSH clone ./repo foo && - $VCSH run "$TESTREPONAME" git rev-parse HEAD >output && + git -C repo rev-parse HEAD >expected && + $VCSH foo rev-parse HEAD >output && test_cmp expected output' test_done diff --git a/t/clone5.t b/t/clone5.t index 1f518648..85287853 100755 --- a/t/clone5.t +++ b/t/clone5.t @@ -6,11 +6,15 @@ test_description='Clone command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone honors -b option before remote' \ - '$VCSH clone -b "$TESTBR1" "$TESTREPO" && - git ls-remote "$TESTREPO" "$TESTBR1" | head -c40 >expected && - echo >>expected && + 'test_create_repo repo && + test_commit -C repo A && + git -C repo checkout -b branchb && + test_commit -C repo B && + git -C repo checkout master && - $VCSH run "$TESTREPONAME" git rev-parse "$TESTBR1" >output && + $VCSH clone -b branchb ./repo && + git -C repo rev-parse branchb >expected && + $VCSH repo rev-parse HEAD >output && test_cmp expected output' test_done diff --git a/t/clone6.t b/t/clone6.t index 143c50ed..f001d8e1 100755 --- a/t/clone6.t +++ b/t/clone6.t @@ -6,11 +6,15 @@ test_description='Clone command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone honors -b option before remote and repo name' \ - '$VCSH clone -b "$TESTBR1" "$TESTREPO" foo && - git ls-remote "$TESTREPO" "$TESTBR1" | head -c40 >expected && - echo >>expected && + 'test_create_repo repo && + test_commit -C repo A && + git -C repo checkout -b branchb && + test_commit -C repo B && + git -C repo checkout master && - $VCSH run foo git rev-parse "$TESTBR1" >output && + $VCSH clone -b branchb ./repo foo && + git -C repo rev-parse branchb >expected && + $VCSH foo rev-parse HEAD >output && test_cmp expected output' test_done diff --git a/t/clone7.t b/t/clone7.t index 577a7bf0..3e8dfc40 100755 --- a/t/clone7.t +++ b/t/clone7.t @@ -6,11 +6,15 @@ test_description='Clone command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone honors -b option after remote' \ - '$VCSH clone "$TESTREPO" -b "$TESTBR1" && - git ls-remote "$TESTREPO" "$TESTBR1" | head -c40 >expected && - echo >>expected && + 'test_create_repo repo && + test_commit -C repo A && + git -C repo checkout -b branchb && + test_commit -C repo B && + git -C repo checkout master && - $VCSH run "$TESTREPONAME" git rev-parse "$TESTBR1" >output && + $VCSH clone ./repo -b branchb && + git -C repo rev-parse branchb >expected && + $VCSH repo rev-parse HEAD >output && test_cmp expected output' test_done diff --git a/t/clone8.t b/t/clone8.t index 9e8938ef..f845d86f 100755 --- a/t/clone8.t +++ b/t/clone8.t @@ -6,11 +6,15 @@ test_description='Clone command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone honors -b option between remote and repo name' \ - '$VCSH clone "$TESTREPO" -b "$TESTBR1" foo && - git ls-remote "$TESTREPO" "$TESTBR1" | head -c40 >expected && - echo >>expected && + 'test_create_repo repo && + test_commit -C repo A && + git -C repo checkout -b branchb && + test_commit -C repo B && + git -C repo checkout master && - $VCSH run foo git rev-parse "$TESTBR1" >output && + $VCSH clone ./repo -b branchb foo && + git -C repo rev-parse branchb >expected && + $VCSH foo rev-parse HEAD >output && test_cmp expected output' test_done diff --git a/t/clone9.t b/t/clone9.t index 54095f52..abab024b 100755 --- a/t/clone9.t +++ b/t/clone9.t @@ -6,11 +6,15 @@ test_description='Clone command' . "$TEST_DIRECTORY/environment.bash" test_expect_success 'Clone honors -b option after repo name' \ - '$VCSH clone "$TESTREPO" foo -b "$TESTBR1" && - git ls-remote "$TESTREPO" "$TESTBR1" | head -c40 >expected && - echo >>expected && + 'test_create_repo repo && + test_commit -C repo A && + git -C repo checkout -b branchb && + test_commit -C repo B && + git -C repo checkout master && - $VCSH run foo git rev-parse "$TESTBR1" >output && + $VCSH clone ./repo foo -b branchb && + git -C repo rev-parse branchb >expected && + $VCSH foo rev-parse HEAD >output && test_cmp expected output' test_done diff --git a/t/environment.bash b/t/environment.bash index eddf6852..9d30bddd 100644 --- a/t/environment.bash +++ b/t/environment.bash @@ -6,17 +6,6 @@ export VCSH="vcsh" # Perhaps it should be ignored if one exists in $XDG_CONFIG_HOME or was # specified with -c? -# Test repository. For faster tests, you can create a local mirror and -# use that instead. -: ${TESTREPO:='https://github.com/djpohly/vcsh_testrepo.git'} -: ${TESTREPONAME:='vcsh_testrepo'} -export TESTREPO TESTREPONAME -export TESTM1=master -export TESTM2=master2 -export TESTBR1=branch1 -export TESTBR2=branch2 -export TESTBRX=conflict - # Other things used in tests export GITVERSION=$(git version) From 1e5ed6d866b821d8edf11ee9474d424aa371b641 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Wed, 17 May 2017 04:11:26 -0500 Subject: [PATCH 098/151] condense foreach tests --- t/foreach.t | 45 +++++++++++++++++++++++++++++++++++++++++++++ t/foreach0.t | 11 ----------- t/foreach1.t | 12 ------------ t/foreach2.t | 26 -------------------------- t/foreach3.t | 26 -------------------------- 5 files changed, 45 insertions(+), 75 deletions(-) create mode 100755 t/foreach.t delete mode 100755 t/foreach0.t delete mode 100755 t/foreach1.t delete mode 100755 t/foreach2.t delete mode 100755 t/foreach3.t diff --git a/t/foreach.t b/t/foreach.t new file mode 100755 index 00000000..399dc9d3 --- /dev/null +++ b/t/foreach.t @@ -0,0 +1,45 @@ +#!/bin/bash + +test_description='Foreach command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Foreach requires an argument' \ + 'test_must_fail $VCSH foreach' + +test_expect_success 'Foreach does nothing if no repositories exist' \ + '$VCSH foreach version >output && + test_must_be_empty output' + +test_expect_success '(setup) Create two repositories' \ + 'test_create_repo repo1 && + test_commit -C repo1 A && + test_create_repo repo2 && + test_commit -C repo2 B && + $VCSH clone ./repo1 foo && + $VCSH clone ./repo2 bar' + +test_expect_success 'Foreach executes Git command inside each repository' \ + '{ + echo "bar:" && + git -C repo2 rev-parse HEAD && + echo "foo:" && + git -C repo1 rev-parse HEAD + } >expected && + + $VCSH foreach rev-parse HEAD >output && + test_cmp expected output' + +test_expect_success 'Foreach supports -g for non-Git commands' \ + '{ + echo "bar:" && + echo "test-output" && + echo "foo:" && + echo "test-output" + } >expected && + + $VCSH foreach -g echo test-output >output && + test_cmp expected output' + +test_done diff --git a/t/foreach0.t b/t/foreach0.t deleted file mode 100755 index d51de00e..00000000 --- a/t/foreach0.t +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -test_description='Foreach command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Foreach requires an argument' \ - 'test_must_fail $VCSH foreach' - -test_done diff --git a/t/foreach1.t b/t/foreach1.t deleted file mode 100755 index ac413491..00000000 --- a/t/foreach1.t +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -test_description='Foreach command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Foreach does nothing if no repositories exist' \ - '$VCSH foreach version >output && - test_must_be_empty output' - -test_done diff --git a/t/foreach2.t b/t/foreach2.t deleted file mode 100755 index 74184eec..00000000 --- a/t/foreach2.t +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -test_description='Foreach command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Foreach executes Git command inside each repository' \ - 'test_create_repo repo1 && - test_commit -C repo1 A && - test_create_repo repo2 && - test_commit -C repo2 B && - $VCSH clone ./repo1 foo && - $VCSH clone ./repo2 bar && - - { - echo "bar:" && - git -C repo2 rev-parse HEAD && - echo "foo:" && - git -C repo1 rev-parse HEAD - } >expected && - - $VCSH foreach rev-parse HEAD >output && - test_cmp expected output' - -test_done diff --git a/t/foreach3.t b/t/foreach3.t deleted file mode 100755 index a9b9f8ce..00000000 --- a/t/foreach3.t +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -test_description='Foreach command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Foreach supports -g for non-Git commands' \ - 'test_create_repo repo1 && - test_commit -C repo1 A && - test_create_repo repo2 && - test_commit -C repo2 B && - $VCSH clone ./repo1 foo && - $VCSH clone ./repo2 bar && - - { - echo "bar:" && - echo "test-output" && - echo "foo:" && - echo "test-output" - } >expected && - - $VCSH foreach -g echo test-output >output && - test_cmp expected output' - -test_done From 194e56e8057a4e05da150d5b72e2a370be29822a Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Wed, 17 May 2017 04:21:01 -0500 Subject: [PATCH 099/151] condense init tests --- t/init-umask.t | 14 --------- t/init.t | 78 +++++++++++++++++++++++++++++++++++++++----------- t/init2.t | 18 ------------ t/init3.t | 13 --------- t/init4.t | 14 --------- t/init5.t | 14 --------- t/init6.t | 12 -------- t/init7.t | 12 -------- t/init8.t | 12 -------- 9 files changed, 61 insertions(+), 126 deletions(-) delete mode 100755 t/init-umask.t delete mode 100755 t/init2.t delete mode 100755 t/init3.t delete mode 100755 t/init4.t delete mode 100755 t/init5.t delete mode 100755 t/init6.t delete mode 100755 t/init7.t delete mode 100755 t/init8.t diff --git a/t/init-umask.t b/t/init-umask.t deleted file mode 100755 index 5996e6c9..00000000 --- a/t/init-umask.t +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -test_description='Ensure init creates files with limited permissions' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -# verifies commit e220a61 -test_expect_success 'Files created by init are not readable by other users' \ - '$VCSH init foo && - find "$HOME" -type f -perm /g+rwx,o+rwx ! -path "$HOME/output" >output && - test_must_be_empty output' - -test_done diff --git a/t/init.t b/t/init.t index ae825b27..3b23a56e 100755 --- a/t/init.t +++ b/t/init.t @@ -8,6 +8,21 @@ test_description='Init command' test_expect_success 'Init command succeeds' \ '$VCSH init foo' +test_expect_success 'Init command creates new Git repository' \ + 'find_gitrepos "$PWD" >output && + test_line_count = 1 output && + + for i in $(test_seq 2 5); do + $VCSH init "count$i" && + find_gitrepos "$PWD" >output && + test_line_count = "$i" output + done' + +# verifies commit e220a61 +test_expect_success 'Files created by init are not readable by other users' \ + 'find "$HOME" -type f -perm /g+rwx,o+rwx ! -path "$HOME/output" >output && + test_must_be_empty output' + test_expect_success 'Init command fails if repository already exists' \ 'test_must_fail $VCSH init foo' @@ -45,25 +60,25 @@ test_expect_success 'Init command respects alternate $HOME' \ test_expect_success 'Init command fails if directories cannot be created' \ 'mkdir ro && chmod a-w ro && - test_env HOME="$PWD/ro" test_must_fail $VCSH init foo' + test_env HOME="$PWD/ro" test_must_fail $VCSH init readonly' test_expect_success '$VCSH_REPO_D overrides $XDG_CONFIG_HOME and $HOME for init' \ 'mkdir -p foo4 bar4 foo4a bar4a over4a over4b && - test_env HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4a" $VCSH init samename && - test_env HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename && - test_env HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename && - test_env HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename && - test_env HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4b" $VCSH init samename && - test_env HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename && - test_env HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename && - test_env HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename' + test_env HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4a" $VCSH init samename1 && + test_env HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename1 && + test_env HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename1 && + test_env HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename1 && + test_env HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4b" $VCSH init samename1 && + test_env HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename1 && + test_env HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename1 && + test_env HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename1' test_expect_success '$XDG_CONFIG_HOME overrides $HOME for init' \ 'mkdir -p foo5 bar5 over5a over5b && - test_env HOME="$PWD/foo5" XDG_CONFIG_HOME="$PWD/over5a" $VCSH init samename && - test_env HOME="$PWD/bar5" XDG_CONFIG_HOME="$PWD/over5a" test_must_fail $VCSH init samename && - test_env HOME="$PWD/foo5" XDG_CONFIG_HOME="$PWD/over5b" $VCSH init samename && - test_env HOME="$PWD/bar5" XDG_CONFIG_HOME="$PWD/over5b" test_must_fail $VCSH init samename' + test_env HOME="$PWD/foo5" XDG_CONFIG_HOME="$PWD/over5a" $VCSH init samename2 && + test_env HOME="$PWD/bar5" XDG_CONFIG_HOME="$PWD/over5a" test_must_fail $VCSH init samename2 && + test_env HOME="$PWD/foo5" XDG_CONFIG_HOME="$PWD/over5b" $VCSH init samename2 && + test_env HOME="$PWD/bar5" XDG_CONFIG_HOME="$PWD/over5b" test_must_fail $VCSH init samename2' # Too internal to implementation? If another command verifies # vcsh.vcsh, use that instead of git config. @@ -74,9 +89,38 @@ test_expect_success 'Init command marks repository with vcsh.vcsh=true' \ test_expect_success 'Init command adds matching gitignore.d files' \ 'mkdir -p .gitattributes.d .gitignore.d && - touch .gitattributes.d/test1 .gitignore.d/test1 && - - test_env VCSH_GITIGNORE=exact $VCSH init test1 && - $VCSH status test1 | assert_grep -Fx "A .gitignore.d/test1"' + touch .gitattributes.d/ignore-d .gitignore.d/ignore-d && + + test_env VCSH_GITIGNORE=exact $VCSH init ignore-d && + $VCSH status ignore-d | assert_grep -Fx "A .gitignore.d/ignore-d"' + +test_expect_success 'VCSH_GITIGNORE variable is validated' \ + 'test_env VCSH_GITIGNORE=x test_must_fail $VCSH init ignore1 && + test_env VCSH_GITIGNORE=nonsense test_must_fail $VCSH init ignore2 && + test_env VCSH_GITIGNORE=fhqwhgads test_must_fail $VCSH init ignore3' + +# XXX test instead by making sure files are actually excluded, not by +# reading config option +test_expect_success 'Init command sets core.excludesfile with VCSH_GITIGNORE=exact' \ + 'test_env VCSH_GITIGNORE=exact $VCSH init excludes && + $VCSH run excludes git config core.excludesfile' + +# XXX test instead by making sure files are actually excluded, not by +# reading config option +test_expect_success 'Init command sets core.excludesfile with VCSH_GITIGNORE=recursive' \ + 'test_env VCSH_GITIGNORE=recursive $VCSH init excludes-r && + $VCSH run excludes-r git config core.excludesfile' + +test_expect_success 'Init command does not set core.excludesfile with VCSH_GITIGNORE=none' \ + 'test_env VCSH_GITIGNORE=none $VCSH init excludes-n && + test_must_fail $VCSH run excludes-n git config core.excludesfile' + +test_expect_success 'Init command sets core.attributesfile with VCSH_GITATTRIBUTES!=none' \ + 'test_env VCSH_GITATTRIBUTES=whatever $VCSH init attrs && + $VCSH run attrs git config core.attributesfile' + +test_expect_success 'Init command does not set core.attributesfile with VCSH_GITATTRIBUTES=none' \ + 'test_env VCSH_GITATTRIBUTES=none $VCSH init no-attrs && + test_must_fail $VCSH run no-attrs git config core.attributesfile' test_done diff --git a/t/init2.t b/t/init2.t deleted file mode 100755 index 5659556e..00000000 --- a/t/init2.t +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -test_description='Init command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Init command creates new Git repository' \ - 'find_gitrepos "$PWD" >output && - test_must_be_empty output && - - for i in $(test_seq 5); do - $VCSH init "test$i" && - find_gitrepos "$PWD" >output && - test_line_count = "$i" output - done' - -test_done diff --git a/t/init3.t b/t/init3.t deleted file mode 100755 index 4f5141a3..00000000 --- a/t/init3.t +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -test_description='Init command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'VCSH_GITIGNORE variable is validated' \ - 'test_env VCSH_GITIGNORE=x test_must_fail $VCSH init foo && - test_env VCSH_GITIGNORE=nonsense test_must_fail $VCSH init foo && - test_env VCSH_GITIGNORE=fhqwhgads test_must_fail $VCSH init foo' - -test_done diff --git a/t/init4.t b/t/init4.t deleted file mode 100755 index fffa0c5a..00000000 --- a/t/init4.t +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -test_description='Init command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -# XXX test instead by making sure files are actually excluded, not by -# reading config option -test_expect_success 'Init command sets core.excludesfile with VCSH_GITIGNORE=exact' \ - 'test_env VCSH_GITIGNORE=exact $VCSH init test1 && - $VCSH run test1 git config core.excludesfile' - -test_done diff --git a/t/init5.t b/t/init5.t deleted file mode 100755 index e6865dc4..00000000 --- a/t/init5.t +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -test_description='Init command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -# XXX test instead by making sure files are actually excluded, not by -# reading config option -test_expect_success 'Init command sets core.excludesfile with VCSH_GITIGNORE=recursive' \ - 'test_env VCSH_GITIGNORE=recursive $VCSH init test1 && - $VCSH run test1 git config core.excludesfile' - -test_done diff --git a/t/init6.t b/t/init6.t deleted file mode 100755 index 5d35e581..00000000 --- a/t/init6.t +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -test_description='Init command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Init command does not set core.excludesfile with VCSH_GITIGNORE=none' \ - 'test_env VCSH_GITIGNORE=none $VCSH init test1 && - test_must_fail $VCSH run test1 git config core.excludesfile' - -test_done diff --git a/t/init7.t b/t/init7.t deleted file mode 100755 index 797aa197..00000000 --- a/t/init7.t +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -test_description='Init command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Init command sets core.attributesfile with VCSH_GITATTRIBUTES!=none' \ - 'test_env VCSH_GITATTRIBUTES=whatever $VCSH init test1 && - $VCSH run test1 git config core.attributesfile' - -test_done diff --git a/t/init8.t b/t/init8.t deleted file mode 100755 index 7127ae57..00000000 --- a/t/init8.t +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -test_description='Init command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Init command does not set core.attributesfile with VCSH_GITATTRIBUTES=none' \ - 'test_env VCSH_GITATTRIBUTES=none $VCSH init test1 && - test_must_fail $VCSH run test1 git config core.attributesfile' - -test_done From 51bcbd9f88c0e801e0e17554d75e5c23ce09e09b Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Wed, 17 May 2017 23:58:16 -0500 Subject: [PATCH 100/151] condense list tests --- t/list.t | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++ t/list1.t | 12 ------ t/list10.t | 20 ---------- t/list2.t | 14 ------- t/list3.t | 18 --------- t/list4.t | 18 --------- t/list5.t | 20 ---------- t/list6.t | 20 ---------- t/list7.t | 16 -------- t/list8.t | 16 -------- t/list9.t | 16 -------- 11 files changed, 109 insertions(+), 170 deletions(-) create mode 100755 t/list.t delete mode 100755 t/list1.t delete mode 100755 t/list10.t delete mode 100755 t/list2.t delete mode 100755 t/list3.t delete mode 100755 t/list4.t delete mode 100755 t/list5.t delete mode 100755 t/list6.t delete mode 100755 t/list7.t delete mode 100755 t/list8.t delete mode 100755 t/list9.t diff --git a/t/list.t b/t/list.t new file mode 100755 index 00000000..6b60f494 --- /dev/null +++ b/t/list.t @@ -0,0 +1,109 @@ +#!/bin/bash + +test_description='List command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Setup' \ + 'test_create_repo repo && + test_commit -C repo A && + test_commit -C repo B' + +test_expect_success 'List command correct for no repositories' \ + '$VCSH list >output && + test_must_be_empty output' + +test_expect_success 'List command displays inited repository' \ + '$VCSH init test1 && + echo test1 >expected && + $VCSH list >output && + test_cmp expected output && + doit | $VCSH delete test1' + +test_expect_success 'List command displays cloned repository' \ + '$VCSH clone ./repo foo && + echo foo >expected && + $VCSH list >output && + test_cmp expected output && + doit | $VCSH delete foo' + +test_expect_success 'List command respects $XDG_CONFIG_HOME' \ + 'test_env XDG_CONFIG_HOME="$PWD/xdg1" $VCSH init test1 && + test_env XDG_CONFIG_HOME="$PWD/xdg2" $VCSH init test2 && + + echo test1 >expected && + test_env XDG_CONFIG_HOME="$PWD/xdg1" $VCSH list >output && + test_cmp expected output && + + echo test2 >expected && + test_env XDG_CONFIG_HOME="$PWD/xdg2" $VCSH list >output && + test_cmp expected output && + + doit | test_env XDG_CONFIG_HOME="$PWD/xdg1" $VCSH delete test1 && + doit | test_env XDG_CONFIG_HOME="$PWD/xdg2" $VCSH delete test2' + +test_expect_success 'List command respects $HOME' \ + 'test_env HOME="$PWD/home1" $VCSH init test1 && + test_env HOME="$PWD/home2" $VCSH init test2 && + + echo test1 >expected && + test_env HOME="$PWD/home1" $VCSH list >output && + test_cmp expected output && + + echo test2 >expected && + test_env HOME="$PWD/home2" $VCSH list >output && + test_cmp expected output && + + doit | test_env HOME="$PWD/home1" $VCSH delete test1 && + doit | test_env HOME="$PWD/home2" $VCSH delete test2' + +test_expect_success 'List command prioritizes $XDG_CONFIG_HOME over $HOME' \ + 'test_env HOME="$PWD/xh1" $VCSH init correct && + test_env HOME="$PWD/xh2" $VCSH init wrong && + + echo correct >expected && + test_env HOME="$PWD/xh2" XDG_CONFIG_HOME="$PWD/xh1/.config" $VCSH list >output && + test_cmp expected output && + + doit | test_env HOME="$PWD/xh1" $VCSH delete correct && + doit | test_env HOME="$PWD/xh2" $VCSH delete wrong' + +test_expect_success 'List command prioritizes $VCSH_REPO_D over $HOME' \ + 'test_env HOME="$PWD/rdh1" $VCSH init correct && + test_env HOME="$PWD/rdh2" $VCSH init wrong && + + echo correct >expected && + test_env HOME="$PWD/rdh2" VCSH_REPO_D="$PWD/rdh1/.config/vcsh/repo.d" $VCSH list >output && + test_cmp expected output && + + doit | test_env HOME="$PWD/rdh1" $VCSH delete correct && + doit | test_env HOME="$PWD/rdh2" $VCSH delete wrong' + +test_expect_success 'List command prioritizes $VCSH_REPO_D over $XDG_CONFIG_HOME' \ + 'test_env XDG_CONFIG_HOME="$PWD/xhrd1" $VCSH init correct && + test_env XDG_CONFIG_HOME="$PWD/xhrd2" $VCSH init wrong && + + echo correct >expected && + test_env XDG_CONFIG_HOME="$PWD/xhrd2" VCSH_REPO_D="$PWD/xhrd1/vcsh/repo.d" $VCSH list >output && + test_cmp expected output && + + doit | test_env XDG_CONFIG_HOME="$PWD/xhrd1" $VCSH delete correct && + doit | test_env XDG_CONFIG_HOME="$PWD/xhrd2" $VCSH delete wrong' + +test_expect_success 'List command respects $VCSH_REPO_D' \ + 'test_env VCSH_REPO_D="$PWD/rd1" $VCSH init test1 && + test_env VCSH_REPO_D="$PWD/rd2" $VCSH init test2 && + + echo test1 >expected && + test_env VCSH_REPO_D="$PWD/rd1" $VCSH list >output && + test_cmp expected output && + + echo test2 >expected && + test_env VCSH_REPO_D="$PWD/rd2" $VCSH list >output && + test_cmp expected output && + + doit | test_env VCSH_REPO_D="$PWD/rd1" $VCSH delete test1 && + doit | test_env VCSH_REPO_D="$PWD/rd2" $VCSH delete test2' + +test_done diff --git a/t/list1.t b/t/list1.t deleted file mode 100755 index 6423d8c5..00000000 --- a/t/list1.t +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -test_description='List command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'List command correct for no repositories' \ - '$VCSH list >output && - test_must_be_empty output' - -test_done diff --git a/t/list10.t b/t/list10.t deleted file mode 100755 index d20be3ca..00000000 --- a/t/list10.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='List command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'List command respects $VCSH_REPO_D' \ - 'test_env VCSH_REPO_D="$PWD/foo" $VCSH init test1 && - test_env VCSH_REPO_D="$PWD/bar" $VCSH init test2 && - - echo test1 >expected && - test_env VCSH_REPO_D="$PWD/foo" $VCSH list >output && - test_cmp expected output && - - echo test2 >expected && - test_env VCSH_REPO_D="$PWD/bar" $VCSH list >output && - test_cmp expected output' - -test_done diff --git a/t/list2.t b/t/list2.t deleted file mode 100755 index e5291d2a..00000000 --- a/t/list2.t +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -test_description='List command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'List command displays inited repository' \ - '$VCSH init test1 && - echo test1 >expected && - $VCSH list >output && - test_cmp expected output' - -test_done diff --git a/t/list3.t b/t/list3.t deleted file mode 100755 index 988dd3ee..00000000 --- a/t/list3.t +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -test_description='List command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'List command displays cloned repository' \ - 'test_create_repo repo && - test_commit -C repo A && - test_commit -C repo B && - - $VCSH clone ./repo foo && - echo foo >expected && - $VCSH list >output && - test_cmp expected output' - -test_done diff --git a/t/list4.t b/t/list4.t deleted file mode 100755 index 3518124f..00000000 --- a/t/list4.t +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -test_description='List command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'List command displays multiple repositories' \ - '$VCSH init foo && - $VCSH init bar && - $VCSH init baz && - echo bar >expected && - echo baz >>expected && - echo foo >>expected && - $VCSH list >output && - test_cmp expected output' - -test_done diff --git a/t/list5.t b/t/list5.t deleted file mode 100755 index 8073a3c4..00000000 --- a/t/list5.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='List command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'List command respects $XDG_CONFIG_HOME' \ - 'test_env XDG_CONFIG_HOME="$PWD/foo" $VCSH init test1 && - test_env XDG_CONFIG_HOME="$PWD/bar" $VCSH init test2 && - - echo test1 >expected && - test_env XDG_CONFIG_HOME="$PWD/foo" $VCSH list >output && - test_cmp expected output && - - echo test2 >expected && - test_env XDG_CONFIG_HOME="$PWD/bar" $VCSH list >output && - test_cmp expected output' - -test_done diff --git a/t/list6.t b/t/list6.t deleted file mode 100755 index a89a1302..00000000 --- a/t/list6.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='List command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'List command respects $HOME' \ - 'test_env HOME="$PWD/foo" $VCSH init test1 && - test_env HOME="$PWD/bar" $VCSH init test2 && - - echo test1 >expected && - test_env HOME="$PWD/foo" $VCSH list >output && - test_cmp expected output && - - echo test2 >expected && - test_env HOME="$PWD/bar" $VCSH list >output && - test_cmp expected output' - -test_done diff --git a/t/list7.t b/t/list7.t deleted file mode 100755 index 11c89414..00000000 --- a/t/list7.t +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -test_description='List command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'List command prioritizes $XDG_CONFIG_HOME over $HOME' \ - 'test_env HOME="$PWD/foo" $VCSH init correct && - test_env HOME="$PWD/bar" $VCSH init wrong && - - echo correct >expected && - test_env HOME="$PWD/bar" XDG_CONFIG_HOME="$PWD/foo/.config" $VCSH list >output && - test_cmp expected output' - -test_done diff --git a/t/list8.t b/t/list8.t deleted file mode 100755 index 78ae5504..00000000 --- a/t/list8.t +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -test_description='List command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'List command prioritizes $VCSH_REPO_D over $HOME' \ - 'test_env HOME="$PWD/foo" $VCSH init correct && - test_env HOME="$PWD/bar" $VCSH init wrong && - - echo correct >expected && - test_env HOME="$PWD/bar" VCSH_REPO_D="$PWD/foo/.config/vcsh/repo.d" $VCSH list >output && - test_cmp expected output' - -test_done diff --git a/t/list9.t b/t/list9.t deleted file mode 100755 index 1fb39eb2..00000000 --- a/t/list9.t +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -test_description='List command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'List command prioritizes $VCSH_REPO_D over $XDG_CONFIG_HOME' \ - 'test_env XDG_CONFIG_HOME="$PWD/foo" $VCSH init correct && - test_env XDG_CONFIG_HOME="$PWD/bar" $VCSH init wrong && - - echo correct >expected && - test_env XDG_CONFIG_HOME="$PWD/bar" VCSH_REPO_D="$PWD/foo/vcsh/repo.d" $VCSH list >output && - test_cmp expected output' - -test_done From 518aaf2397d5b5e2dbe35a236cd5e7d9915ad956 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 18 May 2017 00:14:44 -0500 Subject: [PATCH 101/151] condense delete tests --- t/delete.t | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++ t/delete1.t | 11 ---- t/delete10.t | 19 ------- t/delete11.t | 24 --------- t/delete12.t | 19 ------- t/delete13.t | 26 ---------- t/delete2.t | 11 ---- t/delete3.t | 24 --------- t/delete4.t | 17 ------ t/delete5.t | 15 ------ t/delete6.t | 14 ----- t/delete7.t | 15 ------ t/delete8.t | 18 ------- t/delete9.t | 30 ----------- 14 files changed, 144 insertions(+), 243 deletions(-) create mode 100755 t/delete.t delete mode 100755 t/delete1.t delete mode 100755 t/delete10.t delete mode 100755 t/delete11.t delete mode 100755 t/delete12.t delete mode 100755 t/delete13.t delete mode 100755 t/delete2.t delete mode 100755 t/delete3.t delete mode 100755 t/delete4.t delete mode 100755 t/delete5.t delete mode 100755 t/delete6.t delete mode 100755 t/delete7.t delete mode 100755 t/delete8.t delete mode 100755 t/delete9.t diff --git a/t/delete.t b/t/delete.t new file mode 100755 index 00000000..5376a8d9 --- /dev/null +++ b/t/delete.t @@ -0,0 +1,144 @@ +#!/bin/bash + +test_description='Delete command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Delete requires repo name' \ + 'test_must_fail $VCSH delete' + +test_expect_success 'Repository to be deleted must exist' \ + 'test_must_fail $VCSH delete foo' + +test_expect_success 'Delete requires confirmation' \ + '$VCSH init foo && + echo foo >expected && + + : | test_must_fail $VCSH delete foo && + $VCSH list >output && + test_cmp expected output && + + echo | test_must_fail $VCSH delete foo && + $VCSH list >output && + test_cmp expected output && + + echo no | test_must_fail $VCSH delete foo && + $VCSH list >output && + test_cmp expected output && + + doit | $VCSH delete foo && + $VCSH list >output && + test_must_be_empty output' + +test_expect_success 'Deleted repository removed from list' \ + '$VCSH init foo && + $VCSH init bar && + + doit | $VCSH delete foo && + echo bar >expected && + $VCSH list >output && + test_cmp expected output && + + doit | $VCSH delete bar && + $VCSH list >output && + test_must_be_empty output' + +test_expect_success 'Deleted repository not in status' \ + '$VCSH init foo && + doit | $VCSH delete foo && + + $VCSH status >output && + test_line_count = 0 output' + +test_expect_success 'Deleted repository cannot be subsequently used' \ + '$VCSH init foo && + doit | $VCSH delete foo && + + test_must_fail $VCSH run foo echo fail' + +test_expect_success 'Delete lists staged files before confirmation' \ + '$VCSH init foo && + test_when_finished "doit | $VCSH delete foo" && + touch randomtexttofind && + $VCSH foo add randomtexttofind && + + : | test_must_fail $VCSH delete foo >output && + assert_grep -F randomtexttofind output && + assert_grep -F randomtexttofind expected && - - test_must_fail $VCSH delete foo < /dev/null && - $VCSH list >output && - test_cmp expected output && - - echo | test_must_fail $VCSH delete foo && - $VCSH list >output && - test_cmp expected output && - - echo no | test_must_fail $VCSH delete foo && - $VCSH list >output && - test_cmp expected output' - -test_done diff --git a/t/delete12.t b/t/delete12.t deleted file mode 100755 index fb28d6f8..00000000 --- a/t/delete12.t +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -test_description='Delete command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_failure 'Delete handles filenames with wildcard characters properly' \ - '$VCSH init foo && - touch a b "?" && - $VCSH foo add '\''\?'\'' && - $VCSH foo commit -m "?" && - - doit | $VCSH delete foo && - test_path_is_missing "?" && - test_path_is_file a && - test_path_is_file b' - -test_done diff --git a/t/delete13.t b/t/delete13.t deleted file mode 100755 index f1d16177..00000000 --- a/t/delete13.t +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -test_description='Delete command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Delete can be abbreviated (delet, dele, del, de)' \ - '$VCSH init a && - $VCSH init b && - $VCSH init c && - $VCSH init d && - - doit | $VCSH delet a && - ! $VCSH list | assert_grep -Fx a && - - doit | $VCSH dele b && - ! $VCSH list | assert_grep -Fx b && - - doit | $VCSH del c && - ! $VCSH list | assert_grep -Fx c && - - doit | $VCSH de d && - ! $VCSH list | assert_grep -Fx d' - -test_done diff --git a/t/delete2.t b/t/delete2.t deleted file mode 100755 index 3b53fc10..00000000 --- a/t/delete2.t +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -test_description='Delete command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Repository to be deleted must exist' \ - 'test_must_fail $VCSH delete foo' - -test_done diff --git a/t/delete3.t b/t/delete3.t deleted file mode 100755 index 5c583b8b..00000000 --- a/t/delete3.t +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -test_description='Delete command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Delete requires confirmation' \ - '$VCSH init foo && - echo foo >expected && - - test_must_fail $VCSH delete foo < /dev/null && - $VCSH list >output && - test_cmp expected output && - - echo | test_must_fail $VCSH delete foo && - $VCSH list >output && - test_cmp expected output && - - echo no | test_must_fail $VCSH delete foo && - $VCSH list >output && - test_cmp expected output' - -test_done diff --git a/t/delete4.t b/t/delete4.t deleted file mode 100755 index a5d39a97..00000000 --- a/t/delete4.t +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -test_description='Delete command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Deleted repository removed from list' \ - '$VCSH init foo && - $VCSH init bar && - doit | $VCSH delete foo && - - $VCSH list >output && - echo bar >expected && - test_cmp expected output' - -test_done diff --git a/t/delete5.t b/t/delete5.t deleted file mode 100755 index 84178273..00000000 --- a/t/delete5.t +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -test_description='Delete command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Deleted repository not in status' \ - '$VCSH init foo && - doit | $VCSH delete foo && - - $VCSH status >output && - test_line_count = 0 output' - -test_done diff --git a/t/delete6.t b/t/delete6.t deleted file mode 100755 index 13f41f0e..00000000 --- a/t/delete6.t +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -test_description='Delete command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Deleted repository cannot be subsequently used' \ - '$VCSH init foo && - doit | $VCSH delete foo && - - test_must_fail $VCSH run foo echo fail' - -test_done diff --git a/t/delete7.t b/t/delete7.t deleted file mode 100755 index cca3cae9..00000000 --- a/t/delete7.t +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -test_description='Delete command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Delete lists staged files before confirmation' \ - '$VCSH init foo && - touch randomtexttofind && - $VCSH foo add randomtexttofind && - - : | $VCSH delete foo | assert_grep -F randomtexttofind' - -test_done diff --git a/t/delete8.t b/t/delete8.t deleted file mode 100755 index 77446c16..00000000 --- a/t/delete8.t +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -test_description='Delete command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -# Do we actually want this? -test_expect_failure 'Delete lists files staged for removal before confirmation' \ - '$VCSH init foo && - touch randomtexttofind && - $VCSH foo add randomtexttofind && - $VCSH foo commit -m 'a' && - $VCSH foo rm --cached randomtexttofind && - - : | $VCSH delete foo | assert_grep -F randomtexttofind' - -test_done diff --git a/t/delete9.t b/t/delete9.t deleted file mode 100755 index 911b7b65..00000000 --- a/t/delete9.t +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -test_description='Delete command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Delete removes corresponding files' \ - '$VCSH init foo && - $VCSH init bar && - - touch a b c d e && - $VCSH foo add b e && - $VCSH foo commit -m "b e" && - $VCSH bar add a c && - $VCSH bar commit -m "a c" && - - doit | $VCSH delete foo && - test_path_is_missing b && - test_path_is_missing e && - test_path_is_file a && - test_path_is_file c && - test_path_is_file d && - - doit | $VCSH delete bar && - test_path_is_missing a && - test_path_is_missing c && - test_path_is_file d' - -test_done From ffdc9a2ed2e68379a1e46883df68de710c12f62a Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 19 May 2017 01:20:24 -0500 Subject: [PATCH 102/151] condense rename tests --- t/rename.t | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ t/rename0.t | 12 --------- t/rename1.t | 11 -------- t/rename2.t | 14 ---------- t/rename3.t | 16 ------------ t/rename4.t | 19 -------------- t/rename5.t | 19 -------------- t/rename6.t | 19 -------------- t/rename7.t | 20 -------------- 9 files changed, 75 insertions(+), 130 deletions(-) create mode 100755 t/rename.t delete mode 100755 t/rename0.t delete mode 100755 t/rename1.t delete mode 100755 t/rename2.t delete mode 100755 t/rename3.t delete mode 100755 t/rename4.t delete mode 100755 t/rename5.t delete mode 100755 t/rename6.t delete mode 100755 t/rename7.t diff --git a/t/rename.t b/t/rename.t new file mode 100755 index 00000000..1e8ddb38 --- /dev/null +++ b/t/rename.t @@ -0,0 +1,75 @@ +#!/bin/bash + +test_description='Rename command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Setup' \ + 'test_create_repo repo && + test_commit -C repo A && + test_commit -C repo B' + +test_expect_success 'Repository to be renamed must exist' \ + 'test_must_fail $VCSH rename foo bar' + +test_expect_success 'Rename works on empty repository' \ + '$VCSH init foo && + $VCSH rename foo bar && + + echo bar >expected && + $VCSH list >output && + test_cmp expected output' + +test_expect_success 'Rename works on repository with files/commits' \ + 'git -C repo rev-parse HEAD >expected && + + $VCSH clone ./repo foo && + $VCSH rename foo baz && + $VCSH baz rev-parse HEAD >output && + test_cmp expected output' + +test_expect_success 'Rename requires two arguments' \ + 'test_must_fail $VCSH rename && + test_must_fail $VCSH rename bar' + +test_expect_success 'Target of rename must not already exist' \ + 'test_must_fail $VCSH rename bar baz' + +test_expect_success 'Rename adopts existing .gitignore.d files under new name (bug?)' \ + 'mkdir -p .gitignore.d && + echo test > .gitignore.d/foo && + + $VCSH rename bar foo && + echo ".gitignore.d/foo" >expected && + $VCSH foo ls-files >output && + test_cmp expected output' + +test_expect_success 'Rename adopts existing .gitattributes.d files under new name (bug?)' \ + '$VCSH init bar && + + mkdir -p .gitattributes.d && + echo "* whitespace" > .gitattributes.d/fribble && + + $VCSH rename bar fribble && + echo ".gitattributes.d/fribble" >expected && + $VCSH fribble ls-files >output && + test_cmp expected output' + +test_expect_success 'Rename can be abbreviated (renam, rena, ren, re)' \ + '$VCSH init name1 && + + $VCSH renam name1 name2 && + $VCSH rena name2 name3 && + $VCSH ren name3 name4 && + $VCSH re name4 name5 && + + echo name5 >expected && + $VCSH list >output && + assert_grep -Fx name5 expected && - $VCSH list >output && - test_cmp expected output' - -test_done diff --git a/t/rename4.t b/t/rename4.t deleted file mode 100755 index 6c59238e..00000000 --- a/t/rename4.t +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -test_description='Rename command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Rename works on repository with files/commits' \ - 'test_create_repo repo && - test_commit -C repo A && - test_commit -C repo B && - git -C repo rev-parse HEAD >expected && - - $VCSH clone ./repo foo && - $VCSH rename foo bar && - $VCSH bar rev-parse HEAD >output && - test_cmp expected output' - -test_done diff --git a/t/rename5.t b/t/rename5.t deleted file mode 100755 index 83b790ea..00000000 --- a/t/rename5.t +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -test_description='Rename command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Rename adopts existing .gitignore.d files under new name (bug?)' \ - '$VCSH init foo && - - mkdir -p .gitignore.d && - echo test > .gitignore.d/bar && - - $VCSH rename foo bar && - echo ".gitignore.d/bar" >expected && - $VCSH bar ls-files >output && - test_cmp expected output' - -test_done diff --git a/t/rename6.t b/t/rename6.t deleted file mode 100755 index 49402222..00000000 --- a/t/rename6.t +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -test_description='Rename command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Rename adopts existing .gitattributes.d files under new name (bug?)' \ - '$VCSH init foo && - - mkdir -p .gitattributes.d && - echo "* whitespace" > .gitattributes.d/bar && - - $VCSH rename foo bar && - echo ".gitattributes.d/bar" >expected && - $VCSH bar ls-files >output && - test_cmp expected output' - -test_done diff --git a/t/rename7.t b/t/rename7.t deleted file mode 100755 index d98e0116..00000000 --- a/t/rename7.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Rename command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Rename can be abbreviated (renam, rena, ren, re)' \ - '$VCSH init foo && - - $VCSH renam foo bar && - $VCSH rena bar baz && - $VCSH ren baz bat && - $VCSH re bat quux && - - echo quux >expected && - $VCSH list >output && - test_cmp expected output' - -test_done From 1456ddb9ad03841edd1517ebbfd1ed7be5f3762e Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 19 May 2017 01:31:55 -0500 Subject: [PATCH 103/151] condense which tests --- t/which.t | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++ t/which0.t | 12 -------- t/which1.t | 11 ------- t/which10.t | 21 ------------- t/which11.t | 28 ------------------ t/which2.t | 11 ------- t/which3.t | 17 ----------- t/which4.t | 19 ------------ t/which5.t | 20 ------------- t/which6.t | 20 ------------- t/which7.t | 20 ------------- t/which8.t | 20 ------------- t/which9.t | 20 ------------- 13 files changed, 85 insertions(+), 219 deletions(-) create mode 100755 t/which.t delete mode 100755 t/which0.t delete mode 100755 t/which1.t delete mode 100755 t/which10.t delete mode 100755 t/which11.t delete mode 100755 t/which2.t delete mode 100755 t/which3.t delete mode 100755 t/which4.t delete mode 100755 t/which5.t delete mode 100755 t/which6.t delete mode 100755 t/which7.t delete mode 100755 t/which8.t delete mode 100755 t/which9.t diff --git a/t/which.t b/t/which.t new file mode 100755 index 00000000..f790d005 --- /dev/null +++ b/t/which.t @@ -0,0 +1,85 @@ +#!/bin/bash + +test_description='Which command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Which command does not accept an empty parameter' \ + 'test_must_fail $VCSH which ""' + +test_expect_success 'Which command fails if no repositories' \ + 'test_must_fail $VCSH which nope' + +test_expect_success '(setup) Create repository "foo"' \ + '$VCSH init foo && + + mkdir -p dir/subd && + touch testfile dir/subfile dir/subd/bar calor color colour "colou?r" && + $VCSH foo add * && + $VCSH foo commit -m "commit"' + +test_expect_success 'Which command fails if pattern not found' \ + 'test_must_fail $VCSH which nope' + +test_expect_success 'Which command requires exactly one parameter' \ + 'test_must_fail $VCSH which && + test_must_fail $VCSH which foo bar' + +test_expect_success 'Which command matches exact filename' \ + 'echo "foo: testfile" >expected && + $VCSH which testfile >output && + test_cmp expected output' + +test_expect_success 'Which command matches entire path' \ + 'echo "foo: dir/subfile" >expected && + $VCSH which dir/subfile >output && + test_cmp expected output' + +test_expect_success 'Which command matches filename within subdirectory' \ + 'echo "foo: dir/subfile" >expected && + $VCSH which subfile >output && + test_cmp expected output' + +test_expect_success 'Which command matches directory path component' \ + 'echo "foo: dir/subd/bar" >expected && + $VCSH which subd >output && + test_cmp expected output' + +test_expect_success 'Which command matches partial filename' \ + 'echo "foo: dir/subfile" >expected && + $VCSH which ubfi >output && + test_cmp expected output' + +test_expect_success 'Which command matches partial path component across slash (bug?)' \ + 'echo "foo: dir/subd/bar" >expected && + $VCSH which bd/ba >output && + test_cmp expected output' + +test_expect_success 'Which command matches using POSIX BRE' \ + 'echo "foo: calor" >expected && + echo "foo: color" >>expected && + echo "foo: colour" >>expected && + $VCSH which "c.lou\\?r" >output && + test_cmp expected output' + +test_expect_success 'Which command searches all repos' \ + '$VCSH init bar && + $VCSH init baz && + + mkdir -p a b c && + touch {a,b,c}/{hello,goodbye} && + $VCSH foo add a && + $VCSH foo commit -m "hello" && + $VCSH bar add b && + $VCSH bar commit -m "hello" && + $VCSH baz add c && + $VCSH baz commit -m "hello" && + + echo "bar: b/hello" >expected && + echo "baz: c/hello" >>expected && + echo "foo: a/hello" >>expected && + $VCSH which hello >output && + test_cmp expected output' + +test_done diff --git a/t/which0.t b/t/which0.t deleted file mode 100755 index e097eb1d..00000000 --- a/t/which0.t +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -test_description='Which command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Which command requires exactly one parameter' \ - 'test_must_fail $VCSH which && - test_must_fail $VCSH which foo bar' - -test_done diff --git a/t/which1.t b/t/which1.t deleted file mode 100755 index 2eee1de5..00000000 --- a/t/which1.t +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -test_description='Which command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Which command does not accept an empty parameter' \ - 'test_must_fail $VCSH which ""' - -test_done diff --git a/t/which10.t b/t/which10.t deleted file mode 100755 index 7489209d..00000000 --- a/t/which10.t +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -test_description='Which command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Which command matches using POSIX BRE' \ - '$VCSH init foo && - - touch calor color colour 'colou?r' && - $VCSH foo add * && - $VCSH foo commit -m 'color' && - - echo "foo: calor" >expected && - echo "foo: color" >>expected && - echo "foo: colour" >>expected && - $VCSH which "c.lou\\?r" >output && - test_cmp expected output' - -test_done diff --git a/t/which11.t b/t/which11.t deleted file mode 100755 index 9d01af64..00000000 --- a/t/which11.t +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -test_description='Which command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Which command searches all repos' \ - '$VCSH init foo && - $VCSH init bar && - $VCSH init baz && - - mkdir -p a b c && - touch {a,b,c}/{hello,goodbye} && - $VCSH foo add a && - $VCSH foo commit -m "hello" && - $VCSH bar add b && - $VCSH bar commit -m "hello" && - $VCSH baz add c && - $VCSH baz commit -m "hello" && - - echo "bar: b/hello" >expected && - echo "baz: c/hello" >>expected && - echo "foo: a/hello" >>expected && - $VCSH which hello >output && - test_cmp expected output' - -test_done diff --git a/t/which2.t b/t/which2.t deleted file mode 100755 index 60d7e303..00000000 --- a/t/which2.t +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -test_description='Which command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Which command fails if no repositories' \ - 'test_must_fail $VCSH which nope' - -test_done diff --git a/t/which3.t b/t/which3.t deleted file mode 100755 index f926d758..00000000 --- a/t/which3.t +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -test_description='Which command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Which command fails if pattern not found' \ - '$VCSH init foo && - - touch a && - $VCSH foo add a && - $VCSH foo commit -m "a" && - - test_must_fail $VCSH which nope' - -test_done diff --git a/t/which4.t b/t/which4.t deleted file mode 100755 index e2c23fd7..00000000 --- a/t/which4.t +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -test_description='Which command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Which command matches exact filename' \ - '$VCSH init foo && - - touch hello testfile && - $VCSH foo add hello testfile && - $VCSH foo commit -m "testfile" && - - echo "foo: testfile" >expected && - $VCSH which testfile >output && - test_cmp expected output' - -test_done diff --git a/t/which5.t b/t/which5.t deleted file mode 100755 index 3cf1b6cf..00000000 --- a/t/which5.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Which command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Which command matches entire path' \ - '$VCSH init foo && - - mkdir -p dir && - touch hello dir/testfile && - $VCSH foo add hello dir/testfile && - $VCSH foo commit -m 'dir/testfile' && - - echo "foo: dir/testfile" >expected && - $VCSH which dir/testfile >output && - test_cmp expected output' - -test_done diff --git a/t/which6.t b/t/which6.t deleted file mode 100755 index 289b428e..00000000 --- a/t/which6.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Which command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Which command matches filename within subdirectory' \ - '$VCSH init foo && - - mkdir -p dir && - touch hello dir/testfile && - $VCSH foo add hello dir/testfile && - $VCSH foo commit -m "dir/testfile" && - - echo "foo: dir/testfile" >expected && - $VCSH which testfile >output && - test_cmp expected output' - -test_done diff --git a/t/which7.t b/t/which7.t deleted file mode 100755 index 1ad37896..00000000 --- a/t/which7.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Which command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Which command matches directory path component' \ - '$VCSH init foo && - - mkdir -p dir/subd && - touch hello dir/subd/testfile && - $VCSH foo add hello dir/subd/testfile && - $VCSH foo commit -m "dir/subd/testfile" && - - echo "foo: dir/subd/testfile" >expected && - $VCSH which subd >output && - test_cmp expected output' - -test_done diff --git a/t/which8.t b/t/which8.t deleted file mode 100755 index 8b1e8b4e..00000000 --- a/t/which8.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Which command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Which command matches partial filename' \ - '$VCSH init foo && - - mkdir -p dir/subd && - touch hello dir/subd/testfile && - $VCSH foo add hello dir/subd/testfile && - $VCSH foo commit -m "dir/subd/testfile" && - - echo "foo: dir/subd/testfile" >expected && - $VCSH which estf >output && - test_cmp expected output' - -test_done diff --git a/t/which9.t b/t/which9.t deleted file mode 100755 index 6f4e14ea..00000000 --- a/t/which9.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Which command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Which command matches partial path component across slash' \ - '$VCSH init foo && - - mkdir -p dir/subd && - touch hello dir/subd/testfile && - $VCSH foo add hello dir/subd/testfile && - $VCSH foo commit -m 'dir/subd/testfile' && - - echo "foo: dir/subd/testfile" >expected && - $VCSH which bd/te >output && - test_cmp expected output' - -test_done From 2b713a9d89a7484bf0ba6423a1dd96e455bb5c94 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 19 May 2017 01:48:25 -0500 Subject: [PATCH 104/151] condense clone tests --- t/clone.t | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++ t/clone1.t | 11 ----- t/clone10.t | 19 --------- t/clone11.t | 29 ------------- t/clone2.t | 24 ----------- t/clone3.t | 17 -------- t/clone4.t | 17 -------- t/clone5.t | 20 --------- t/clone6.t | 20 --------- t/clone7.t | 20 --------- t/clone8.t | 20 --------- t/clone9.t | 20 --------- 12 files changed, 115 insertions(+), 217 deletions(-) create mode 100755 t/clone.t delete mode 100755 t/clone1.t delete mode 100755 t/clone10.t delete mode 100755 t/clone11.t delete mode 100755 t/clone2.t delete mode 100755 t/clone3.t delete mode 100755 t/clone4.t delete mode 100755 t/clone5.t delete mode 100755 t/clone6.t delete mode 100755 t/clone7.t delete mode 100755 t/clone8.t delete mode 100755 t/clone9.t diff --git a/t/clone.t b/t/clone.t new file mode 100755 index 00000000..c03a4e52 --- /dev/null +++ b/t/clone.t @@ -0,0 +1,115 @@ +#!/bin/bash + +test_description='Clone command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'Setup' \ + 'test_create_repo repo && + test_commit -C repo A && + git -C repo checkout -b branchb && + test_commit -C repo A2 && + git -C repo checkout master && + + test_create_repo repo2 && + test_commit -C repo2 B && + + git clone --bare repo2 repo3.git' + +test_expect_success 'Clone requires a remote' \ + 'test_must_fail $VCSH clone' + +test_expect_success 'Clone uses existing repo name by default' \ + '$VCSH clone ./repo && + echo "repo" >expected && + $VCSH list >output && + + $VCSH clone ./repo3.git && + echo "repo3" >>expected && + $VCSH list >output && + test_cmp expected output && + + doit | $VCSH delete repo && + doit | $VCSH delete repo3' + +test_expect_success 'Clone honors specified repo name' \ + '$VCSH clone ./repo foo && + echo foo >expected && + $VCSH list >output && + test_cmp expected output' + +test_expect_success 'Clone defaults to HEAD of given remote' \ + 'git -C repo rev-parse HEAD >expected && + $VCSH foo rev-parse HEAD >output && + test_cmp expected output && + + doit | $VCSH delete foo' + +test_expect_success 'Clone can be abbreviated (clon, clo, cl)' \ + '$VCSH clon ./repo a && + echo a >expected && + $VCSH list >output && + test_cmp expected output && + doit | $VCSH delete a && + + $VCSH clo ./repo b && + echo b >expected && + $VCSH list >output && + test_cmp expected output && + doit | $VCSH delete b && + + $VCSH cl ./repo c && + echo c >expected && + $VCSH list >output && + test_cmp expected output && + doit | $VCSH delete c' + +test_expect_success 'Clone honors -b option before remote' \ + '$VCSH clone -b branchb ./repo && + git -C repo rev-parse branchb >expected && + $VCSH repo rev-parse HEAD >output && + test_cmp expected output && + + doit | $VCSH delete repo' + +test_expect_success 'Clone honors -b option before remote and repo name' \ + '$VCSH clone -b branchb ./repo foo && + git -C repo rev-parse branchb >expected && + $VCSH foo rev-parse HEAD >output && + test_cmp expected output && + + doit | $VCSH delete foo' + +test_expect_success 'Clone honors -b option after remote' \ + '$VCSH clone ./repo -b branchb && + git -C repo rev-parse branchb >expected && + $VCSH repo rev-parse HEAD >output && + test_cmp expected output && + + doit | $VCSH delete repo' + +test_expect_success 'Clone honors -b option between remote and repo name' \ + '$VCSH clone ./repo -b branchb foo && + git -C repo rev-parse branchb >expected && + $VCSH foo rev-parse HEAD >output && + test_cmp expected output && + + doit | $VCSH delete foo' + +test_expect_success 'Clone honors -b option after repo name' \ + '$VCSH clone ./repo foo -b branchb && + git -C repo rev-parse branchb >expected && + $VCSH foo rev-parse HEAD >output && + test_cmp expected output && + + doit | $VCSH delete foo' + +test_expect_success 'Clone -b option clones only one branch' \ + '$VCSH clone -b branchb ./repo foo && + $VCSH foo show-ref --heads >output && + test_line_count = 1 output && + + doit | $VCSH delete foo' + +test_done diff --git a/t/clone1.t b/t/clone1.t deleted file mode 100755 index 720b032f..00000000 --- a/t/clone1.t +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -test_description='Clone command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Clone requires a remote' \ - 'test_must_fail $VCSH clone' - -test_done diff --git a/t/clone10.t b/t/clone10.t deleted file mode 100755 index 8433f7f9..00000000 --- a/t/clone10.t +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -test_description='Clone command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Clone -b option clones only one branch' \ - 'test_create_repo repo && - test_commit -C repo A && - git -C repo checkout -b branchb && - test_commit -C repo B && - git -C repo checkout master && - - $VCSH clone -b branchb ./repo foo && - $VCSH foo show-ref --heads >output && - test_line_count = 1 output' - -test_done diff --git a/t/clone11.t b/t/clone11.t deleted file mode 100755 index 2f46baab..00000000 --- a/t/clone11.t +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -test_description='Clone command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Clone can be abbreviated (clon, clo, cl)' \ - 'test_create_repo repo && - test_commit -C repo A && - git -C repo checkout --orphan branchb && - git -C repo rm -rf . && - test_commit -C repo B && - git -C repo checkout --orphan branchc && - git -C repo rm -rf . && - test_commit -C repo C && - git -C repo checkout master && - - $VCSH clon ./repo a && - $VCSH clo -b branchb ./repo b && - $VCSH cl -b branchc ./repo c && - - echo a > expected && - echo b >> expected && - echo c >> expected && - $VCSH list >output && - test_cmp expected output' - -test_done diff --git a/t/clone2.t b/t/clone2.t deleted file mode 100755 index 1cdd9eed..00000000 --- a/t/clone2.t +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -test_description='Clone command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Clone uses existing repo name by default' \ - 'test_create_repo repo1 && - test_create_repo repo2 && - test_commit -C repo1 A && - test_commit -C repo2 B && - git clone --bare repo2 repo3.git && - - $VCSH clone ./repo && - echo "repo" >expected && - $VCSH list >output && - - $VCSH clone ./repo3.git && - echo "repo3" >>expected && - $VCSH list >output && - test_cmp expected output' - -test_done diff --git a/t/clone3.t b/t/clone3.t deleted file mode 100755 index e4e639c4..00000000 --- a/t/clone3.t +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -test_description='Clone command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Clone honors specified repo name' \ - 'test_create_repo repo && - test_commit -C repo A && - - $VCSH clone ./repo foo && - echo foo >expected && - $VCSH list >output && - test_cmp expected output' - -test_done diff --git a/t/clone4.t b/t/clone4.t deleted file mode 100755 index 7a4a696f..00000000 --- a/t/clone4.t +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -test_description='Clone command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Clone uses given remote HEAD by default' \ - 'test_create_repo repo && - test_commit -C repo A && - $VCSH clone ./repo foo && - - git -C repo rev-parse HEAD >expected && - $VCSH foo rev-parse HEAD >output && - test_cmp expected output' - -test_done diff --git a/t/clone5.t b/t/clone5.t deleted file mode 100755 index 85287853..00000000 --- a/t/clone5.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Clone command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Clone honors -b option before remote' \ - 'test_create_repo repo && - test_commit -C repo A && - git -C repo checkout -b branchb && - test_commit -C repo B && - git -C repo checkout master && - - $VCSH clone -b branchb ./repo && - git -C repo rev-parse branchb >expected && - $VCSH repo rev-parse HEAD >output && - test_cmp expected output' - -test_done diff --git a/t/clone6.t b/t/clone6.t deleted file mode 100755 index f001d8e1..00000000 --- a/t/clone6.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Clone command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Clone honors -b option before remote and repo name' \ - 'test_create_repo repo && - test_commit -C repo A && - git -C repo checkout -b branchb && - test_commit -C repo B && - git -C repo checkout master && - - $VCSH clone -b branchb ./repo foo && - git -C repo rev-parse branchb >expected && - $VCSH foo rev-parse HEAD >output && - test_cmp expected output' - -test_done diff --git a/t/clone7.t b/t/clone7.t deleted file mode 100755 index 3e8dfc40..00000000 --- a/t/clone7.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Clone command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Clone honors -b option after remote' \ - 'test_create_repo repo && - test_commit -C repo A && - git -C repo checkout -b branchb && - test_commit -C repo B && - git -C repo checkout master && - - $VCSH clone ./repo -b branchb && - git -C repo rev-parse branchb >expected && - $VCSH repo rev-parse HEAD >output && - test_cmp expected output' - -test_done diff --git a/t/clone8.t b/t/clone8.t deleted file mode 100755 index f845d86f..00000000 --- a/t/clone8.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Clone command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Clone honors -b option between remote and repo name' \ - 'test_create_repo repo && - test_commit -C repo A && - git -C repo checkout -b branchb && - test_commit -C repo B && - git -C repo checkout master && - - $VCSH clone ./repo -b branchb foo && - git -C repo rev-parse branchb >expected && - $VCSH foo rev-parse HEAD >output && - test_cmp expected output' - -test_done diff --git a/t/clone9.t b/t/clone9.t deleted file mode 100755 index abab024b..00000000 --- a/t/clone9.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Clone command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'Clone honors -b option after repo name' \ - 'test_create_repo repo && - test_commit -C repo A && - git -C repo checkout -b branchb && - test_commit -C repo B && - git -C repo checkout master && - - $VCSH clone ./repo foo -b branchb && - git -C repo rev-parse branchb >expected && - $VCSH foo rev-parse HEAD >output && - test_cmp expected output' - -test_done From a66c08d94bd85ded4e6a49eafbaa430c1da85bc7 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 19 May 2017 01:56:48 -0500 Subject: [PATCH 105/151] condense commit tests --- t/commit.t | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ t/commit0.t | 12 --------- t/commit1.t | 24 ----------------- t/commit2.t | 27 ------------------- t/commit3.t | 21 --------------- t/commit4.t | 23 ----------------- t/commit5.t | 14 ---------- 7 files changed, 74 insertions(+), 121 deletions(-) create mode 100755 t/commit.t delete mode 100755 t/commit0.t delete mode 100755 t/commit1.t delete mode 100755 t/commit2.t delete mode 100755 t/commit3.t delete mode 100755 t/commit4.t delete mode 100755 t/commit5.t diff --git a/t/commit.t b/t/commit.t new file mode 100755 index 00000000..d36c7da1 --- /dev/null +++ b/t/commit.t @@ -0,0 +1,74 @@ +#!/bin/bash + +test_description='Commit command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'commit works with no repos' \ + '$VCSH commit >output && + test_must_be_empty output' + +# Commit is broken +test_expect_failure 'commit works with single repo' \ + '$VCSH init foo && + + touch single && + $VCSH foo add single && + # XXX Is printing a trailing space really intended? + echo "foo: " >expected && + echo "" >>expected && + $VCSH commit -m "single" >output && + test_cmp expected output && + + echo 1 >expected && + $VCSH foo rev-list HEAD --count >output && + test_cmp expected output' + +# Commit is broken +test_expect_failure 'commit works with multiple repos' \ + '$VCSH init bar && + + touch multi1 multi2 && + $VCSH foo add multi1 && + $VCSH bar add multi2 && + # XXX Is printing a trailing space and blank line really intended? + echo "bar: " >expected && + echo "" >>expected && + echo "foo: " >>expected && + echo "" >>expected && + $VCSH commit -m "multiple" >output && + test_cmp expected output && + + $VCSH foo log --oneline | assert_grep -x "....... multiple" && + $VCSH bar log --oneline | assert_grep -x "....... multiple"' + +# Commit is broken +test_expect_failure 'commit can handle arguments with spaces' \ + 'touch msg1 msg2 && + $VCSH foo add msg1 && + $VCSH bar add msg2 && + $VCSH commit -m "log message" && + + $VCSH foo log --oneline | assert_grep -x "....... log message" && + $VCSH bar log --oneline | assert_grep -x "....... log message"' + +# Commit is broken +test_expect_failure 'commit works even if not all repos have changes' \ + 'touch part1 part2 && + $VCSH foo add part1 && + $VCSH commit -m "part1" && + + $VCSH bar add part2 && + $VCSH commit -m "part2" && + + $VCSH foo log --oneline | assert_grep -x "....... part1" && + $VCSH bar log --oneline | assert_grep -x "....... part2"' + +# Known bug +test_expect_failure 'commit not affected by existing $VCSH_COMMAND_RETURN_CODE' \ + 'VCSH_COMMAND_RETURN_CODE=1 && + export VCSH_COMMAND_RETURN_CODE && + $VCSH commit' + +test_done diff --git a/t/commit0.t b/t/commit0.t deleted file mode 100755 index 37c47ccf..00000000 --- a/t/commit0.t +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -test_description='Commit command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'commit works with no repos' \ - '$VCSH commit >output && - test_must_be_empty output' - -test_done diff --git a/t/commit1.t b/t/commit1.t deleted file mode 100755 index b40dc4f2..00000000 --- a/t/commit1.t +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -test_description='Commit command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -# Commit is broken -test_expect_failure 'commit works with single repo' \ - '$VCSH init foo && - - touch a && - $VCSH foo add a && - # XXX Is printing a trailing space really intended? - echo "foo: " >expected && - echo "" >>expected && - $VCSH commit -m a >output && - test_cmp expected output && - - echo 1 >expected && - $VCSH foo rev-list HEAD --count >output && - test_cmp expected output' - -test_done diff --git a/t/commit2.t b/t/commit2.t deleted file mode 100755 index ce0248e5..00000000 --- a/t/commit2.t +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -test_description='Commit command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -# Commit is broken -test_expect_failure 'commit works with multiple repos' \ - '$VCSH init foo && - $VCSH init bar && - - touch a b && - $VCSH foo add a && - $VCSH bar add b && - # XXX Is printing a trailing space and blank line really intended? - echo "bar: " >expected && - echo "" >>expected && - echo "foo: " >>expected && - echo "" >>expected && - $VCSH commit -m "ab" >output && - test_cmp expected output && - - $VCSH foo log --oneline | assert_grep -x "....... ab" && - $VCSH bar log --oneline | assert_grep -x "....... ab"' - -test_done diff --git a/t/commit3.t b/t/commit3.t deleted file mode 100755 index 437dd750..00000000 --- a/t/commit3.t +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -test_description='Commit command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -# Commit is broken -test_expect_failure 'commit can handle arguments with spaces' \ - '$VCSH init foo && - $VCSH init bar && - - touch a b && - $VCSH foo add a && - $VCSH bar add b && - $VCSH commit -m "log message" && - - $VCSH foo log --oneline | assert_grep -x "....... log message" && - $VCSH bar log --oneline | assert_grep -x "....... log message"' - -test_done diff --git a/t/commit4.t b/t/commit4.t deleted file mode 100755 index 00991ae6..00000000 --- a/t/commit4.t +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -test_description='Commit command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -# Commit is broken -test_expect_failure 'commit works even if not all repos have changes' \ - '$VCSH init foo && - $VCSH init bar && - - touch a b && - $VCSH foo add a && - $VCSH commit -m "part1" && - - $VCSH bar add b && - $VCSH commit -m "part2" && - - $VCSH foo log --oneline | assert_grep -x "....... part1" && - $VCSH bar log --oneline | assert_grep -x "....... part2"' - -test_done diff --git a/t/commit5.t b/t/commit5.t deleted file mode 100755 index b42b0e3b..00000000 --- a/t/commit5.t +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -test_description='Commit command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -# Known bug -test_expect_failure 'commit not affected by existing $VCSH_COMMAND_RETURN_CODE' \ - 'VCSH_COMMAND_RETURN_CODE=1 && - export VCSH_COMMAND_RETURN_CODE && - $VCSH commit' - -test_done From bf008750fc080125fc6c894aa3a3ecab0b5c6b1e Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 19 May 2017 16:03:22 -0500 Subject: [PATCH 106/151] consolidate list-tracked tests --- t/list-tracked.t | 108 +++++++++++++++++++++++++++++++++++++++++++++ t/list-tracked0.t | 12 ----- t/list-tracked1.t | 14 ------ t/list-tracked10.t | 11 ----- t/list-tracked11.t | 11 ----- t/list-tracked12.t | 32 -------------- t/list-tracked2.t | 11 ----- t/list-tracked3.t | 15 ------- t/list-tracked4.t | 22 --------- t/list-tracked5.t | 27 ------------ t/list-tracked6.t | 32 -------------- t/list-tracked7.t | 27 ------------ t/list-tracked8.t | 25 ----------- t/list-tracked9.t | 29 ------------ 14 files changed, 108 insertions(+), 268 deletions(-) create mode 100755 t/list-tracked.t delete mode 100755 t/list-tracked0.t delete mode 100755 t/list-tracked1.t delete mode 100755 t/list-tracked10.t delete mode 100755 t/list-tracked11.t delete mode 100755 t/list-tracked12.t delete mode 100755 t/list-tracked2.t delete mode 100755 t/list-tracked3.t delete mode 100755 t/list-tracked4.t delete mode 100755 t/list-tracked5.t delete mode 100755 t/list-tracked6.t delete mode 100755 t/list-tracked7.t delete mode 100755 t/list-tracked8.t delete mode 100755 t/list-tracked9.t diff --git a/t/list-tracked.t b/t/list-tracked.t new file mode 100755 index 00000000..84e6a270 --- /dev/null +++ b/t/list-tracked.t @@ -0,0 +1,108 @@ +#!/bin/bash + +test_description='List-tracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'list-tracked works with no repos' \ + '$VCSH list-tracked &>output && + test_must_be_empty output' + +test_expect_success 'list-tracked command works with no repos and untracked files' \ + 'touch a b c d e && + + $VCSH list-tracked >output && + test_must_be_empty output' + +test_expect_failure 'list-tracked fails if argument is not a repo' \ + 'test_must_fail $VCSH list-tracked nope' + +test_expect_success 'list-tracked works on empty repo' \ + '$VCSH init foo && + $VCSH list-tracked >output && + test_must_be_empty output' + +test_expect_success 'list-tracked works on specified empty repo' \ + '$VCSH list-tracked foo >output && + test_must_be_empty output' + +test_expect_success 'list-tracked lists files from one repo' \ + '$VCSH foo add a d && + $VCSH foo commit -m "a d" && + + { + echo "$HOME/a" && + echo "$HOME/d" + } >expected && + $VCSH list-tracked >output && + test_cmp expected output' + +test_expect_success 'list-tracked lists files from two repos' \ + '$VCSH init bar && + + $VCSH bar add b e && + $VCSH bar commit -m "b e" && + + { + echo "$HOME/a" && + echo "$HOME/b" && + echo "$HOME/d" && + echo "$HOME/e" + } >expected && + $VCSH list-tracked >output && + test_cmp expected output' + +test_expect_success 'list-tracked lists files from specified repo' \ + '{ + echo "$HOME/a" && + echo "$HOME/d" + } >expected && + $VCSH list-tracked foo >output && + test_cmp expected output && + + { + echo "$HOME/b" && + echo "$HOME/e" + } >expected && + $VCSH list-tracked bar >output && + test_cmp expected output' + +test_expect_success 'list-tracked does not repeat multiple-tracked files' \ + 'rev=$($VCSH bar rev-parse HEAD) && + $VCSH bar add a && + $VCSH bar commit -m "a" && + + { + echo "$HOME/a" && + echo "$HOME/b" && + echo "$HOME/d" && + echo "$HOME/e" + } >expected && + $VCSH list-tracked >output && + test_cmp expected output && + + $VCSH bar reset --hard "$rev"' + +test_expect_success 'list-tracked-by requires an argument' \ + 'test_must_fail $VCSH list-tracked-by' + +test_expect_failure 'list-tracked-by fails if argument is not a repo' \ + 'test_must_fail $VCSH list-tracked-by nope' + +test_expect_success 'list-tracked-by lists files from specified repo' \ + '{ + echo "$HOME/a" && + echo "$HOME/d" + } >expected && + $VCSH list-tracked-by foo >output && + test_cmp expected output && + + { + echo "$HOME/b" && + echo "$HOME/e" + } >expected && + $VCSH list-tracked-by bar >output && + test_cmp expected output' + +test_done diff --git a/t/list-tracked0.t b/t/list-tracked0.t deleted file mode 100755 index abfae37e..00000000 --- a/t/list-tracked0.t +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -test_description='List-tracked command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'list-tracked works with no repos' \ - '$VCSH list-tracked &>output && - test_must_be_empty output' - -test_done diff --git a/t/list-tracked1.t b/t/list-tracked1.t deleted file mode 100755 index b69f244a..00000000 --- a/t/list-tracked1.t +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -test_description='List-tracked command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'list-tracked command works with no repos and untracked files' \ - 'touch a b c d e && - - $VCSH list-tracked >output && - test_must_be_empty output' - -test_done diff --git a/t/list-tracked10.t b/t/list-tracked10.t deleted file mode 100755 index d7c0688a..00000000 --- a/t/list-tracked10.t +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -test_description='List-tracked command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'list-tracked-by requires an argument' \ - 'test_must_fail $VCSH list-tracked-by' - -test_done diff --git a/t/list-tracked11.t b/t/list-tracked11.t deleted file mode 100755 index f5940e22..00000000 --- a/t/list-tracked11.t +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -test_description='List-tracked command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_failure 'list-tracked-by fails if argument is not a repo' \ - 'test_must_fail $VCSH list-tracked-by nope' - -test_done diff --git a/t/list-tracked12.t b/t/list-tracked12.t deleted file mode 100755 index b683fb19..00000000 --- a/t/list-tracked12.t +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -test_description='List-tracked command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'list-tracked-by lists files from specified repo' \ - '$VCSH init foo && - $VCSH init bar && - - touch a b c d e && - $VCSH foo add a b && - $VCSH foo commit -m "a b" && - $VCSH bar add c d && - $VCSH bar commit -m "c d" && - - { - echo "$HOME/a" && - echo "$HOME/b" - } >expected && - $VCSH list-tracked-by foo >output && - test_cmp expected output && - - { - echo "$HOME/c" && - echo "$HOME/d" - } >expected && - $VCSH list-tracked-by bar >output && - test_cmp expected output' - -test_done diff --git a/t/list-tracked2.t b/t/list-tracked2.t deleted file mode 100755 index 4c023d97..00000000 --- a/t/list-tracked2.t +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -test_description='List-tracked command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_failure 'list-tracked fails if argument is not a repo' \ - 'test_must_fail $VCSH list-tracked nope' - -test_done diff --git a/t/list-tracked3.t b/t/list-tracked3.t deleted file mode 100755 index d543026d..00000000 --- a/t/list-tracked3.t +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -test_description='List-tracked command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'list-tracked works on empty repo' \ - 'touch a b c d e && - - $VCSH init foo && - $VCSH list-tracked >output && - test_must_be_empty output' - -test_done diff --git a/t/list-tracked4.t b/t/list-tracked4.t deleted file mode 100755 index 4545f74b..00000000 --- a/t/list-tracked4.t +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -test_description='List-tracked command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'list-tracked lists files from one repo' \ - '$VCSH init foo && - - touch a b c d e && - $VCSH foo add a d && - $VCSH foo commit -m "a d" && - - { - echo "$HOME/a" && - echo "$HOME/d" - } >expected && - $VCSH list-tracked >output && - test_cmp expected output' - -test_done diff --git a/t/list-tracked5.t b/t/list-tracked5.t deleted file mode 100755 index a7d17499..00000000 --- a/t/list-tracked5.t +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -test_description='List-tracked command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'list-tracked lists files from two repos' \ - '$VCSH init foo && - $VCSH init bar && - - touch a b c d e && - $VCSH foo add a b && - $VCSH foo commit -m "a b" && - $VCSH bar add c d && - $VCSH bar commit -m "c d" && - - { - echo "$HOME/a" && - echo "$HOME/b" && - echo "$HOME/c" && - echo "$HOME/d" - } >expected && - $VCSH list-tracked >output && - test_cmp expected output' - -test_done diff --git a/t/list-tracked6.t b/t/list-tracked6.t deleted file mode 100755 index af40d958..00000000 --- a/t/list-tracked6.t +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -test_description='List-tracked command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'list-tracked lists files from specified repo' \ - '$VCSH init foo && - $VCSH init bar && - - touch a b c d e && - $VCSH foo add a b && - $VCSH foo commit -m "a b" && - $VCSH bar add c d && - $VCSH bar commit -m "c d" && - - { - echo "$HOME/a" && - echo "$HOME/b" - } >expected && - $VCSH list-tracked foo >output && - test_cmp expected output && - - { - echo "$HOME/c" && - echo "$HOME/d" - } >expected && - $VCSH list-tracked bar >output && - test_cmp expected output' - -test_done diff --git a/t/list-tracked7.t b/t/list-tracked7.t deleted file mode 100755 index 653373ec..00000000 --- a/t/list-tracked7.t +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -test_description='List-tracked command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'list-tracked orders files by path' \ - '$VCSH init foo && - $VCSH init bar && - - touch a b c d e && - $VCSH foo add a d && - $VCSH foo commit -m "a d" && - $VCSH bar add b e && - $VCSH bar commit -m "b e" && - - { - echo "$HOME/a" && - echo "$HOME/b" && - echo "$HOME/d" && - echo "$HOME/e" - } >expected && - $VCSH list-tracked >output && - test_cmp expected output' - -test_done diff --git a/t/list-tracked8.t b/t/list-tracked8.t deleted file mode 100755 index 0665e40d..00000000 --- a/t/list-tracked8.t +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -test_description='List-tracked command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'list-tracked does not repeat multiple-tracked files' \ - '$VCSH init foo && - $VCSH init bar && - - touch a b && - $VCSH foo add a b && - $VCSH foo commit -m "a b" && - $VCSH bar add a b && - $VCSH bar commit -m "a b" && - - { - echo "$HOME/a" && - echo "$HOME/b" - } >expected && - $VCSH list-tracked >output && - test_cmp expected output' - -test_done diff --git a/t/list-tracked9.t b/t/list-tracked9.t deleted file mode 100755 index 65eb50f3..00000000 --- a/t/list-tracked9.t +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -test_description='List-tracked command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'list-tracked accepts each repo for multiple-tracked files' \ - '$VCSH init foo && - $VCSH init bar && - - touch a b && - $VCSH foo add a b && - $VCSH foo commit -m "a b" && - $VCSH bar add a b && - $VCSH bar commit -m "a b" && - - { - echo "$HOME/a" && - echo "$HOME/b" - } >expected && - - $VCSH list-tracked foo >output && - test_cmp expected output && - - $VCSH list-tracked bar >output && - test_cmp expected output' - -test_done From 859b9bd136bbe212681079734848af05b76faf87 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 19 May 2017 16:04:11 -0500 Subject: [PATCH 107/151] ignore results and trash directories --- t/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 t/.gitignore diff --git a/t/.gitignore b/t/.gitignore new file mode 100644 index 00000000..17b1b974 --- /dev/null +++ b/t/.gitignore @@ -0,0 +1,2 @@ +/test-results/ +/trash directory.*/ From f2f55bc26e9f38398766877b7c6e69765232990f Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 19 May 2017 17:05:35 -0500 Subject: [PATCH 108/151] consolidate push and pull tests --- t/pull.t | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ t/pull0.t | 12 ---------- t/pull1.t | 17 -------------- t/pull2.t | 20 ---------------- t/pull3.t | 30 ------------------------ t/pull4.t | 21 ----------------- t/pull5.t | 21 ----------------- t/push.t | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ t/push0.t | 12 ---------- t/push1.t | 20 ---------------- t/push2.t | 22 ----------------- t/push3.t | 33 -------------------------- t/push4.t | 27 --------------------- t/push5.t | 27 --------------------- 14 files changed, 134 insertions(+), 262 deletions(-) create mode 100755 t/pull.t delete mode 100755 t/pull0.t delete mode 100755 t/pull1.t delete mode 100755 t/pull2.t delete mode 100755 t/pull3.t delete mode 100755 t/pull4.t delete mode 100755 t/pull5.t create mode 100755 t/push.t delete mode 100755 t/push0.t delete mode 100755 t/push1.t delete mode 100755 t/push2.t delete mode 100755 t/push3.t delete mode 100755 t/push4.t delete mode 100755 t/push5.t diff --git a/t/pull.t b/t/pull.t new file mode 100755 index 00000000..1964828c --- /dev/null +++ b/t/pull.t @@ -0,0 +1,64 @@ +#!/bin/bash + +test_description='Pull command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'pull works with no repositories' \ + '$VCSH pull >output && + test_must_be_empty output' + +test_expect_success 'pull succeeds if up-to-date' \ + 'test_create_repo repo && + test_commit -C repo A && + $VCSH clone ./repo foo && + + echo -e "foo: Already up-to-date.\\n" >expected && + $VCSH pull >output && + test_cmp expected output' + +test_expect_success 'pull works with one repository' \ + 'test_commit -C repo B && + git -C repo rev-parse HEAD >expected && + + $VCSH pull && + $VCSH foo rev-parse HEAD >output && + test_cmp expected output' + +test_expect_success 'pull works with multiple repositories' \ + 'test_create_repo repo2 && + test_commit -C repo2 C && + $VCSH clone ./repo2 bar && + + test_commit -C repo X && + git -C repo rev-parse HEAD >expected && + + $VCSH pull && + $VCSH foo rev-parse HEAD >output && + test_cmp expected output && + + test_commit -C repo2 Y && + git -C repo2 rev-parse HEAD >expected && + + $VCSH pull && + $VCSH bar rev-parse HEAD >output && + test_cmp expected output' + +test_expect_failure 'pull fails if first pull fails' \ + 'mv repo2 repo2.missing && + test_when_finished "mv repo2.missing repo2" && + + test_commit -C repo D && + + test_must_fail $VCSH pull' + +test_expect_success 'pull fails if last pull fails' \ + 'mv repo repo.missing && + test_when_finished "mv repo.missing repo" && + + test_commit -C repo2 E && + + test_must_fail $VCSH pull' + +test_done diff --git a/t/pull0.t b/t/pull0.t deleted file mode 100755 index 68541057..00000000 --- a/t/pull0.t +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -test_description='Pull command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'pull works with no repositories' \ - '$VCSH pull >output && - test_must_be_empty output' - -test_done diff --git a/t/pull1.t b/t/pull1.t deleted file mode 100755 index 6f6829f2..00000000 --- a/t/pull1.t +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -test_description='Pull command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'pull succeeds if up-to-date' \ - 'test_create_repo repo && - test_commit -C repo A && - $VCSH clone ./repo foo && - - echo -e "foo: Already up-to-date.\\n" >expected && - $VCSH pull >output && - test_cmp expected output' - -test_done diff --git a/t/pull2.t b/t/pull2.t deleted file mode 100755 index dca449a2..00000000 --- a/t/pull2.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Pull command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'pull works with one repository' \ - 'test_create_repo repo && - test_commit -C repo A && - $VCSH clone ./repo foo && - - test_commit -C repo B && - git -C repo rev-parse HEAD >expected && - - $VCSH pull && - $VCSH foo rev-parse HEAD >output && - test_cmp expected output' - -test_done diff --git a/t/pull3.t b/t/pull3.t deleted file mode 100755 index 10e3b37f..00000000 --- a/t/pull3.t +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -test_description='Pull command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'pull works with multiple repositories' \ - 'test_create_repo repo1 && - test_create_repo repo2 && - test_commit -C repo1 A && - test_commit -C repo2 B && - $VCSH clone ./repo1 foo && - $VCSH clone ./repo2 bar && - - test_commit -C repo1 X && - git -C repo1 rev-parse HEAD >expected && - - $VCSH pull && - $VCSH foo rev-parse HEAD >output && - test_cmp expected output && - - test_commit -C repo2 Y && - git -C repo2 rev-parse HEAD >expected && - - $VCSH pull && - $VCSH bar rev-parse HEAD >output && - test_cmp expected output' - -test_done diff --git a/t/pull4.t b/t/pull4.t deleted file mode 100755 index 3bb9db9c..00000000 --- a/t/pull4.t +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -test_description='Pull command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_failure 'pull fails if first pull fails' \ - 'test_create_repo repo1 && - test_create_repo repo2 && - test_commit -C repo1 A && - test_commit -C repo2 B && - $VCSH clone ./repo1 a && - $VCSH clone ./repo2 b && - - rm -rf repo1 && - test_commit -C repo2 X && - - test_must_fail $VCSH pull' - -test_done diff --git a/t/pull5.t b/t/pull5.t deleted file mode 100755 index fead2a94..00000000 --- a/t/pull5.t +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -test_description='Pull command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'pull fails if last pull fails' \ - 'test_create_repo repo1 && - test_create_repo repo2 && - test_commit -C repo1 A && - test_commit -C repo2 B && - $VCSH clone ./repo1 a && - $VCSH clone ./repo2 b && - - test_commit -C repo1 X && - rm -rf repo2 && - - test_must_fail $VCSH pull' - -test_done diff --git a/t/push.t b/t/push.t new file mode 100755 index 00000000..3dd8d062 --- /dev/null +++ b/t/push.t @@ -0,0 +1,70 @@ +#!/bin/bash + +test_description='Push command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.bash" + +test_expect_success 'push works with no repositories' \ + '$VCSH push &>output && + test_must_be_empty output' + +test_expect_success 'push succeeds if up-to-date' \ + 'test_create_repo repo && + test_commit -C repo A && + git clone --bare ./repo repo.git && + + $VCSH clone ./repo.git foo && + $VCSH foo config push.default simple && + + echo -e "foo: Everything up-to-date\\n" >expected && + $VCSH push &>output && + test_cmp expected output' + +test_expect_success 'push works with one repository' \ + '$VCSH foo commit --allow-empty -m "empty" && + $VCSH foo rev-parse HEAD >expected && + + $VCSH push && + git -C ./repo.git rev-parse HEAD >output && + test_cmp expected output' + +test_expect_success 'push works with multiple repositories' \ + 'test_create_repo repo2 && + test_commit -C repo2 C && + git clone --bare ./repo2 repo2.git && + + $VCSH clone ./repo2.git bar && + $VCSH bar config push.default simple && + + $VCSH foo commit --allow-empty -m "empty" && + $VCSH bar commit --allow-empty -m "empty" && + $VCSH push && + + $VCSH foo rev-parse HEAD >expected && + git -C repo.git rev-parse HEAD >output && + test_cmp expected output && + + $VCSH bar rev-parse HEAD >expected && + git -C repo2.git rev-parse HEAD >output && + test_cmp expected output' + +test_expect_failure 'push fails if first push fails' \ + '$VCSH foo commit --allow-empty -m "empty" && + $VCSH bar commit --allow-empty -m "empty" && + + mv repo2.git repo2.git.missing && + test_when_finished "mv repo2.git.missing repo2.git" && + + test_must_fail $VCSH push' + +test_expect_success 'push fails if first push fails' \ + '$VCSH foo commit --allow-empty -m "empty" && + $VCSH bar commit --allow-empty -m "empty" && + + mv repo.git repo.git.missing && + test_when_finished "mv repo.git.missing repo.git" && + + test_must_fail $VCSH push' + +test_done diff --git a/t/push0.t b/t/push0.t deleted file mode 100755 index 4815fbcb..00000000 --- a/t/push0.t +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -test_description='Push command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'push works with no repositories' \ - '$VCSH push &>output && - test_must_be_empty output' - -test_done diff --git a/t/push1.t b/t/push1.t deleted file mode 100755 index 97b59535..00000000 --- a/t/push1.t +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -test_description='Push command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'push succeeds if up-to-date' \ - 'test_create_repo repo && - test_commit -C repo A && - git clone --bare ./repo repo.git && - - $VCSH clone ./repo.git foo && - $VCSH foo config push.default simple && - - echo -e "foo: Everything up-to-date\\n" >expected && - $VCSH push &>output && - test_cmp expected output' - -test_done diff --git a/t/push2.t b/t/push2.t deleted file mode 100755 index 472365cc..00000000 --- a/t/push2.t +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -test_description='Push command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'push works with one repository' \ - 'test_create_repo repo && - test_commit -C repo A && - git clone --bare ./repo repo.git && - - $VCSH clone ./repo.git foo && - $VCSH foo config push.default simple && - $VCSH foo commit --allow-empty -m "empty" && - $VCSH foo rev-parse HEAD >expected && - - $VCSH push && - git -C ./repo.git rev-parse HEAD >output && - test_cmp expected output' - -test_done diff --git a/t/push3.t b/t/push3.t deleted file mode 100755 index a456a043..00000000 --- a/t/push3.t +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -test_description='Push command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'push works with multiple repositories' \ - 'test_create_repo repo1 && - test_create_repo repo2 && - test_commit -C repo1 A && - test_commit -C repo2 B && - git clone --bare ./repo1 repo1.git && - git clone --bare ./repo2 repo2.git && - - $VCSH clone repo1.git foo && - $VCSH foo config push.default simple && - $VCSH clone repo2.git bar && - $VCSH bar config push.default simple && - - $VCSH foo commit --allow-empty -m "empty" && - $VCSH bar commit --allow-empty -m "empty" && - $VCSH push && - - $VCSH foo rev-parse HEAD >expected && - git -C repo1.git rev-parse HEAD >output && - test_cmp expected output && - - $VCSH bar rev-parse HEAD >expected && - git -C repo2.git rev-parse HEAD >output && - test_cmp expected output' - -test_done diff --git a/t/push4.t b/t/push4.t deleted file mode 100755 index 8918348d..00000000 --- a/t/push4.t +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -test_description='Push command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_failure 'push fails if first push fails' \ - 'test_create_repo repo1 && - test_create_repo repo2 && - test_commit -C repo1 A && - test_commit -C repo2 B && - git clone --bare ./repo1 repo1.git && - git clone --bare ./repo2 repo2.git && - - $VCSH clone repo1.git a && - $VCSH a config push.default simple && - $VCSH clone repo2.git b && - $VCSH b config push.default simple && - - $VCSH a commit --allow-empty -m "empty" && - $VCSH b commit --allow-empty -m "empty" && - - rm -rf repo1.git && - test_must_fail $VCSH push' - -test_done diff --git a/t/push5.t b/t/push5.t deleted file mode 100755 index c4822837..00000000 --- a/t/push5.t +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -test_description='Push command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" - -test_expect_success 'push fails if last push fails' \ - 'test_create_repo repo1 && - test_create_repo repo2 && - test_commit -C repo1 A && - test_commit -C repo2 B && - git clone --bare ./repo1 repo1.git && - git clone --bare ./repo2 repo2.git && - - $VCSH clone repo1.git a && - $VCSH a config push.default simple && - $VCSH clone repo2.git b && - $VCSH b config push.default simple && - - $VCSH a commit --allow-empty -m "empty" && - $VCSH b commit --allow-empty -m "empty" && - - rm -rf repo2.git && - test_must_fail $VCSH push' - -test_done From 0eebc710c1cfaa0c38788e837afb03cfcc764486 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 19 May 2017 17:31:29 -0500 Subject: [PATCH 109/151] update badge to this branch --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 422aad8f..cb536908 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ vcsh - Version Control System for $HOME - multiple Git repositories in $HOME -[![Build Status](https://travis-ci.org/djpohly/vcsh.svg?branch=bats)](https://travis-ci.org/djpohly/vcsh) +[![Build Status](https://travis-ci.org/djpohly/vcsh.svg?branch=git-test-lib)](https://travis-ci.org/djpohly/vcsh) # Index From dc262fb73a5c32e7909ae74d56aa4e7828ac2e04 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 25 May 2017 01:42:44 -0500 Subject: [PATCH 110/151] remove some vestigial helper functions --- t/environment.bash | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/t/environment.bash b/t/environment.bash index 9d30bddd..32db1bda 100644 --- a/t/environment.bash +++ b/t/environment.bash @@ -1,14 +1,12 @@ # Command to run for vcsh (test-lib will put build dir at the head of PATH) -# To test other shells: "dash vcsh", "zsh vcsh", etc. -export VCSH="vcsh" +# To test other shells, run with VCSH="dash vcsh", VCSH="zsh vcsh", etc. +: "${VCSH:=vcsh}" +export VCSH # XXX Currently the /etc/vcsh/config file can affect testcases. # Perhaps it should be ignored if one exists in $XDG_CONFIG_HOME or was # specified with -c? -# Other things used in tests -export GITVERSION=$(git version) - # Clear out environment variables that affect VCSH behavior unset VCSH_OPTION_CONFIG VCSH_REPO_D VCSH_HOOK_D VCSH_OVERLAY_D unset VCSH_BASE VCSH_GITIGNORE VCSH_GITATTRIBUTES VCSH_WORKTREE @@ -22,41 +20,6 @@ num_gitrepos() { find_gitrepos "$@" | wc -l } -assert() { - if [ $# -ne 3 ]; then - echo 'assert: requires three arguments (forgot to quote?)' >&2 - return 2 - fi - - if ! test "$@"; then - echo "assertion \"$2\" failed" >&2 - echo "actual : \"$1\"" >&2 - echo "reference: \"$3\"" >&2 - return 1 - fi -} - -assert_file() { - negate= - if [ "$1" = "!" ]; then - if [ $# -ne 3 ]; then - echo 'assert_file: requires two arguments after ! (forgot to quote?)' >&2 - return 2 - fi - negate='! ' - shift - elif [ $# -ne 2 ]; then - echo 'assert_file: requires two arguments (forgot to quote?)' >&2 - return 2 - fi - - if ! test $negate "$@"; then - echo "assertion \"$negate$1\" failed" >&2 - echo "file: \"$2\"" >&2 - return 1 - fi -} - # Similar to grep -q, but prints the entire input to stderr for debugging assert_grep() { tee /dev/stderr | grep "$@" > /dev/null From 3b759416dea5da9fd3815ad8a755aee906f029e9 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 25 May 2017 01:43:56 -0500 Subject: [PATCH 111/151] s/assert_grep/test_grep/ to match convention --- t/commit.t | 12 ++++++------ t/debug.t | 4 ++-- t/delete.t | 12 ++++++------ t/environment.bash | 2 +- t/help.t | 8 ++++---- t/init.t | 2 +- t/rename.t | 10 +++++----- t/version.t | 4 ++-- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/t/commit.t b/t/commit.t index d36c7da1..9ed180e9 100755 --- a/t/commit.t +++ b/t/commit.t @@ -40,8 +40,8 @@ test_expect_failure 'commit works with multiple repos' \ $VCSH commit -m "multiple" >output && test_cmp expected output && - $VCSH foo log --oneline | assert_grep -x "....... multiple" && - $VCSH bar log --oneline | assert_grep -x "....... multiple"' + $VCSH foo log --oneline | test_grep -x "....... multiple" && + $VCSH bar log --oneline | test_grep -x "....... multiple"' # Commit is broken test_expect_failure 'commit can handle arguments with spaces' \ @@ -50,8 +50,8 @@ test_expect_failure 'commit can handle arguments with spaces' \ $VCSH bar add msg2 && $VCSH commit -m "log message" && - $VCSH foo log --oneline | assert_grep -x "....... log message" && - $VCSH bar log --oneline | assert_grep -x "....... log message"' + $VCSH foo log --oneline | test_grep -x "....... log message" && + $VCSH bar log --oneline | test_grep -x "....... log message"' # Commit is broken test_expect_failure 'commit works even if not all repos have changes' \ @@ -62,8 +62,8 @@ test_expect_failure 'commit works even if not all repos have changes' \ $VCSH bar add part2 && $VCSH commit -m "part2" && - $VCSH foo log --oneline | assert_grep -x "....... part1" && - $VCSH bar log --oneline | assert_grep -x "....... part2"' + $VCSH foo log --oneline | test_grep -x "....... part1" && + $VCSH bar log --oneline | test_grep -x "....... part2"' # Known bug test_expect_failure 'commit not affected by existing $VCSH_COMMAND_RETURN_CODE' \ diff --git a/t/debug.t b/t/debug.t index b9c2059c..03317443 100755 --- a/t/debug.t +++ b/t/debug.t @@ -7,7 +7,7 @@ test_description='Debug mode' # XXX add more? test_expect_success 'Debug output includes git version' \ - '$VCSH -d init foo |& assert_grep "git version [0-9]" && - $VCSH -d list |& assert_grep "git version [0-9]"' + '$VCSH -d init foo |& test_grep "git version [0-9]" && + $VCSH -d list |& test_grep "git version [0-9]"' test_done diff --git a/t/delete.t b/t/delete.t index 5376a8d9..5d6525de 100755 --- a/t/delete.t +++ b/t/delete.t @@ -64,7 +64,7 @@ test_expect_success 'Delete lists staged files before confirmation' \ $VCSH foo add randomtexttofind && : | test_must_fail $VCSH delete foo >output && - assert_grep -F randomtexttofind output && - assert_grep -F randomtexttofind /dev/null } diff --git a/t/help.t b/t/help.t index 715507ea..11140673 100755 --- a/t/help.t +++ b/t/help.t @@ -9,13 +9,13 @@ test_expect_failure 'Help command succeeds' \ '$VCSH help' test_expect_success 'Help command writes to stderr and not stdout' \ - '$VCSH help 2>&1 1>/dev/null | assert_grep "" && - $VCSH help 2>/dev/null | test_must_fail assert_grep ""' + '$VCSH help 2>&1 1>/dev/null | test_grep "" && + $VCSH help 2>/dev/null | test_must_fail test_grep ""' test_expect_success 'Help command prints usage on first line' \ '$VCSH help |& head -1 | - assert_grep "^usage: "' + test_grep "^usage: "' test_expect_failure 'Help command can be abbreviated (hel, he)' \ '$VCSH help >expected 2>&1 && @@ -29,7 +29,7 @@ test_expect_failure 'Help command can be abbreviated (hel, he)' \ for cmd in clone commit delete enter foreach help init list list-tracked list-untracked \ pull push rename run status upgrade version which write-gitignore; do test_expect_success "Help text includes $cmd command" \ - '$VCSH help 2>&1 | assert_grep "^ '"$cmd"'\\b"' + '$VCSH help 2>&1 | test_grep "^ '"$cmd"'\\b"' done test_done diff --git a/t/init.t b/t/init.t index 3b23a56e..413f7c03 100755 --- a/t/init.t +++ b/t/init.t @@ -92,7 +92,7 @@ test_expect_success 'Init command adds matching gitignore.d files' \ touch .gitattributes.d/ignore-d .gitignore.d/ignore-d && test_env VCSH_GITIGNORE=exact $VCSH init ignore-d && - $VCSH status ignore-d | assert_grep -Fx "A .gitignore.d/ignore-d"' + $VCSH status ignore-d | test_grep -Fx "A .gitignore.d/ignore-d"' test_expect_success 'VCSH_GITIGNORE variable is validated' \ 'test_env VCSH_GITIGNORE=x test_must_fail $VCSH init ignore1 && diff --git a/t/rename.t b/t/rename.t index 1e8ddb38..32e2c7b8 100755 --- a/t/rename.t +++ b/t/rename.t @@ -66,10 +66,10 @@ test_expect_success 'Rename can be abbreviated (renam, rena, ren, re)' \ echo name5 >expected && $VCSH list >output && - assert_grep -Fx name5 output && - sed -n 1p output | assert_grep "^vcsh [0-9]" && - sed -n 2p output | assert_grep "^git version [0-9]"' + sed -n 1p output | test_grep "^vcsh [0-9]" && + sed -n 2p output | test_grep "^git version [0-9]"' test_expect_success 'Version can be abbreviated (versio, versi, vers, ver, ve)' \ '$VCSH version >expected && From d5368fc3508beefd2c8767173df1da64a6a3f23e Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 25 May 2017 01:45:30 -0500 Subject: [PATCH 112/151] rename to environment.sh --- t/clone.t | 2 +- t/commit.t | 2 +- t/configfiles.t | 2 +- t/debug.t | 2 +- t/delete.t | 2 +- t/{environment.bash => environment.sh} | 0 t/external-vars.t | 2 +- t/foreach.t | 2 +- t/help.t | 2 +- t/hooks.t | 2 +- t/init.t | 2 +- t/list-tracked.t | 2 +- t/list-untracked0.t | 2 +- t/list.t | 2 +- t/prove.t | 2 +- t/pull.t | 2 +- t/push.t | 2 +- t/rename.t | 2 +- t/run-enter.t | 2 +- t/status.t | 2 +- t/version.t | 2 +- t/which.t | 2 +- 22 files changed, 21 insertions(+), 21 deletions(-) rename t/{environment.bash => environment.sh} (100%) diff --git a/t/clone.t b/t/clone.t index c03a4e52..e0d20459 100755 --- a/t/clone.t +++ b/t/clone.t @@ -3,7 +3,7 @@ test_description='Clone command' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success 'Setup' \ 'test_create_repo repo && diff --git a/t/commit.t b/t/commit.t index 9ed180e9..9b7836d0 100755 --- a/t/commit.t +++ b/t/commit.t @@ -3,7 +3,7 @@ test_description='Commit command' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success 'commit works with no repos' \ '$VCSH commit >output && diff --git a/t/configfiles.t b/t/configfiles.t index 215ec665..1df043b9 100755 --- a/t/configfiles.t +++ b/t/configfiles.t @@ -3,7 +3,7 @@ test_description='Configuration files' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" # XXX writeme diff --git a/t/debug.t b/t/debug.t index 03317443..536c8c6c 100755 --- a/t/debug.t +++ b/t/debug.t @@ -3,7 +3,7 @@ test_description='Debug mode' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" # XXX add more? test_expect_success 'Debug output includes git version' \ diff --git a/t/delete.t b/t/delete.t index 5d6525de..1c9bd8b9 100755 --- a/t/delete.t +++ b/t/delete.t @@ -3,7 +3,7 @@ test_description='Delete command' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success 'Delete requires repo name' \ 'test_must_fail $VCSH delete' diff --git a/t/environment.bash b/t/environment.sh similarity index 100% rename from t/environment.bash rename to t/environment.sh diff --git a/t/external-vars.t b/t/external-vars.t index 5ef4cb99..57c2c843 100755 --- a/t/external-vars.t +++ b/t/external-vars.t @@ -3,7 +3,7 @@ test_description='External environment variables' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" # XXX writeme diff --git a/t/foreach.t b/t/foreach.t index 399dc9d3..ffd7bfef 100755 --- a/t/foreach.t +++ b/t/foreach.t @@ -3,7 +3,7 @@ test_description='Foreach command' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success 'Foreach requires an argument' \ 'test_must_fail $VCSH foreach' diff --git a/t/help.t b/t/help.t index 11140673..de01ac82 100755 --- a/t/help.t +++ b/t/help.t @@ -3,7 +3,7 @@ test_description='Help command' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_failure 'Help command succeeds' \ '$VCSH help' diff --git a/t/hooks.t b/t/hooks.t index 161c28a4..bdac0bc3 100755 --- a/t/hooks.t +++ b/t/hooks.t @@ -3,7 +3,7 @@ test_description='Hooks and overlays' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" # XXX writeme diff --git a/t/init.t b/t/init.t index 413f7c03..c07e2a24 100755 --- a/t/init.t +++ b/t/init.t @@ -3,7 +3,7 @@ test_description='Init command' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success 'Init command succeeds' \ '$VCSH init foo' diff --git a/t/list-tracked.t b/t/list-tracked.t index 84e6a270..92082325 100755 --- a/t/list-tracked.t +++ b/t/list-tracked.t @@ -3,7 +3,7 @@ test_description='List-tracked command' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success 'list-tracked works with no repos' \ '$VCSH list-tracked &>output && diff --git a/t/list-untracked0.t b/t/list-untracked0.t index 8db58da7..de6faffa 100755 --- a/t/list-untracked0.t +++ b/t/list-untracked0.t @@ -3,7 +3,7 @@ test_description='List-untracked command' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success 'list-untracked works with no repos' \ '$VCSH list-untracked &>output && diff --git a/t/list.t b/t/list.t index 6b60f494..a3df9e1f 100755 --- a/t/list.t +++ b/t/list.t @@ -3,7 +3,7 @@ test_description='List command' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success 'Setup' \ 'test_create_repo repo && diff --git a/t/prove.t b/t/prove.t index 51dc3d81..a149abcf 100755 --- a/t/prove.t +++ b/t/prove.t @@ -3,7 +3,7 @@ test_description='Old tests' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success '300-add.t' \ '$VCSH init test1 && diff --git a/t/pull.t b/t/pull.t index 1964828c..a2cf7282 100755 --- a/t/pull.t +++ b/t/pull.t @@ -3,7 +3,7 @@ test_description='Pull command' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success 'pull works with no repositories' \ '$VCSH pull >output && diff --git a/t/push.t b/t/push.t index 3dd8d062..b1acb622 100755 --- a/t/push.t +++ b/t/push.t @@ -3,7 +3,7 @@ test_description='Push command' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success 'push works with no repositories' \ '$VCSH push &>output && diff --git a/t/rename.t b/t/rename.t index 32e2c7b8..ced055da 100755 --- a/t/rename.t +++ b/t/rename.t @@ -3,7 +3,7 @@ test_description='Rename command' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success 'Setup' \ 'test_create_repo repo && diff --git a/t/run-enter.t b/t/run-enter.t index bfd2e317..ca53555c 100755 --- a/t/run-enter.t +++ b/t/run-enter.t @@ -3,7 +3,7 @@ test_description='Run/enter commands' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success 'Setup' \ 'test_create_repo repo1 && diff --git a/t/status.t b/t/status.t index af77bf45..824a1d73 100755 --- a/t/status.t +++ b/t/status.t @@ -3,7 +3,7 @@ test_description='Status command' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success 'Status argument if any must be a repo' \ 'test_must_fail $VCSH status nope' diff --git a/t/version.t b/t/version.t index 25f267f0..363d3186 100755 --- a/t/version.t +++ b/t/version.t @@ -3,7 +3,7 @@ test_description='Version command' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success 'Version command succeeds' \ '$VCSH version' diff --git a/t/which.t b/t/which.t index f790d005..17b57260 100755 --- a/t/which.t +++ b/t/which.t @@ -3,7 +3,7 @@ test_description='Which command' . ./test-lib.sh -. "$TEST_DIRECTORY/environment.bash" +. "$TEST_DIRECTORY/environment.sh" test_expect_success 'Which command does not accept an empty parameter' \ 'test_must_fail $VCSH which ""' From 078fb4dbdb7a3eae4a9bf41a05f04911394c56a9 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 25 May 2017 02:05:09 -0500 Subject: [PATCH 113/151] convert over some old list-untracked tests The tests for this command need some work. The command itself needs some work too, to be fair. --- t/list-untracked.t | 74 +++++++++++++++++++++++++++++++++++++++++++++ t/list-untracked0.t | 12 -------- 2 files changed, 74 insertions(+), 12 deletions(-) create mode 100755 t/list-untracked.t delete mode 100755 t/list-untracked0.t diff --git a/t/list-untracked.t b/t/list-untracked.t new file mode 100755 index 00000000..6f2232dc --- /dev/null +++ b/t/list-untracked.t @@ -0,0 +1,74 @@ +#!/bin/bash + +test_description='List-untracked command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.sh" + +test_expect_success 'list-untracked works with no repos' \ + '$VCSH list-untracked &>output && + test_must_be_empty output' + +# Bug +test_expect_failure 'list-untracked argument must be a repo' \ + 'test_must_fail $VCSH list-untracked nope' + +test_expect_success '(setup) Create directory to isolate files' \ + 'mkdir files && + export VCSH_BASE="$PWD/files" && + + # Needed to avoid creating additional untracked dirs/files + export VCSH_GITIGNORE=none VCSH_GITATTRIBUTES=none' + +test_expect_success 'list-untracked works with no files' \ + '$VCSH list-untracked >output && + test_must_be_empty output' + +# Bug? +test_expect_failure 'list-untracked works with no repos' \ + 'mkdir files/dir && + touch files/a files/b files/c files/dir/d files/dir/e && + { + echo a && + echo b && + echo c && + echo dir/ + } >expected && + $VCSH list-untracked >output && + test_cmp expected output' + +# Bug? +test_expect_failure 'list-untracked -r works with no repos' \ + 'mkdir files/dir && + touch files/a files/b files/c files/dir/d files/dir/e && + { + echo a && + echo b && + echo c && + echo dir/d && + echo dir/e + } >expected && + $VCSH list-untracked -r >output && + test_cmp expected output' + +test_expect_success 'list-untracked works with one repo' \ + '$VCSH init foo && + + $VCSH foo add a c dir/d && + $VCSH foo commit -m 'files' && + + { + echo b && + echo dir/e + } >expected && + $VCSH list-untracked >output && + test_cmp expected output' + +# Bug +test_expect_failure 'list-untracked not affected by $ran_once in environment' \ + 'test_env ran_once=1 $VCSH list-untracked >output && + test_cmp expected output' + +# XXX Needs tests for multiple repos, with and without -r + +test_done diff --git a/t/list-untracked0.t b/t/list-untracked0.t deleted file mode 100755 index de6faffa..00000000 --- a/t/list-untracked0.t +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -test_description='List-untracked command' - -. ./test-lib.sh -. "$TEST_DIRECTORY/environment.sh" - -test_expect_success 'list-untracked works with no repos' \ - '$VCSH list-untracked &>output && - test_must_be_empty output' - -test_done From 60cae6a3af87f568c11f6e439dfc4cf88ae232c4 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Wed, 21 Jun 2017 01:07:27 -0500 Subject: [PATCH 114/151] add empty repo tests for list-untracked --- t/list-untracked.t | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/t/list-untracked.t b/t/list-untracked.t index 6f2232dc..b747d9b1 100755 --- a/t/list-untracked.t +++ b/t/list-untracked.t @@ -5,6 +5,9 @@ test_description='List-untracked command' . ./test-lib.sh . "$TEST_DIRECTORY/environment.sh" +# Needed to avoid creating additional untracked dirs/files +export VCSH_GITIGNORE=none VCSH_GITATTRIBUTES=none + test_expect_success 'list-untracked works with no repos' \ '$VCSH list-untracked &>output && test_must_be_empty output' @@ -15,10 +18,7 @@ test_expect_failure 'list-untracked argument must be a repo' \ test_expect_success '(setup) Create directory to isolate files' \ 'mkdir files && - export VCSH_BASE="$PWD/files" && - - # Needed to avoid creating additional untracked dirs/files - export VCSH_GITIGNORE=none VCSH_GITATTRIBUTES=none' + export VCSH_BASE="$PWD/files"' test_expect_success 'list-untracked works with no files' \ '$VCSH list-untracked >output && @@ -39,9 +39,7 @@ test_expect_failure 'list-untracked works with no repos' \ # Bug? test_expect_failure 'list-untracked -r works with no repos' \ - 'mkdir files/dir && - touch files/a files/b files/c files/dir/d files/dir/e && - { + '{ echo a && echo b && echo c && @@ -51,11 +49,32 @@ test_expect_failure 'list-untracked -r works with no repos' \ $VCSH list-untracked -r >output && test_cmp expected output' -test_expect_success 'list-untracked works with one repo' \ +test_expect_success 'list-untracked works with one empty repo' \ '$VCSH init foo && - $VCSH foo add a c dir/d && - $VCSH foo commit -m 'files' && + { + echo a && + echo b && + echo c && + echo dir/ + } >expected && + $VCSH list-untracked >output && + test_cmp expected output' + +test_expect_success 'list-untracked -r works with one empty repo' \ + '{ + echo a && + echo b && + echo c && + echo dir/d && + echo dir/e + } >expected && + $VCSH list-untracked -r >output && + test_cmp expected output' + +test_expect_success 'list-untracked works with one repo' \ + '$VCSH foo add a c dir/d && + $VCSH foo commit -m "files" && { echo b && From 38d5276b4992d076725689bb24e7a4bc0d736109 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 24 Jul 2017 09:51:43 -0500 Subject: [PATCH 115/151] add test_setup function for setup tasks Tests should now be written to be nilpotent; anything with lasting side effects goes in test_setup instead of test_expect_success. It is still expected to succeed. Each test_setup script will be run regardless of which tests are being run/skipped, and their results will not be counted in the totals. --- t/test-lib-functions.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 6f77d307..f73d11aa 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -385,6 +385,22 @@ test_verify_prereq () { error "bug in the test script: '$test_prereq' does not look like a prereq" } +test_setup () { + test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq= + test "$#" = 2 || + error "bug in the test script: not 2 or 3 parameters to test-setup" + test_verify_prereq + export test_prereq + say "# setup: $1" + if ! test_run_ "$2"; then + printf 'Bail out! %s\n' "setup script failed" + shift + printf '%s\n' "$*" | sed -e 's/^/# /' + GIT_EXIT_OK=t + exit 1 + fi +} + test_expect_failure () { test_start_ test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq= From 0b2c905d5ae5ab59579fddef010e422d007926c5 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 24 Jul 2017 10:12:11 -0500 Subject: [PATCH 116/151] use test_when_finished and test_setup for clone.t Idea: Any set of tests without an intervening test_setup could be run in random order... or, for that matter, in parallel copies of the starting state. Worthwhile? Interesting? --- t/clone.t | 68 ++++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/t/clone.t b/t/clone.t index e0d20459..11dd1fe5 100755 --- a/t/clone.t +++ b/t/clone.t @@ -5,7 +5,7 @@ test_description='Clone command' . ./test-lib.sh . "$TEST_DIRECTORY/environment.sh" -test_expect_success 'Setup' \ +test_setup 'Create upstream repos' \ 'test_create_repo repo && test_commit -C repo A && git -C repo checkout -b branchb && @@ -22,94 +22,90 @@ test_expect_success 'Clone requires a remote' \ test_expect_success 'Clone uses existing repo name by default' \ '$VCSH clone ./repo && + test_when_finished "doit | $VCSH delete repo" && echo "repo" >expected && $VCSH list >output && $VCSH clone ./repo3.git && + test_when_finished "doit | $VCSH delete repo3" && echo "repo3" >>expected && $VCSH list >output && - test_cmp expected output && - - doit | $VCSH delete repo && - doit | $VCSH delete repo3' + test_cmp expected output' test_expect_success 'Clone honors specified repo name' \ '$VCSH clone ./repo foo && + test_when_finished "doit | $VCSH delete foo" && echo foo >expected && $VCSH list >output && test_cmp expected output' test_expect_success 'Clone defaults to HEAD of given remote' \ - 'git -C repo rev-parse HEAD >expected && + '$VCSH clone ./repo foo && + test_when_finished "doit | $VCSH delete foo" && + git -C repo rev-parse HEAD >expected && $VCSH foo rev-parse HEAD >output && - test_cmp expected output && - - doit | $VCSH delete foo' + test_cmp expected output' -test_expect_success 'Clone can be abbreviated (clon, clo, cl)' \ +test_expect_success 'Clone can be abbreviated "clon"' \ '$VCSH clon ./repo a && + test_when_finished "doit | $VCSH delete a" && echo a >expected && $VCSH list >output && - test_cmp expected output && - doit | $VCSH delete a && + test_cmp expected output' - $VCSH clo ./repo b && +test_expect_success 'Clone can be abbreviated "clo"' \ + '$VCSH clo ./repo b && + test_when_finished "doit | $VCSH delete b" && echo b >expected && $VCSH list >output && - test_cmp expected output && - doit | $VCSH delete b && + test_cmp expected output' - $VCSH cl ./repo c && +test_expect_success 'Clone can be abbreviated "cl"' \ + '$VCSH cl ./repo c && + test_when_finished "doit | $VCSH delete c" && echo c >expected && $VCSH list >output && - test_cmp expected output && - doit | $VCSH delete c' + test_cmp expected output' test_expect_success 'Clone honors -b option before remote' \ '$VCSH clone -b branchb ./repo && + test_when_finished "doit | $VCSH delete repo" && git -C repo rev-parse branchb >expected && $VCSH repo rev-parse HEAD >output && - test_cmp expected output && - - doit | $VCSH delete repo' + test_cmp expected output' test_expect_success 'Clone honors -b option before remote and repo name' \ '$VCSH clone -b branchb ./repo foo && + test_when_finished "doit | $VCSH delete foo" && git -C repo rev-parse branchb >expected && $VCSH foo rev-parse HEAD >output && - test_cmp expected output && - - doit | $VCSH delete foo' + test_cmp expected output' test_expect_success 'Clone honors -b option after remote' \ '$VCSH clone ./repo -b branchb && + test_when_finished "doit | $VCSH delete repo" && git -C repo rev-parse branchb >expected && $VCSH repo rev-parse HEAD >output && - test_cmp expected output && - - doit | $VCSH delete repo' + test_cmp expected output' test_expect_success 'Clone honors -b option between remote and repo name' \ '$VCSH clone ./repo -b branchb foo && + test_when_finished "doit | $VCSH delete foo" && git -C repo rev-parse branchb >expected && $VCSH foo rev-parse HEAD >output && - test_cmp expected output && - - doit | $VCSH delete foo' + test_cmp expected output' test_expect_success 'Clone honors -b option after repo name' \ '$VCSH clone ./repo foo -b branchb && + test_when_finished "doit | $VCSH delete foo" && git -C repo rev-parse branchb >expected && $VCSH foo rev-parse HEAD >output && - test_cmp expected output && - - doit | $VCSH delete foo' + test_cmp expected output' test_expect_success 'Clone -b option clones only one branch' \ '$VCSH clone -b branchb ./repo foo && + test_when_finished "doit | $VCSH delete foo" && $VCSH foo show-ref --heads >output && - test_line_count = 1 output && - - doit | $VCSH delete foo' + test_line_count = 1 output' test_done From e23344050164ea4c5af244acfc41ebb97d384010 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 24 Jul 2017 10:39:05 -0500 Subject: [PATCH 117/151] use test_setup some more --- t/foreach.t | 2 +- t/init.t | 41 +++++++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/t/foreach.t b/t/foreach.t index ffd7bfef..9d5b56f5 100755 --- a/t/foreach.t +++ b/t/foreach.t @@ -12,7 +12,7 @@ test_expect_success 'Foreach does nothing if no repositories exist' \ '$VCSH foreach version >output && test_must_be_empty output' -test_expect_success '(setup) Create two repositories' \ +test_setup 'Create two repositories' \ 'test_create_repo repo1 && test_commit -C repo1 A && test_create_repo repo2 && diff --git a/t/init.t b/t/init.t index c07e2a24..321ffa5d 100755 --- a/t/init.t +++ b/t/init.t @@ -6,18 +6,23 @@ test_description='Init command' . "$TEST_DIRECTORY/environment.sh" test_expect_success 'Init command succeeds' \ - '$VCSH init foo' + '$VCSH init foo && + test_when_finished "doit | $VCSH delete foo"' test_expect_success 'Init command creates new Git repository' \ 'find_gitrepos "$PWD" >output && - test_line_count = 1 output && + test_line_count = 0 output && - for i in $(test_seq 2 5); do + for i in $(test_seq 1 4); do $VCSH init "count$i" && + test_when_finished "doit | $VCSH delete count$i" find_gitrepos "$PWD" >output && test_line_count = "$i" output done' +test_setup 'Create repository' \ + '$VCSH init foo' + # verifies commit e220a61 test_expect_success 'Files created by init are not readable by other users' \ 'find "$HOME" -type f -perm /g+rwx,o+rwx ! -path "$HOME/output" >output && @@ -28,7 +33,9 @@ test_expect_success 'Init command fails if repository already exists' \ test_expect_success 'Init command can be abbreviated (ini, in)' \ '$VCSH ini bar && + test_when_finished "doit | $VCSH delete bar" && $VCSH in baz && + test_when_finished "doit | $VCSH delete baz" && test_must_fail $VCSH ini foo && test_must_fail $VCSH in foo' @@ -37,34 +44,37 @@ test_expect_failure 'Init command takes exactly one parameter' \ test_must_fail $VCSH init one two && test_must_fail $VCSH init a b c' +test_setup 'Create second repository' \ + '$VCSH init bar' + test_expect_success 'Init creates repositories with same toplevel' \ '$VCSH run foo git rev-parse --show-toplevel >output1 && $VCSH run bar git rev-parse --show-toplevel >output2 && test_cmp output1 output2' +test_setup 'Create test directories' \ + 'mkdir -p repod1 repod2 xdg1 xdg2 home1 home2 ro && + chmod a-w ro && + mkdir -p foo4 bar4 foo4a bar4a over4a over4b && + mkdir -p foo5 bar5 over5a over5b' + test_expect_success 'Init command respects alternate $VCSH_REPO_D' \ - 'mkdir -p repod1 repod2 && - test_env VCSH_REPO_D="$PWD/repod1" $VCSH init alt-repo && + 'test_env VCSH_REPO_D="$PWD/repod1" $VCSH init alt-repo && test_env VCSH_REPO_D="$PWD/repod2" $VCSH init alt-repo' test_expect_success 'Init command respects alternate $XDG_CONFIG_HOME' \ - 'mkdir -p xdg1 xdg2 && - test_env XDG_CONFIG_HOME="$PWD/xdg1" $VCSH init alt-xdg && + 'test_env XDG_CONFIG_HOME="$PWD/xdg1" $VCSH init alt-xdg && test_env XDG_CONFIG_HOME="$PWD/xdg2" $VCSH init alt-xdg' test_expect_success 'Init command respects alternate $HOME' \ - 'mkdir -p home1 home2 && - test_env HOME="$PWD/home1" $VCSH init alt-home && + 'test_env HOME="$PWD/home1" $VCSH init alt-home && test_env HOME="$PWD/home2" $VCSH init alt-home' test_expect_success 'Init command fails if directories cannot be created' \ - 'mkdir ro && - chmod a-w ro && - test_env HOME="$PWD/ro" test_must_fail $VCSH init readonly' + 'test_env HOME="$PWD/ro" test_must_fail $VCSH init readonly' test_expect_success '$VCSH_REPO_D overrides $XDG_CONFIG_HOME and $HOME for init' \ - 'mkdir -p foo4 bar4 foo4a bar4a over4a over4b && - test_env HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4a" $VCSH init samename1 && + 'test_env HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4a" $VCSH init samename1 && test_env HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename1 && test_env HOME="$PWD/foo4" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename1 && test_env HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4a" test_must_fail $VCSH init samename1 && @@ -74,8 +84,7 @@ test_expect_success '$VCSH_REPO_D overrides $XDG_CONFIG_HOME and $HOME for init' test_env HOME="$PWD/foo4a" XDG_CONFIG_HOME="$PWD/bar4a" VCSH_REPO_D="$PWD/over4b" test_must_fail $VCSH init samename1' test_expect_success '$XDG_CONFIG_HOME overrides $HOME for init' \ - 'mkdir -p foo5 bar5 over5a over5b && - test_env HOME="$PWD/foo5" XDG_CONFIG_HOME="$PWD/over5a" $VCSH init samename2 && + 'test_env HOME="$PWD/foo5" XDG_CONFIG_HOME="$PWD/over5a" $VCSH init samename2 && test_env HOME="$PWD/bar5" XDG_CONFIG_HOME="$PWD/over5a" test_must_fail $VCSH init samename2 && test_env HOME="$PWD/foo5" XDG_CONFIG_HOME="$PWD/over5b" $VCSH init samename2 && test_env HOME="$PWD/bar5" XDG_CONFIG_HOME="$PWD/over5b" test_must_fail $VCSH init samename2' From 61594901fd998a180840ffa6b393cdb3b666b741 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 24 Jul 2017 13:08:01 -0500 Subject: [PATCH 118/151] some more use of test_setup --- t/list-tracked.t | 27 ++++++++++++++---------- t/list.t | 54 +++++++++++++++++++++--------------------------- t/rename.t | 49 +++++++++++++++++++++++++++---------------- 3 files changed, 70 insertions(+), 60 deletions(-) diff --git a/t/list-tracked.t b/t/list-tracked.t index 92082325..64e1b890 100755 --- a/t/list-tracked.t +++ b/t/list-tracked.t @@ -9,42 +9,47 @@ test_expect_success 'list-tracked works with no repos' \ '$VCSH list-tracked &>output && test_must_be_empty output' -test_expect_success 'list-tracked command works with no repos and untracked files' \ - 'touch a b c d e && +test_setup 'Create some files' \ + 'touch a b c d e' - $VCSH list-tracked >output && +test_expect_success 'list-tracked command works with no repos and untracked files' \ + '$VCSH list-tracked >output && test_must_be_empty output' test_expect_failure 'list-tracked fails if argument is not a repo' \ 'test_must_fail $VCSH list-tracked nope' +test_setup 'Create repo' \ + '$VCSH init foo' + test_expect_success 'list-tracked works on empty repo' \ - '$VCSH init foo && - $VCSH list-tracked >output && + '$VCSH list-tracked >output && test_must_be_empty output' test_expect_success 'list-tracked works on specified empty repo' \ '$VCSH list-tracked foo >output && test_must_be_empty output' -test_expect_success 'list-tracked lists files from one repo' \ +test_setup 'Commit some files' \ '$VCSH foo add a d && - $VCSH foo commit -m "a d" && + $VCSH foo commit -m "a d"' - { +test_expect_success 'list-tracked lists files from one repo' \ + '{ echo "$HOME/a" && echo "$HOME/d" } >expected && $VCSH list-tracked >output && test_cmp expected output' -test_expect_success 'list-tracked lists files from two repos' \ +test_setup 'Set up second repo' \ '$VCSH init bar && $VCSH bar add b e && - $VCSH bar commit -m "b e" && + $VCSH bar commit -m "b e"' - { +test_expect_success 'list-tracked lists files from two repos' \ + '{ echo "$HOME/a" && echo "$HOME/b" && echo "$HOME/d" && diff --git a/t/list.t b/t/list.t index a3df9e1f..e3d56a39 100755 --- a/t/list.t +++ b/t/list.t @@ -5,7 +5,7 @@ test_description='List command' . ./test-lib.sh . "$TEST_DIRECTORY/environment.sh" -test_expect_success 'Setup' \ +test_setup 'Create repo and commits' \ 'test_create_repo repo && test_commit -C repo A && test_commit -C repo B' @@ -15,22 +15,22 @@ test_expect_success 'List command correct for no repositories' \ test_must_be_empty output' test_expect_success 'List command displays inited repository' \ - '$VCSH init test1 && + 'vcsh_temp_repo test1 && echo test1 >expected && $VCSH list >output && - test_cmp expected output && - doit | $VCSH delete test1' + test_cmp expected output' test_expect_success 'List command displays cloned repository' \ - '$VCSH clone ./repo foo && + 'vcsh_temp_clone ./repo foo && echo foo >expected && $VCSH list >output && - test_cmp expected output && - doit | $VCSH delete foo' + test_cmp expected output' test_expect_success 'List command respects $XDG_CONFIG_HOME' \ 'test_env XDG_CONFIG_HOME="$PWD/xdg1" $VCSH init test1 && + test_when_finished "doit | test_env XDG_CONFIG_HOME=\"$PWD/xdg1\" $VCSH delete test1" && test_env XDG_CONFIG_HOME="$PWD/xdg2" $VCSH init test2 && + test_when_finished "doit | test_env XDG_CONFIG_HOME=\"$PWD/xdg2\" $VCSH delete test2" && echo test1 >expected && test_env XDG_CONFIG_HOME="$PWD/xdg1" $VCSH list >output && @@ -38,14 +38,13 @@ test_expect_success 'List command respects $XDG_CONFIG_HOME' \ echo test2 >expected && test_env XDG_CONFIG_HOME="$PWD/xdg2" $VCSH list >output && - test_cmp expected output && - - doit | test_env XDG_CONFIG_HOME="$PWD/xdg1" $VCSH delete test1 && - doit | test_env XDG_CONFIG_HOME="$PWD/xdg2" $VCSH delete test2' + test_cmp expected output' test_expect_success 'List command respects $HOME' \ 'test_env HOME="$PWD/home1" $VCSH init test1 && + test_when_finished "doit | test_env HOME=\"$PWD/home1\" $VCSH delete test1" && test_env HOME="$PWD/home2" $VCSH init test2 && + test_when_finished "doit | test_env HOME=\"$PWD/home2\" $VCSH delete test2" && echo test1 >expected && test_env HOME="$PWD/home1" $VCSH list >output && @@ -53,47 +52,43 @@ test_expect_success 'List command respects $HOME' \ echo test2 >expected && test_env HOME="$PWD/home2" $VCSH list >output && - test_cmp expected output && - - doit | test_env HOME="$PWD/home1" $VCSH delete test1 && - doit | test_env HOME="$PWD/home2" $VCSH delete test2' + test_cmp expected output' test_expect_success 'List command prioritizes $XDG_CONFIG_HOME over $HOME' \ 'test_env HOME="$PWD/xh1" $VCSH init correct && + test_when_finished "doit | test_env HOME=\"$PWD/xh1\" $VCSH delete correct" && test_env HOME="$PWD/xh2" $VCSH init wrong && + test_when_finished "doit | test_env HOME=\"$PWD/xh2\" $VCSH delete wrong" && echo correct >expected && test_env HOME="$PWD/xh2" XDG_CONFIG_HOME="$PWD/xh1/.config" $VCSH list >output && - test_cmp expected output && - - doit | test_env HOME="$PWD/xh1" $VCSH delete correct && - doit | test_env HOME="$PWD/xh2" $VCSH delete wrong' + test_cmp expected output' test_expect_success 'List command prioritizes $VCSH_REPO_D over $HOME' \ 'test_env HOME="$PWD/rdh1" $VCSH init correct && + test_when_finished "doit | test_env HOME=\"$PWD/rdh1\" $VCSH delete correct" && test_env HOME="$PWD/rdh2" $VCSH init wrong && + test_when_finished "doit | test_env HOME=\"$PWD/rdh2\" $VCSH delete wrong" && echo correct >expected && test_env HOME="$PWD/rdh2" VCSH_REPO_D="$PWD/rdh1/.config/vcsh/repo.d" $VCSH list >output && - test_cmp expected output && - - doit | test_env HOME="$PWD/rdh1" $VCSH delete correct && - doit | test_env HOME="$PWD/rdh2" $VCSH delete wrong' + test_cmp expected output' test_expect_success 'List command prioritizes $VCSH_REPO_D over $XDG_CONFIG_HOME' \ 'test_env XDG_CONFIG_HOME="$PWD/xhrd1" $VCSH init correct && + test_when_finished "doit | test_env XDG_CONFIG_HOME=\"$PWD/xhrd1\" $VCSH delete correct" && test_env XDG_CONFIG_HOME="$PWD/xhrd2" $VCSH init wrong && + test_when_finished "doit | test_env XDG_CONFIG_HOME=\"$PWD/xhrd2\" $VCSH delete wrong" && echo correct >expected && test_env XDG_CONFIG_HOME="$PWD/xhrd2" VCSH_REPO_D="$PWD/xhrd1/vcsh/repo.d" $VCSH list >output && - test_cmp expected output && - - doit | test_env XDG_CONFIG_HOME="$PWD/xhrd1" $VCSH delete correct && - doit | test_env XDG_CONFIG_HOME="$PWD/xhrd2" $VCSH delete wrong' + test_cmp expected output' test_expect_success 'List command respects $VCSH_REPO_D' \ 'test_env VCSH_REPO_D="$PWD/rd1" $VCSH init test1 && + test_when_finished "doit | test_env VCSH_REPO_D=\"$PWD/rd1\" $VCSH delete test1" && test_env VCSH_REPO_D="$PWD/rd2" $VCSH init test2 && + test_when_finished "doit | test_env VCSH_REPO_D=\"$PWD/rd2\" $VCSH delete test2" && echo test1 >expected && test_env VCSH_REPO_D="$PWD/rd1" $VCSH list >output && @@ -101,9 +96,6 @@ test_expect_success 'List command respects $VCSH_REPO_D' \ echo test2 >expected && test_env VCSH_REPO_D="$PWD/rd2" $VCSH list >output && - test_cmp expected output && - - doit | test_env VCSH_REPO_D="$PWD/rd1" $VCSH delete test1 && - doit | test_env VCSH_REPO_D="$PWD/rd2" $VCSH delete test2' + test_cmp expected output' test_done diff --git a/t/rename.t b/t/rename.t index ced055da..7f7cad07 100755 --- a/t/rename.t +++ b/t/rename.t @@ -5,7 +5,7 @@ test_description='Rename command' . ./test-lib.sh . "$TEST_DIRECTORY/environment.sh" -test_expect_success 'Setup' \ +test_setup 'Create repo and make commits' \ 'test_create_repo repo && test_commit -C repo A && test_commit -C repo B' @@ -13,19 +13,27 @@ test_expect_success 'Setup' \ test_expect_success 'Repository to be renamed must exist' \ 'test_must_fail $VCSH rename foo bar' -test_expect_success 'Rename works on empty repository' \ +test_setup 'Create empty and nonempty repos' \ '$VCSH init foo && - $VCSH rename foo bar && + $VCSH init foo2 && + $VCSH clone ./repo bar' + +test_expect_success 'Rename works on empty repository' \ + '$VCSH rename foo baz && + test_when_finished "$VCSH rename baz foo" && + + echo bar >expected && + echo baz >>expected && + echo foo2>>expected && - echo bar >expected && $VCSH list >output && test_cmp expected output' test_expect_success 'Rename works on repository with files/commits' \ - 'git -C repo rev-parse HEAD >expected && + '$VCSH rename bar baz && + test_when_finished "$VCSH rename baz bar" && - $VCSH clone ./repo foo && - $VCSH rename foo baz && + git -C repo rev-parse HEAD >expected && $VCSH baz rev-parse HEAD >output && test_cmp expected output' @@ -34,26 +42,30 @@ test_expect_success 'Rename requires two arguments' \ test_must_fail $VCSH rename bar' test_expect_success 'Target of rename must not already exist' \ - 'test_must_fail $VCSH rename bar baz' + 'test_must_fail $VCSH rename foo bar' test_expect_success 'Rename adopts existing .gitignore.d files under new name (bug?)' \ 'mkdir -p .gitignore.d && - echo test > .gitignore.d/foo && + test_when_finished "rm -r .gitignore.d/" && + echo test > .gitignore.d/baz && + + $VCSH rename foo baz && + test_when_finished "$VCSH rename baz foo" && - $VCSH rename bar foo && - echo ".gitignore.d/foo" >expected && - $VCSH foo ls-files >output && + echo ".gitignore.d/baz" >expected && + $VCSH baz ls-files >output && test_cmp expected output' test_expect_success 'Rename adopts existing .gitattributes.d files under new name (bug?)' \ - '$VCSH init bar && + 'mkdir -p .gitattributes.d && + test_when_finished "rm -r .gitattributes.d/" && + echo "* whitespace" > .gitattributes.d/baz && - mkdir -p .gitattributes.d && - echo "* whitespace" > .gitattributes.d/fribble && + $VCSH rename foo2 baz && + test_when_finished "$VCSH rename baz foo2" && - $VCSH rename bar fribble && - echo ".gitattributes.d/fribble" >expected && - $VCSH fribble ls-files >output && + echo ".gitattributes.d/baz" >expected && + $VCSH baz ls-files >output && test_cmp expected output' test_expect_success 'Rename can be abbreviated (renam, rena, ren, re)' \ @@ -63,6 +75,7 @@ test_expect_success 'Rename can be abbreviated (renam, rena, ren, re)' \ $VCSH rena name2 name3 && $VCSH ren name3 name4 && $VCSH re name4 name5 && + test_when_finished "doit | $VCSH delete name5" && echo name5 >expected && $VCSH list >output && From 72e08ac2ed4f2d4e0177c2fe142231b9133d3c82 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 18 Dec 2017 21:47:42 -0500 Subject: [PATCH 119/151] add and start using vcsh_temp_{clone,repo} --- t/delete.t | 7 ++----- t/environment.sh | 10 ++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/t/delete.t b/t/delete.t index 1c9bd8b9..4540a179 100755 --- a/t/delete.t +++ b/t/delete.t @@ -58,8 +58,7 @@ test_expect_success 'Deleted repository cannot be subsequently used' \ test_must_fail $VCSH run foo echo fail' test_expect_success 'Delete lists staged files before confirmation' \ - '$VCSH init foo && - test_when_finished "doit | $VCSH delete foo" && + 'vcsh_temp_repo foo && touch randomtexttofind && $VCSH foo add randomtexttofind && @@ -68,9 +67,7 @@ test_expect_success 'Delete lists staged files before confirmation' \ # Do we actually want this? test_expect_failure 'Delete lists files staged for removal before confirmation' \ - '$VCSH init foo && - test_when_finished "doit | $VCSH delete foo" && - + 'vcsh_temp_repo foo && touch randomtexttofind && $VCSH foo add randomtexttofind && $VCSH foo commit -m 'a' && diff --git a/t/environment.sh b/t/environment.sh index 8a527357..29617811 100644 --- a/t/environment.sh +++ b/t/environment.sh @@ -29,3 +29,13 @@ test_grep() { doit() { echo "Yes, do as I say" } + +vcsh_temp_repo() { + $VCSH init "$1" && + test_when_finished "doit | \$VCSH delete \"$1\"" +} + +vcsh_temp_clone() { + $VCSH clone "$1" "$2" && + test_when_finished "doit | \$VCSH delete \"$2\"" +} From fda3f55cb01eae434ce0afeb0211c7143c5d0efc Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 18 Dec 2017 21:48:07 -0500 Subject: [PATCH 120/151] make sure test_grep output goes to &3 --- t/environment.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/environment.sh b/t/environment.sh index 29617811..ed2b2089 100644 --- a/t/environment.sh +++ b/t/environment.sh @@ -22,7 +22,7 @@ num_gitrepos() { # Similar to grep -q, but prints the entire input to stderr for debugging test_grep() { - tee /dev/stderr | grep "$@" > /dev/null + tee /dev/stderr 2>&3 | grep "$@" > /dev/null } # For delete testing From bf7a0495214d1258e2a94ec1f1b673b4c37fbdae Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 18 Dec 2017 21:48:44 -0500 Subject: [PATCH 121/151] update list-untracked tests --- t/list-untracked.t | 81 ++++++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/t/list-untracked.t b/t/list-untracked.t index b747d9b1..fe6926b3 100755 --- a/t/list-untracked.t +++ b/t/list-untracked.t @@ -5,8 +5,8 @@ test_description='List-untracked command' . ./test-lib.sh . "$TEST_DIRECTORY/environment.sh" -# Needed to avoid creating additional untracked dirs/files -export VCSH_GITIGNORE=none VCSH_GITATTRIBUTES=none +test_setup 'Avoid creating additional untracked dirs/files' \ + 'export VCSH_GITIGNORE=none VCSH_GITATTRIBUTES=none' test_expect_success 'list-untracked works with no repos' \ '$VCSH list-untracked &>output && @@ -16,7 +16,7 @@ test_expect_success 'list-untracked works with no repos' \ test_expect_failure 'list-untracked argument must be a repo' \ 'test_must_fail $VCSH list-untracked nope' -test_expect_success '(setup) Create directory to isolate files' \ +test_setup 'Create directory to isolate files' \ 'mkdir files && export VCSH_BASE="$PWD/files"' @@ -24,15 +24,18 @@ test_expect_success 'list-untracked works with no files' \ '$VCSH list-untracked >output && test_must_be_empty output' +test_setup 'Create some files/directories' \ + 'mkdir files/{tracked,part,untracked} && + touch files/{a,b,tracked/{c,d},part/{e,f},untracked/{g,h}}' + # Bug? test_expect_failure 'list-untracked works with no repos' \ - 'mkdir files/dir && - touch files/a files/b files/c files/dir/d files/dir/e && - { + '{ echo a && echo b && - echo c && - echo dir/ + echo part/ && + echo tracked/ && + echo untracked/ } >expected && $VCSH list-untracked >output && test_cmp expected output' @@ -42,21 +45,26 @@ test_expect_failure 'list-untracked -r works with no repos' \ '{ echo a && echo b && - echo c && - echo dir/d && - echo dir/e + echo part/e && + echo part/f && + echo tracked/c && + echo tracked/d && + echo untracked/g && + echo untracked/h } >expected && $VCSH list-untracked -r >output && test_cmp expected output' -test_expect_success 'list-untracked works with one empty repo' \ - '$VCSH init foo && +test_setup 'Initialize empty repository' \ + '$VCSH init foo' - { +test_expect_success 'list-untracked works with one empty repo' \ + '{ echo a && echo b && - echo c && - echo dir/ + echo part/ && + echo tracked/ && + echo untracked/ } >expected && $VCSH list-untracked >output && test_cmp expected output' @@ -65,23 +73,42 @@ test_expect_success 'list-untracked -r works with one empty repo' \ '{ echo a && echo b && - echo c && - echo dir/d && - echo dir/e + echo part/e && + echo part/f && + echo tracked/c && + echo tracked/d && + echo untracked/g && + echo untracked/h } >expected && $VCSH list-untracked -r >output && test_cmp expected output' -test_expect_success 'list-untracked works with one repo' \ - '$VCSH foo add a c dir/d && - $VCSH foo commit -m "files" && +test_setup 'Add some files to repository' \ + '$VCSH foo add a tracked/d && + $VCSH foo commit -m "files"' - { - echo b && - echo dir/e - } >expected && +test_expect_success 'list-untracked does not include tracked files for one repo' \ + '{ + echo a && + echo tracked/d + } >bad && $VCSH list-untracked >output && - test_cmp expected output' + test_must_fail test_grep -Fx -f bad output && + test_grep -Fx untracked/ output && + test_grep -Fx untracked/g Date: Mon, 18 Dec 2017 21:52:56 -0500 Subject: [PATCH 122/151] use test_setup in pull.t --- t/pull.t | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/t/pull.t b/t/pull.t index a2cf7282..bca78729 100755 --- a/t/pull.t +++ b/t/pull.t @@ -9,56 +9,59 @@ test_expect_success 'pull works with no repositories' \ '$VCSH pull >output && test_must_be_empty output' -test_expect_success 'pull succeeds if up-to-date' \ +test_setup 'Create upstream and downstream repos' \ 'test_create_repo repo && test_commit -C repo A && - $VCSH clone ./repo foo && + $VCSH clone ./repo foo' - echo -e "foo: Already up-to-date.\\n" >expected && +test_expect_success 'pull succeeds if up-to-date' \ + 'echo -e "foo: Already up to date.\n" >expected && $VCSH pull >output && test_cmp expected output' +test_setup 'Add upstream commit' \ + 'test_commit -C repo B' + test_expect_success 'pull works with one repository' \ - 'test_commit -C repo B && - git -C repo rev-parse HEAD >expected && + 'git -C repo rev-parse HEAD >expected && $VCSH pull && $VCSH foo rev-parse HEAD >output && test_cmp expected output' -test_expect_success 'pull works with multiple repositories' \ +test_setup 'Create second upstream/downstream repo' \ 'test_create_repo repo2 && test_commit -C repo2 C && $VCSH clone ./repo2 bar && test_commit -C repo X && - git -C repo rev-parse HEAD >expected && + test_commit -C repo2 Y' - $VCSH pull && +test_expect_success 'pull works with multiple repositories' \ + '$VCSH pull && + + git -C repo rev-parse HEAD >expected && $VCSH foo rev-parse HEAD >output && test_cmp expected output && - test_commit -C repo2 Y && git -C repo2 rev-parse HEAD >expected && - - $VCSH pull && $VCSH bar rev-parse HEAD >output && test_cmp expected output' +test_setup 'Add more commits' \ + 'test_commit -C repo D && + test_commit -C repo2 E' + test_expect_failure 'pull fails if first pull fails' \ 'mv repo2 repo2.missing && test_when_finished "mv repo2.missing repo2" && - test_commit -C repo D && - test_must_fail $VCSH pull' test_expect_success 'pull fails if last pull fails' \ 'mv repo repo.missing && test_when_finished "mv repo.missing repo" && - test_commit -C repo2 E && - test_must_fail $VCSH pull' test_done From 84a7042197e2b2b7cbedfc84124d9c402c5e79eb Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 21 Dec 2017 23:40:31 -0500 Subject: [PATCH 123/151] remove changeable string from expected result --- t/pull.t | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/t/pull.t b/t/pull.t index bca78729..f8085030 100755 --- a/t/pull.t +++ b/t/pull.t @@ -15,9 +15,7 @@ test_setup 'Create upstream and downstream repos' \ $VCSH clone ./repo foo' test_expect_success 'pull succeeds if up-to-date' \ - 'echo -e "foo: Already up to date.\n" >expected && - $VCSH pull >output && - test_cmp expected output' + '$VCSH pull' test_setup 'Add upstream commit' \ 'test_commit -C repo B' From b434e59b52e634d53ad4b0bbef7be28a990ea793 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 21 Dec 2017 23:49:12 -0500 Subject: [PATCH 124/151] fix up status.t color test, use test_setup --- t/status.t | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/t/status.t b/t/status.t index 824a1d73..d0e3850a 100755 --- a/t/status.t +++ b/t/status.t @@ -12,10 +12,11 @@ test_expect_success 'Status command correct for no repos' \ '$VCSH status >output && test_must_be_empty output' -test_expect_success 'Status command correct for empty repo' \ - '$VCSH init foo && +test_setup 'Create empty repo' \ + '$VCSH init foo' - echo "foo:" >expected && +test_expect_success 'Status command correct for empty repo' \ + 'echo "foo:" >expected && echo "" >>expected && $VCSH status >output && test_cmp expected output' @@ -24,31 +25,33 @@ test_expect_success 'Terse status correct for empty repo' \ '$VCSH status --terse >output && test_must_be_empty output' -test_expect_success 'Check for socat (needed for pseudo-tty)' \ +test_setup 'Check for socat (needed for pseudo-tty)' \ 'if which socat; then test_set_prereq SOCAT fi' -test_expect_success SOCAT 'Status colored when output to tty' \ +test_setup 'Set color config' \ + '$VCSH run foo git config --local color.status.added green' + +test_setup 'Create and add a file' \ 'touch a && - $VCSH run foo git add a && - $VCSH run foo git config --local color.status.added green && + $VCSH run foo git add a' - # Ensure terminal is something Git will attempt to color +test_expect_success SOCAT 'Status colored when output to tty' \ + '# Ensure terminal is something Git will attempt to color TERM=vt100 && export TERM && - printf "\\e[32mA\\e[m a\n" >expected && + printf "\\e[m\n" >expected && socat -u exec:"$VCSH status foo",pty,rawer stdio >output && - test_cmp expected output' + test_grep -Ff expected output' -test_expect_success 'Delete/recreate repository' \ +test_setup 'Delete repository, init foo and bar' \ 'doit | $VCSH delete foo && - $VCSH init foo' + $VCSH init foo && + $VCSH init bar' test_expect_success 'Status command correct for multiple empty repos' \ - '$VCSH init bar && - - echo "bar:" >expected && + 'echo "bar:" >expected && echo "" >>expected && echo "foo:" >>expected && echo "" >>expected && @@ -59,7 +62,7 @@ test_expect_success 'Terse status correct for multiple empty repos' \ '$VCSH status --terse >output && test_must_be_empty output' -test_expect_success 'Status shows added/modified/moved/deleted files' \ +test_setup 'Set up files with many statuses' \ 'for f in 00 0M 0D M0 MM MD A0 AM AD D0 R0x RMx RDx oo; do echo "$f" > "$f" done && @@ -89,9 +92,10 @@ test_expect_success 'Status shows added/modified/moved/deleted files' \ done && # Deleted locally - rm ?D && + rm ?D' - echo "bar:" >expected && +test_expect_success 'Status shows added/modified/moved/deleted files' \ + 'echo "bar:" >expected && echo "" >>expected && echo "foo:" >>expected && echo " D 0D" >>expected && From 2d65e5975c7f2bc46c981289af31e04481263f0d Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 21 Dec 2017 23:51:07 -0500 Subject: [PATCH 125/151] remove color test for now hard to reproduce consistently, a fluff feature anyway --- t/status.t | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/t/status.t b/t/status.t index d0e3850a..bdf3cfeb 100755 --- a/t/status.t +++ b/t/status.t @@ -30,21 +30,10 @@ test_setup 'Check for socat (needed for pseudo-tty)' \ test_set_prereq SOCAT fi' -test_setup 'Set color config' \ - '$VCSH run foo git config --local color.status.added green' - test_setup 'Create and add a file' \ 'touch a && $VCSH run foo git add a' -test_expect_success SOCAT 'Status colored when output to tty' \ - '# Ensure terminal is something Git will attempt to color - TERM=vt100 && - export TERM && - printf "\\e[m\n" >expected && - socat -u exec:"$VCSH status foo",pty,rawer stdio >output && - test_grep -Ff expected output' - test_setup 'Delete repository, init foo and bar' \ 'doit | $VCSH delete foo && $VCSH init foo && From 45eadba33627cae0a969e6ecdcd3fb1a0f8861a1 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 22 Dec 2017 00:55:09 -0500 Subject: [PATCH 126/151] update test-lib from git --- t/test-lib-functions.sh | 1 + t/test-lib.sh | 45 +++++++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index f73d11aa..a8469784 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -42,6 +42,7 @@ test_decode_color () { function name(n) { if (n == 0) return "RESET"; if (n == 1) return "BOLD"; + if (n == 7) return "REVERSE"; if (n == 30) return "BLACK"; if (n == 31) return "RED"; if (n == 32) return "GREEN"; diff --git a/t/test-lib.sh b/t/test-lib.sh index 7e54d1ea..113ccdad 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -36,6 +36,11 @@ then fi GIT_BUILD_DIR="$TEST_DIRECTORY"/.. +# If LSAN is in effect we _do_ want leak checking, but we still +# want to abort so that we notice the problems. +: ${LSAN_OPTIONS=abort_on_error=1} +export LSAN_OPTIONS + ################################################################ # It appears that people try to run tests without building... if ! test -x "$GIT_BUILD_DIR/vcsh" @@ -89,7 +94,6 @@ unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH" -e ' my $ok = join("|", qw( TRACE DEBUG - USE_LOOKUP TEST .*_TEST PROVE @@ -162,9 +166,10 @@ esac # Convenience # -# A regexp to match 5 and 40 hexdigits +# A regexp to match 5, 35 and 40 hexdigits _x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' -_x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05" +_x35="$_x05$_x05$_x05$_x05$_x05$_x05$_x05" +_x40="$_x35$_x05" # Zero SHA-1 _z40=0000000000000000000000000000000000000000 @@ -180,7 +185,7 @@ LF=' # when case-folding filenames u200c=$(printf '\342\200\214') -export _x05 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB +export _x05 _x35 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB # Each test should start with something like this, after copyright notices: # @@ -834,9 +839,6 @@ case $uname_s in find () { /usr/bin/find "$@" } - sum () { - md5sum "$@" - } # git sees Windows-style pwd pwd () { builtin pwd -W @@ -866,8 +868,11 @@ esac ( COLUMNS=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1 test -z "$NO_PERL" && test_set_prereq PERL +test -z "$NO_PTHREADS" && test_set_prereq PTHREADS test -z "$NO_PYTHON" && test_set_prereq PYTHON -test -n "$USE_LIBPCRE" && test_set_prereq LIBPCRE +test -n "$USE_LIBPCRE1$USE_LIBPCRE2" && test_set_prereq PCRE +test -n "$USE_LIBPCRE1" && test_set_prereq LIBPCRE1 +test -n "$USE_LIBPCRE2" && test_set_prereq LIBPCRE2 test -z "$NO_GETTEXT" && test_set_prereq GETTEXT # Can we rely on git's output in the C locale? @@ -908,14 +913,8 @@ test_i18ngrep () { test_lazy_prereq PIPE ' # test whether the filesystem supports FIFOs - case $(uname -s) in - CYGWIN*|MINGW*) - false - ;; - *) - rm -f testfifo && mkfifo testfifo - ;; - esac + test_have_prereq !MINGW,!CYGWIN && + rm -f testfifo && mkfifo testfifo ' test_lazy_prereq SYMLINKS ' @@ -1011,7 +1010,19 @@ run_with_limited_cmdline () { (ulimit -s 128 && "$@") } -test_lazy_prereq CMDLINE_LIMIT 'run_with_limited_cmdline true' +test_lazy_prereq CMDLINE_LIMIT ' + test_have_prereq !MINGW,!CYGWIN && + run_with_limited_cmdline true +' + +run_with_limited_stack () { + (ulimit -s 128 && "$@") +} + +test_lazy_prereq ULIMIT_STACK_SIZE ' + test_have_prereq !MINGW,!CYGWIN && + run_with_limited_stack true +' build_option () { git version --build-options | From a4390cbba1239ae6040f20065f698b3ac95a5d26 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 22 Dec 2017 01:12:20 -0500 Subject: [PATCH 127/151] more consistent use of test_setup --- t/push.t | 42 +++++++++++++++++++++++++----------------- t/run-enter.t | 2 +- t/which.t | 9 +++++---- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/t/push.t b/t/push.t index b1acb622..3b117924 100755 --- a/t/push.t +++ b/t/push.t @@ -9,37 +9,43 @@ test_expect_success 'push works with no repositories' \ '$VCSH push &>output && test_must_be_empty output' -test_expect_success 'push succeeds if up-to-date' \ +test_setup 'create and clone one repo' \ 'test_create_repo repo && test_commit -C repo A && git clone --bare ./repo repo.git && $VCSH clone ./repo.git foo && - $VCSH foo config push.default simple && + $VCSH foo config push.default simple' - echo -e "foo: Everything up-to-date\\n" >expected && +test_expect_success 'push succeeds if up-to-date' \ + 'echo -e "foo: Everything up-to-date\\n" >expected && $VCSH push &>output && test_cmp expected output' -test_expect_success 'push works with one repository' \ - '$VCSH foo commit --allow-empty -m "empty" && - $VCSH foo rev-parse HEAD >expected && +test_setup 'add empty commit' \ + '$VCSH foo commit --allow-empty -m "empty"' +# XXX Not idempotent - the push affects the "remote" repo +test_expect_success 'push works with one repository' \ + '$VCSH foo rev-parse HEAD >expected && $VCSH push && git -C ./repo.git rev-parse HEAD >output && test_cmp expected output' -test_expect_success 'push works with multiple repositories' \ +test_setup 'create and clone second repo' \ 'test_create_repo repo2 && test_commit -C repo2 C && git clone --bare ./repo2 repo2.git && $VCSH clone ./repo2.git bar && - $VCSH bar config push.default simple && + $VCSH bar config push.default simple' - $VCSH foo commit --allow-empty -m "empty" && - $VCSH bar commit --allow-empty -m "empty" && - $VCSH push && +test_setup 'add more commits' \ + '$VCSH foo commit --allow-empty -m "empty" && + $VCSH bar commit --allow-empty -m "empty"' + +test_expect_success 'push works with multiple repositories' \ + '$VCSH push && $VCSH foo rev-parse HEAD >expected && git -C repo.git rev-parse HEAD >output && @@ -49,20 +55,22 @@ test_expect_success 'push works with multiple repositories' \ git -C repo2.git rev-parse HEAD >output && test_cmp expected output' -test_expect_failure 'push fails if first push fails' \ +test_setup 'add more commits' \ '$VCSH foo commit --allow-empty -m "empty" && - $VCSH bar commit --allow-empty -m "empty" && + $VCSH bar commit --allow-empty -m "empty"' - mv repo2.git repo2.git.missing && +test_expect_failure 'push fails if first push fails' \ + 'mv repo2.git repo2.git.missing && test_when_finished "mv repo2.git.missing repo2.git" && test_must_fail $VCSH push' -test_expect_success 'push fails if first push fails' \ +test_setup 'add more commits' \ '$VCSH foo commit --allow-empty -m "empty" && - $VCSH bar commit --allow-empty -m "empty" && + $VCSH bar commit --allow-empty -m "empty"' - mv repo.git repo.git.missing && +test_expect_success 'push fails if last push fails' \ + 'mv repo.git repo.git.missing && test_when_finished "mv repo.git.missing repo.git" && test_must_fail $VCSH push' diff --git a/t/run-enter.t b/t/run-enter.t index ca53555c..4d36cfca 100755 --- a/t/run-enter.t +++ b/t/run-enter.t @@ -5,7 +5,7 @@ test_description='Run/enter commands' . ./test-lib.sh . "$TEST_DIRECTORY/environment.sh" -test_expect_success 'Setup' \ +test_setup 'Create and populate repos' \ 'test_create_repo repo1 && test_create_repo repo2 && test_commit -C repo1 A && diff --git a/t/which.t b/t/which.t index 17b57260..9fbb6d6b 100755 --- a/t/which.t +++ b/t/which.t @@ -11,7 +11,7 @@ test_expect_success 'Which command does not accept an empty parameter' \ test_expect_success 'Which command fails if no repositories' \ 'test_must_fail $VCSH which nope' -test_expect_success '(setup) Create repository "foo"' \ +test_setup 'Create repository "foo"' \ '$VCSH init foo && mkdir -p dir/subd && @@ -63,7 +63,7 @@ test_expect_success 'Which command matches using POSIX BRE' \ $VCSH which "c.lou\\?r" >output && test_cmp expected output' -test_expect_success 'Which command searches all repos' \ +test_setup 'Create and populate bar/baz repos' \ '$VCSH init bar && $VCSH init baz && @@ -74,9 +74,10 @@ test_expect_success 'Which command searches all repos' \ $VCSH bar add b && $VCSH bar commit -m "hello" && $VCSH baz add c && - $VCSH baz commit -m "hello" && + $VCSH baz commit -m "hello"' - echo "bar: b/hello" >expected && +test_expect_success 'Which command searches all repos' \ + 'echo "bar: b/hello" >expected && echo "baz: c/hello" >>expected && echo "foo: a/hello" >>expected && $VCSH which hello >output && From 804207c13b2ba6a31c0c80baf716987937ebd1a5 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 22 Dec 2017 14:21:57 -0500 Subject: [PATCH 128/151] don't mix quoting when avoidable --- t/delete.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/delete.t b/t/delete.t index 4540a179..82192d6f 100755 --- a/t/delete.t +++ b/t/delete.t @@ -70,7 +70,7 @@ test_expect_failure 'Delete lists files staged for removal before confirmation' 'vcsh_temp_repo foo && touch randomtexttofind && $VCSH foo add randomtexttofind && - $VCSH foo commit -m 'a' && + $VCSH foo commit -m "a" && $VCSH foo rm --cached randomtexttofind && : | test_must_fail $VCSH delete foo >output && @@ -112,7 +112,7 @@ test_expect_failure 'Delete handles filenames with spaces properly' \ test_expect_failure 'Delete handles filenames with wildcard characters properly' \ '$VCSH init foo && touch a b "?" && - $VCSH foo add '\''\?'\'' && + $VCSH foo add "\\?" && $VCSH foo commit -m "?" && doit | $VCSH delete foo && From d7a912caf432629149a9982d4d8fe85adf10c75a Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 22 Dec 2017 14:54:35 -0500 Subject: [PATCH 129/151] set push.default globally --- t/push.t | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/t/push.t b/t/push.t index 3b117924..45d1c7b1 100755 --- a/t/push.t +++ b/t/push.t @@ -5,6 +5,9 @@ test_description='Push command' . ./test-lib.sh . "$TEST_DIRECTORY/environment.sh" +test_setup 'set push.default=simple' \ + 'git config --global push.default simple' + test_expect_success 'push works with no repositories' \ '$VCSH push &>output && test_must_be_empty output' @@ -14,8 +17,7 @@ test_setup 'create and clone one repo' \ test_commit -C repo A && git clone --bare ./repo repo.git && - $VCSH clone ./repo.git foo && - $VCSH foo config push.default simple' + $VCSH clone ./repo.git foo' test_expect_success 'push succeeds if up-to-date' \ 'echo -e "foo: Everything up-to-date\\n" >expected && @@ -37,8 +39,7 @@ test_setup 'create and clone second repo' \ test_commit -C repo2 C && git clone --bare ./repo2 repo2.git && - $VCSH clone ./repo2.git bar && - $VCSH bar config push.default simple' + $VCSH clone ./repo2.git bar' test_setup 'add more commits' \ '$VCSH foo commit --allow-empty -m "empty" && From 42d355eb9e04ba88212293c0c4db0a86e45db5d1 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 22 Dec 2017 15:14:13 -0500 Subject: [PATCH 130/151] allow vcsh_temp_repo to create multiple repos --- t/environment.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/environment.sh b/t/environment.sh index ed2b2089..28335ff7 100644 --- a/t/environment.sh +++ b/t/environment.sh @@ -31,8 +31,10 @@ doit() { } vcsh_temp_repo() { - $VCSH init "$1" && - test_when_finished "doit | \$VCSH delete \"$1\"" + for repo; do + $VCSH init "$repo" && + test_when_finished "doit | \$VCSH delete \"$repo\"" + done } vcsh_temp_clone() { From 2350e079d0f28fd44446071f10ecd8661aa53281 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 22 Dec 2017 15:16:40 -0500 Subject: [PATCH 131/151] ensure all parts of vcsh_temp_* succeed --- t/environment.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/environment.sh b/t/environment.sh index 28335ff7..ecd05027 100644 --- a/t/environment.sh +++ b/t/environment.sh @@ -33,11 +33,11 @@ doit() { vcsh_temp_repo() { for repo; do $VCSH init "$repo" && - test_when_finished "doit | \$VCSH delete \"$repo\"" + test_when_finished "doit | \$VCSH delete \"$repo\"" || return 1 done } vcsh_temp_clone() { $VCSH clone "$1" "$2" && - test_when_finished "doit | \$VCSH delete \"$2\"" + test_when_finished "doit | \$VCSH delete \"$2\"" || return 1 } From 64a52067e024d0fb4deb29739d65d68db9568dbb Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 22 Dec 2017 15:36:33 -0500 Subject: [PATCH 132/151] use test_setup consistently in commit.t --- t/commit.t | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/t/commit.t b/t/commit.t index e01b8523..8c7db767 100755 --- a/t/commit.t +++ b/t/commit.t @@ -9,10 +9,11 @@ test_expect_success 'commit works with no repos' \ '$VCSH commit >output && test_must_be_empty output' -test_expect_success 'commit works with single repo' \ - '$VCSH init foo && +test_setup 'create a repo' \ + '$VCSH init foo' - touch single && +test_expect_success 'commit works with single repo' \ + 'touch single && $VCSH foo add single && # XXX Is printing a trailing space really intended? echo "foo: " >expected && @@ -24,10 +25,11 @@ test_expect_success 'commit works with single repo' \ $VCSH foo rev-list HEAD --count >output && test_cmp expected output' -test_expect_success 'commit works with multiple repos' \ - '$VCSH init bar && +test_setup 'create a second repository' \ + '$VCSH init bar' - touch multi1 multi2 && +test_expect_success 'commit works with multiple repos' \ + 'touch multi1 multi2 && $VCSH foo add multi1 && $VCSH bar add multi2 && # XXX Is printing a trailing space and blank line really intended? From 59f781e6d0a8a39baff9a4437a2a17da785c2fc2 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 22 Dec 2017 15:39:42 -0500 Subject: [PATCH 133/151] these commits were part of their respective tests The state each test should return to is having the vcsh repos are in sync with their upstreams. With these as test_setup, it actually makes things more different when skipping/selecting tests. --- t/push.t | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/t/push.t b/t/push.t index 45d1c7b1..afc5f30e 100755 --- a/t/push.t +++ b/t/push.t @@ -24,12 +24,9 @@ test_expect_success 'push succeeds if up-to-date' \ $VCSH push &>output && test_cmp expected output' -test_setup 'add empty commit' \ - '$VCSH foo commit --allow-empty -m "empty"' - -# XXX Not idempotent - the push affects the "remote" repo test_expect_success 'push works with one repository' \ - '$VCSH foo rev-parse HEAD >expected && + '$VCSH foo commit --allow-empty -m "empty" && + $VCSH foo rev-parse HEAD >expected && $VCSH push && git -C ./repo.git rev-parse HEAD >output && test_cmp expected output' @@ -41,12 +38,10 @@ test_setup 'create and clone second repo' \ $VCSH clone ./repo2.git bar' -test_setup 'add more commits' \ - '$VCSH foo commit --allow-empty -m "empty" && - $VCSH bar commit --allow-empty -m "empty"' - test_expect_success 'push works with multiple repositories' \ - '$VCSH push && + '$VCSH foo commit --allow-empty -m "empty" && + $VCSH bar commit --allow-empty -m "empty" && + $VCSH push && $VCSH foo rev-parse HEAD >expected && git -C repo.git rev-parse HEAD >output && @@ -56,22 +51,20 @@ test_expect_success 'push works with multiple repositories' \ git -C repo2.git rev-parse HEAD >output && test_cmp expected output' -test_setup 'add more commits' \ +test_expect_failure 'push fails if first push fails' \ '$VCSH foo commit --allow-empty -m "empty" && - $VCSH bar commit --allow-empty -m "empty"' + $VCSH bar commit --allow-empty -m "empty" && -test_expect_failure 'push fails if first push fails' \ - 'mv repo2.git repo2.git.missing && + mv repo2.git repo2.git.missing && test_when_finished "mv repo2.git.missing repo2.git" && test_must_fail $VCSH push' -test_setup 'add more commits' \ +test_expect_success 'push fails if last push fails' \ '$VCSH foo commit --allow-empty -m "empty" && - $VCSH bar commit --allow-empty -m "empty"' + $VCSH bar commit --allow-empty -m "empty" && -test_expect_success 'push fails if last push fails' \ - 'mv repo.git repo.git.missing && + mv repo.git repo.git.missing && test_when_finished "mv repo.git.missing repo.git" && test_must_fail $VCSH push' From f10cc41eb7de95c457aad2bca686ddb6357919cc Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 22 Dec 2017 18:19:13 -0500 Subject: [PATCH 134/151] more appropriate gitignore/gitattributes tests Rather than check to see if core.excludesfile and core.attributesfile are set, check to see if the data written to the agreed-upon ignore or attributes file actually takes effect. (Less reliance on internals.) --- t/init.t | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/t/init.t b/t/init.t index 321ffa5d..126f797e 100755 --- a/t/init.t +++ b/t/init.t @@ -108,28 +108,37 @@ test_expect_success 'VCSH_GITIGNORE variable is validated' \ test_env VCSH_GITIGNORE=nonsense test_must_fail $VCSH init ignore2 && test_env VCSH_GITIGNORE=fhqwhgads test_must_fail $VCSH init ignore3' -# XXX test instead by making sure files are actually excluded, not by -# reading config option -test_expect_success 'Init command sets core.excludesfile with VCSH_GITIGNORE=exact' \ +test_setup 'Create gitignore/gitattributes dirs and test files' \ + 'touch ignoreme ignoreme2 ignoreme3 attrfile attrfile2 && + mkdir -p .gitignore.d .gitattributes.d' + +test_expect_success 'Init command sets up .gitignore.d with VCSH_GITIGNORE=exact' \ 'test_env VCSH_GITIGNORE=exact $VCSH init excludes && - $VCSH run excludes git config core.excludesfile' + echo "/ignoreme" >.gitignore.d/excludes && + $VCSH run excludes git check-ignore ignoreme' -# XXX test instead by making sure files are actually excluded, not by -# reading config option -test_expect_success 'Init command sets core.excludesfile with VCSH_GITIGNORE=recursive' \ +test_expect_success 'Init command sets up .gitignore.d with VCSH_GITIGNORE=recursive' \ 'test_env VCSH_GITIGNORE=recursive $VCSH init excludes-r && - $VCSH run excludes-r git config core.excludesfile' + echo "/ignoreme2" >.gitignore.d/excludes-r && + $VCSH run excludes-r git check-ignore ignoreme2' test_expect_success 'Init command does not set core.excludesfile with VCSH_GITIGNORE=none' \ 'test_env VCSH_GITIGNORE=none $VCSH init excludes-n && - test_must_fail $VCSH run excludes-n git config core.excludesfile' + echo "/ignoreme3" >.gitignore.d/excludes-n && + test_must_fail $VCSH run excludes-n git check-ignore ignoreme3' test_expect_success 'Init command sets core.attributesfile with VCSH_GITATTRIBUTES!=none' \ 'test_env VCSH_GITATTRIBUTES=whatever $VCSH init attrs && - $VCSH run attrs git config core.attributesfile' + echo "/attrfile vcshtest=pass" >.gitattributes.d/attrs && + printf "attrfile\\0vcshtest\\0pass\\0" >expected && + $VCSH run attrs git check-attr -z vcshtest attrfile >output && + test_cmp expected output' test_expect_success 'Init command does not set core.attributesfile with VCSH_GITATTRIBUTES=none' \ 'test_env VCSH_GITATTRIBUTES=none $VCSH init no-attrs && - test_must_fail $VCSH run no-attrs git config core.attributesfile' + echo "/attrfile2 vcshtest=pass" >.gitattributes.d/no-attrs && + printf "attrfile2\\0vcshtest\\0unspecified\\0" >expected && + $VCSH run no-attrs git check-attr -z vcshtest attrfile2 >output && + test_cmp expected output' test_done From c43daa85f8fbefde5bf6698c9ce94b80e424e462 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 22 Dec 2017 18:40:40 -0500 Subject: [PATCH 135/151] remove changeable string from push test --- t/push.t | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/t/push.t b/t/push.t index afc5f30e..dc854dc0 100755 --- a/t/push.t +++ b/t/push.t @@ -20,9 +20,7 @@ test_setup 'create and clone one repo' \ $VCSH clone ./repo.git foo' test_expect_success 'push succeeds if up-to-date' \ - 'echo -e "foo: Everything up-to-date\\n" >expected && - $VCSH push &>output && - test_cmp expected output' + '$VCSH push' test_expect_success 'push works with one repository' \ '$VCSH foo commit --allow-empty -m "empty" && From 9e26e19c7884f8b137e0c65b1d81b5cc73fef55b Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 22 Dec 2017 19:10:19 -0500 Subject: [PATCH 136/151] make tests dash-friendly Redirections with >&, piping with |&, and brace expansion weren't handled by dash. Replace with portable equivalents. --- t/debug.t | 4 ++-- t/help.t | 2 +- t/list-tracked.t | 2 +- t/list-untracked.t | 9 ++++++--- t/push.t | 2 +- t/which.t | 2 +- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/t/debug.t b/t/debug.t index 536c8c6c..3151e2c8 100755 --- a/t/debug.t +++ b/t/debug.t @@ -7,7 +7,7 @@ test_description='Debug mode' # XXX add more? test_expect_success 'Debug output includes git version' \ - '$VCSH -d init foo |& test_grep "git version [0-9]" && - $VCSH -d list |& test_grep "git version [0-9]"' + '$VCSH -d init foo 2>&1 | test_grep "git version [0-9]" && + $VCSH -d list 2>&1 | test_grep "git version [0-9]"' test_done diff --git a/t/help.t b/t/help.t index de01ac82..a9a05f8e 100755 --- a/t/help.t +++ b/t/help.t @@ -13,7 +13,7 @@ test_expect_success 'Help command writes to stderr and not stdout' \ $VCSH help 2>/dev/null | test_must_fail test_grep ""' test_expect_success 'Help command prints usage on first line' \ - '$VCSH help |& + '$VCSH help 2>&1 | head -1 | test_grep "^usage: "' diff --git a/t/list-tracked.t b/t/list-tracked.t index 64e1b890..680d49cb 100755 --- a/t/list-tracked.t +++ b/t/list-tracked.t @@ -6,7 +6,7 @@ test_description='List-tracked command' . "$TEST_DIRECTORY/environment.sh" test_expect_success 'list-tracked works with no repos' \ - '$VCSH list-tracked &>output && + '$VCSH list-tracked >output 2>&1 && test_must_be_empty output' test_setup 'Create some files' \ diff --git a/t/list-untracked.t b/t/list-untracked.t index fe6926b3..edf160c9 100755 --- a/t/list-untracked.t +++ b/t/list-untracked.t @@ -9,7 +9,7 @@ test_setup 'Avoid creating additional untracked dirs/files' \ 'export VCSH_GITIGNORE=none VCSH_GITATTRIBUTES=none' test_expect_success 'list-untracked works with no repos' \ - '$VCSH list-untracked &>output && + '$VCSH list-untracked >output 2>&1 && test_must_be_empty output' # Bug @@ -25,8 +25,11 @@ test_expect_success 'list-untracked works with no files' \ test_must_be_empty output' test_setup 'Create some files/directories' \ - 'mkdir files/{tracked,part,untracked} && - touch files/{a,b,tracked/{c,d},part/{e,f},untracked/{g,h}}' + 'mkdir files/tracked files/part files/untracked && + touch files/a files/b \ + files/tracked/c files/tracked/d \ + files/part/e files/part/f \ + files/untracked/g files/untracked/h' # Bug? test_expect_failure 'list-untracked works with no repos' \ diff --git a/t/push.t b/t/push.t index dc854dc0..5dabd8d2 100755 --- a/t/push.t +++ b/t/push.t @@ -9,7 +9,7 @@ test_setup 'set push.default=simple' \ 'git config --global push.default simple' test_expect_success 'push works with no repositories' \ - '$VCSH push &>output && + '$VCSH push >output 2>&1 && test_must_be_empty output' test_setup 'create and clone one repo' \ diff --git a/t/which.t b/t/which.t index 9fbb6d6b..2567f7f5 100755 --- a/t/which.t +++ b/t/which.t @@ -68,7 +68,7 @@ test_setup 'Create and populate bar/baz repos' \ $VCSH init baz && mkdir -p a b c && - touch {a,b,c}/{hello,goodbye} && + touch a/hello b/hello c/hello a/goodbye b/goodbye c/goodbye && $VCSH foo add a && $VCSH foo commit -m "hello" && $VCSH bar add b && From 6d0a3c5278ec26bd545974de5d8ed372fa28c9e0 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 22 Dec 2017 19:11:11 -0500 Subject: [PATCH 137/151] switch /bin/bash to /bin/sh in tests --- t/clone.t | 2 +- t/commit.t | 2 +- t/configfiles.t | 2 +- t/debug.t | 2 +- t/delete.t | 2 +- t/external-vars.t | 2 +- t/foreach.t | 2 +- t/help.t | 2 +- t/hooks.t | 2 +- t/init.t | 2 +- t/list-tracked.t | 2 +- t/list-untracked.t | 2 +- t/list.t | 2 +- t/prove.t | 2 +- t/pull.t | 2 +- t/push.t | 2 +- t/rename.t | 2 +- t/run-enter.t | 2 +- t/status.t | 2 +- t/version.t | 2 +- t/which.t | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) diff --git a/t/clone.t b/t/clone.t index 11dd1fe5..f9317f53 100755 --- a/t/clone.t +++ b/t/clone.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Clone command' diff --git a/t/commit.t b/t/commit.t index 8c7db767..893bbbf2 100755 --- a/t/commit.t +++ b/t/commit.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Commit command' diff --git a/t/configfiles.t b/t/configfiles.t index 1df043b9..07e505c7 100755 --- a/t/configfiles.t +++ b/t/configfiles.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Configuration files' diff --git a/t/debug.t b/t/debug.t index 3151e2c8..15d0c710 100755 --- a/t/debug.t +++ b/t/debug.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Debug mode' diff --git a/t/delete.t b/t/delete.t index 82192d6f..f364c4f2 100755 --- a/t/delete.t +++ b/t/delete.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Delete command' diff --git a/t/external-vars.t b/t/external-vars.t index 57c2c843..5d99a007 100755 --- a/t/external-vars.t +++ b/t/external-vars.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='External environment variables' diff --git a/t/foreach.t b/t/foreach.t index 9d5b56f5..c27c3dc6 100755 --- a/t/foreach.t +++ b/t/foreach.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Foreach command' diff --git a/t/help.t b/t/help.t index a9a05f8e..4290a9a7 100755 --- a/t/help.t +++ b/t/help.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Help command' diff --git a/t/hooks.t b/t/hooks.t index bdac0bc3..0947a9d2 100755 --- a/t/hooks.t +++ b/t/hooks.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Hooks and overlays' diff --git a/t/init.t b/t/init.t index 126f797e..4c4b178a 100755 --- a/t/init.t +++ b/t/init.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Init command' diff --git a/t/list-tracked.t b/t/list-tracked.t index 680d49cb..c775072e 100755 --- a/t/list-tracked.t +++ b/t/list-tracked.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='List-tracked command' diff --git a/t/list-untracked.t b/t/list-untracked.t index edf160c9..4ccaf15a 100755 --- a/t/list-untracked.t +++ b/t/list-untracked.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='List-untracked command' diff --git a/t/list.t b/t/list.t index e3d56a39..64c88405 100755 --- a/t/list.t +++ b/t/list.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='List command' diff --git a/t/prove.t b/t/prove.t index a149abcf..3c4c2d2d 100755 --- a/t/prove.t +++ b/t/prove.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Old tests' diff --git a/t/pull.t b/t/pull.t index f8085030..93086145 100755 --- a/t/pull.t +++ b/t/pull.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Pull command' diff --git a/t/push.t b/t/push.t index 5dabd8d2..8522f166 100755 --- a/t/push.t +++ b/t/push.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Push command' diff --git a/t/rename.t b/t/rename.t index 7f7cad07..8aaea22d 100755 --- a/t/rename.t +++ b/t/rename.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Rename command' diff --git a/t/run-enter.t b/t/run-enter.t index 4d36cfca..15e3a598 100755 --- a/t/run-enter.t +++ b/t/run-enter.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Run/enter commands' diff --git a/t/status.t b/t/status.t index bdf3cfeb..05c68eed 100755 --- a/t/status.t +++ b/t/status.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Status command' diff --git a/t/version.t b/t/version.t index 363d3186..497c64ef 100755 --- a/t/version.t +++ b/t/version.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Version command' diff --git a/t/which.t b/t/which.t index 2567f7f5..6f07729f 100755 --- a/t/which.t +++ b/t/which.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh test_description='Which command' From 8b94f1d7dc9804a60f0da1d1d5280598a1c1bf4b Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Fri, 22 Dec 2017 22:54:25 -0500 Subject: [PATCH 138/151] add external-vars tests These check to make sure that values from the environment don't interfere with internal variables used by vcsh. --- t/external-vars.t | 94 ++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 67 deletions(-) diff --git a/t/external-vars.t b/t/external-vars.t index 5d99a007..62633d6a 100755 --- a/t/external-vars.t +++ b/t/external-vars.t @@ -5,73 +5,33 @@ test_description='External environment variables' . ./test-lib.sh . "$TEST_DIRECTORY/environment.sh" -# XXX writeme +test_setup 'Create a test repository' \ + 'test_create_repo repo && + test_commit -C repo A && + $VCSH init foo' -# All of the following variables are used in vcsh. Make sure that having -# cockamamie values for any of the ones that aren't supposed to affect the -# behavior of vcsh... doesn't. -# -# COLORING -# GIT_DIR -# GIT_DIR_NEW -# GIT_REMOTE -# GIT_VERSION -# GIT_VERSION_MAJOR -# GIT_VERSION_MINOR -# IFS -# OLDIFS -# OPTARG -# PATH -# PWD -# SELF -# SHELL -# STATUS -# TMPDIR -# VCSH_BASE -# VCSH_BRANCH -# VCSH_COMMAND -# VCSH_COMMAND_PARAMETER -# VCSH_COMMAND_RETURN_CODE -# VCSH_CONFLICT -# VCSH_DEBUG -# VCSH_GITATTRIBUTES -# VCSH_GITIGNORE -# VCSH_GIT_OPTIONS -# VCSH_HOOK_D -# VCSH_OPTION_CONFIG -# VCSH_OVERLAY_D -# VCSH_REPO_D -# VCSH_REPO_NAME -# VCSH_REPO_NAME_NEW -# VCSH_STATUS_TERSE -# VCSH_VERBOSE -# VCSH_WORKTREE -# VERSION -# XDG_CONFIG_HOME -# answer -# check_directory -# command_prefix -# commits_ahead -# commits_behind -# directory_component -# directory_opt -# exclude_standard_opt -# file -# files -# gitignore -# gitignores -# hook -# line -# new -# object -# output -# overlay -# ran_once -# remote_tracking_branch -# repo -# temp_file_others -# temp_file_untracked -# temp_file_untracked_copy -# tempfile +test_expect_failure 'No interference from $COLORING' \ + 'COLORING=--fail $VCSH status --terse >output 2>&1 && + test_must_be_empty output' + +test_expect_failure 'No interference from $VCSH_COMMAND_RETURN_CODE' \ + 'VCSH_COMMAND_RETURN_CODE=1 $VCSH list' + +test_expect_failure 'No interference from $VCSH_CONFLICT' \ + 'VCSH_CONFLICT=1 $VCSH clone repo bar && + test_pause && + doit | $VCSH delete bar' + +test_expect_failure 'No interference from $VCSH_OPTION_CONFIG' \ + 'VCSH_OPTION_CONFIG=nothing $VCSH list' + +test_expect_failure 'No interference from $VCSH_STATUS_TERSE' \ + 'echo "foo:" >>expected && + echo "" >>expected && + VCSH_STATUS_TERSE=1 $VCSH status >output && + test_cmp expected output' + +# XXX: `ran_once=1 $VCSH list-untracked' is also problematic but +# may not be worth writing a test for test_done From fb0732b7cb3773b15dc0c5ab3bc6d378b92c6959 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 23 Dec 2017 01:51:49 -0500 Subject: [PATCH 139/151] nuke vcsh_testrepo No need for this with test-lib.sh --- Makefile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 9e568e81..42369a4b 100644 --- a/Makefile +++ b/Makefile @@ -45,10 +45,7 @@ purge: uninstall rmdir -p --ignore-fail-on-non-empty $(DESTDIR)$(DOCDIR) rmdir -p --ignore-fail-on-non-empty $(DESTDIR)$(ZSHDIR) -vcsh_testrepo.git: - git clone --mirror https://github.com/djpohly/vcsh_testrepo.git - -test: | vcsh_testrepo.git +test: $(MAKE) -C t/ moo: From 468649c954da2cd06a51f36c744ee351efa6d6d1 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 24 Dec 2017 17:05:04 -0500 Subject: [PATCH 140/151] add test for help as default command --- t/help.t | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/t/help.t b/t/help.t index 4290a9a7..85e305e5 100755 --- a/t/help.t +++ b/t/help.t @@ -24,6 +24,11 @@ test_expect_failure 'Help command can be abbreviated (hel, he)' \ $VCSH he >output 2>&1 && test_cmp expected output' +test_expect_failure 'Help printed when no command given' \ + '$VCSH help >expected 2>&1 && + $VCSH >output 2>&1 && + test_cmp expected output' + # Help should explain each non-deprecated command. (Note: adjust this if the # format of help output changes.) for cmd in clone commit delete enter foreach help init list list-tracked list-untracked \ From a0f0c3b85e70859918c62fe7d92626579353576d Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 24 Dec 2017 17:16:44 -0500 Subject: [PATCH 141/151] test both -v and -d options --- t/debug.t | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/t/debug.t b/t/debug.t index 15d0c710..db1ccb5a 100755 --- a/t/debug.t +++ b/t/debug.t @@ -1,13 +1,14 @@ #!/bin/sh -test_description='Debug mode' +test_description='Debug/verbose output' . ./test-lib.sh . "$TEST_DIRECTORY/environment.sh" -# XXX add more? -test_expect_success 'Debug output includes git version' \ - '$VCSH -d init foo 2>&1 | test_grep "git version [0-9]" && - $VCSH -d list 2>&1 | test_grep "git version [0-9]"' +test_expect_success 'Verbose output triggered by -v' \ + '$VCSH -v list 2>&1 | test_grep "list begin"' + +test_expect_success 'Debug output triggered by -d' \ + '$VCSH -d list 2>&1 | test_grep "git version"' test_done From 5114b064a65c3c3559ce107d84656f81a0fbe6c1 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 24 Dec 2017 18:07:47 -0500 Subject: [PATCH 142/151] start some configfiles tests This suite can be fleshed out with some clarification on how exactly config files are supposed to work/be used. --- t/configfiles.t | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/t/configfiles.t b/t/configfiles.t index 07e505c7..375bff41 100755 --- a/t/configfiles.t +++ b/t/configfiles.t @@ -5,6 +5,16 @@ test_description='Configuration files' . ./test-lib.sh . "$TEST_DIRECTORY/environment.sh" -# XXX writeme +test_expect_success 'File given with -c is sourced' \ + 'echo "echo _SUCCESS_" >config && + $VCSH -c "$PWD/config" list | test_grep _SUCCESS_' + +test_expect_success 'Relative path works with -c' \ + 'echo "echo _SUCCESS_" >config && + $VCSH -c config list | test_grep _SUCCESS_' + +test_expect_failure 'Command-line options take priority over config files' \ + 'echo "VCSH_VERBOSE=0" >config && + $VCSH -v -c "$PWD/config" list 2>&1 | test_grep "list begin"' test_done From 8b05dc46f5caa174759bbcd1a18a40d3c19e5cda Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 24 Dec 2017 18:08:38 -0500 Subject: [PATCH 143/151] add tests for GIT_WORKTREE --- t/init.t | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/t/init.t b/t/init.t index 4c4b178a..d3ddd4ae 100755 --- a/t/init.t +++ b/t/init.t @@ -96,6 +96,23 @@ test_expect_success 'Init command marks repository with vcsh.vcsh=true' \ $VCSH run foo git config vcsh.vcsh >output && test_cmp expected output' +test_expect_success 'VCSH_WORKTREE=absolute is honored' \ + 'test_env VCSH_WORKTREE=absolute $VCSH init work-abs && + $VCSH work-abs config core.worktree | test_grep "^/"' + +test_expect_success 'VCSH_WORKTREE=absolute is default' \ + 'test_env $VCSH init work-abs2 && + $VCSH work-abs2 config core.worktree | test_grep "^/"' + +test_expect_success 'VCSH_WORKTREE=relative is honored' \ + 'test_env VCSH_WORKTREE=relative $VCSH init work-rel && + $VCSH work-rel config core.worktree | test_grep -v "^/"' + +test_expect_success 'VCSH_WORKTREE variable is validated' \ + 'test_env VCSH_WORKTREE=x test_must_fail $VCSH init wignore1 && + test_env VCSH_WORKTREE=nonsense test_must_fail $VCSH init wignore2 && + test_env VCSH_WORKTREE=fhqwhgads test_must_fail $VCSH init wignore3' + test_expect_success 'Init command adds matching gitignore.d files' \ 'mkdir -p .gitattributes.d .gitignore.d && touch .gitattributes.d/ignore-d .gitignore.d/ignore-d && From 38432caf6676dcd9f44b77ab6e2f64c3998309e2 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 24 Dec 2017 18:28:34 -0500 Subject: [PATCH 144/151] add missing command abbreviation tests --- t/commit.t | 36 +++++++++++++++++++++++++++--------- t/pull.t | 8 ++++++++ t/push.t | 7 +++++++ 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/t/commit.t b/t/commit.t index 893bbbf2..fae064a0 100755 --- a/t/commit.t +++ b/t/commit.t @@ -9,24 +9,42 @@ test_expect_success 'commit works with no repos' \ '$VCSH commit >output && test_must_be_empty output' -test_setup 'create a repo' \ - '$VCSH init foo' - test_expect_success 'commit works with single repo' \ - 'touch single && - $VCSH foo add single && + 'vcsh_temp_repo one && + touch single && + $VCSH one add single && # XXX Is printing a trailing space really intended? - echo "foo: " >expected && + echo "one: " >expected && echo "" >>expected && $VCSH commit -m "single" >output && test_cmp expected output && echo 1 >expected && - $VCSH foo rev-list HEAD --count >output && + $VCSH one rev-list HEAD --count >output && + test_cmp expected output' + +test_expect_success 'commit can be abbreviated (commi, comm, com, co)' \ + 'vcsh_temp_repo abbr && + touch commi && + $VCSH abbr add commi && + $VCSH commi -m "commi" && + touch comm && + $VCSH abbr add comm && + $VCSH comm -m "comm" && + touch com && + $VCSH abbr add com && + $VCSH com -m "com" && + touch co && + $VCSH abbr add co && + $VCSH co -m "co" && + + echo 4 >expected && + $VCSH abbr rev-list --count HEAD >output && test_cmp expected output' -test_setup 'create a second repository' \ - '$VCSH init bar' +test_setup 'create two repositories' \ + '$VCSH init foo && + $VCSH init bar' test_expect_success 'commit works with multiple repos' \ 'touch multi1 multi2 && diff --git a/t/pull.t b/t/pull.t index 93086145..5e2d0723 100755 --- a/t/pull.t +++ b/t/pull.t @@ -27,6 +27,14 @@ test_expect_success 'pull works with one repository' \ $VCSH foo rev-parse HEAD >output && test_cmp expected output' +test_expect_success 'pull can be abbreviated (pul)' \ + 'test_commit -C repo B2 && + git -C repo rev-parse HEAD >expected && + + $VCSH pul && + $VCSH foo rev-parse HEAD >output && + test_cmp expected output' + test_setup 'Create second upstream/downstream repo' \ 'test_create_repo repo2 && test_commit -C repo2 C && diff --git a/t/push.t b/t/push.t index 8522f166..ec9af340 100755 --- a/t/push.t +++ b/t/push.t @@ -29,6 +29,13 @@ test_expect_success 'push works with one repository' \ git -C ./repo.git rev-parse HEAD >output && test_cmp expected output' +test_expect_success 'push can be abbreviated (pus)' \ + '$VCSH foo commit --allow-empty -m "empty2" && + $VCSH foo rev-parse HEAD >expected && + $VCSH pus && + git -C ./repo.git rev-parse HEAD >output && + test_cmp expected output' + test_setup 'create and clone second repo' \ 'test_create_repo repo2 && test_commit -C repo2 C && From 6e755dbe87c746abcfb601b26d51456bea72444e Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 24 Dec 2017 18:29:43 -0500 Subject: [PATCH 145/151] fix whitespace errors --- t/delete.t | 4 ++-- t/list-tracked.t | 2 +- t/run-enter.t | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/t/delete.t b/t/delete.t index f364c4f2..4831712c 100755 --- a/t/delete.t +++ b/t/delete.t @@ -26,7 +26,7 @@ test_expect_success 'Delete requires confirmation' \ echo no | test_must_fail $VCSH delete foo && $VCSH list >output && test_cmp expected output && - + doit | $VCSH delete foo && $VCSH list >output && test_must_be_empty output' @@ -39,7 +39,7 @@ test_expect_success 'Deleted repository removed from list' \ echo bar >expected && $VCSH list >output && test_cmp expected output && - + doit | $VCSH delete bar && $VCSH list >output && test_must_be_empty output' diff --git a/t/list-tracked.t b/t/list-tracked.t index c775072e..64dff85f 100755 --- a/t/list-tracked.t +++ b/t/list-tracked.t @@ -86,7 +86,7 @@ test_expect_success 'list-tracked does not repeat multiple-tracked files' \ } >expected && $VCSH list-tracked >output && test_cmp expected output && - + $VCSH bar reset --hard "$rev"' test_expect_success 'list-tracked-by requires an argument' \ diff --git a/t/run-enter.t b/t/run-enter.t index 15e3a598..5a24cf04 100755 --- a/t/run-enter.t +++ b/t/run-enter.t @@ -10,7 +10,7 @@ test_setup 'Create and populate repos' \ test_create_repo repo2 && test_commit -C repo1 A && test_commit -C repo2 B && - + $VCSH clone ./repo1 foo && $VCSH clone ./repo2 bar' From 30cfff6cb5636fea6d296a4ae5f5c3d150c3647f Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 24 Dec 2017 18:35:20 -0500 Subject: [PATCH 146/151] use test_env more faithfully --- t/external-vars.t | 12 ++++++------ t/run-enter.t | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/t/external-vars.t b/t/external-vars.t index 62633d6a..5820e9a5 100755 --- a/t/external-vars.t +++ b/t/external-vars.t @@ -11,27 +11,27 @@ test_setup 'Create a test repository' \ $VCSH init foo' test_expect_failure 'No interference from $COLORING' \ - 'COLORING=--fail $VCSH status --terse >output 2>&1 && + 'test_env COLORING=--fail $VCSH status --terse >output 2>&1 && test_must_be_empty output' test_expect_failure 'No interference from $VCSH_COMMAND_RETURN_CODE' \ - 'VCSH_COMMAND_RETURN_CODE=1 $VCSH list' + 'test_env VCSH_COMMAND_RETURN_CODE=1 $VCSH list' test_expect_failure 'No interference from $VCSH_CONFLICT' \ - 'VCSH_CONFLICT=1 $VCSH clone repo bar && + 'test_env VCSH_CONFLICT=1 $VCSH clone repo bar && test_pause && doit | $VCSH delete bar' test_expect_failure 'No interference from $VCSH_OPTION_CONFIG' \ - 'VCSH_OPTION_CONFIG=nothing $VCSH list' + 'test_env VCSH_OPTION_CONFIG=nothing $VCSH list' test_expect_failure 'No interference from $VCSH_STATUS_TERSE' \ 'echo "foo:" >>expected && echo "" >>expected && - VCSH_STATUS_TERSE=1 $VCSH status >output && + test_env VCSH_STATUS_TERSE=1 $VCSH status >output && test_cmp expected output' -# XXX: `ran_once=1 $VCSH list-untracked' is also problematic but +# XXX: `test_env ran_once=1 $VCSH list-untracked' is also problematic but # may not be worth writing a test for test_done diff --git a/t/run-enter.t b/t/run-enter.t index 5a24cf04..0384fbbd 100755 --- a/t/run-enter.t +++ b/t/run-enter.t @@ -53,7 +53,7 @@ test_expect_success 'Enter executes inside specific repository' \ test_expect_success 'Enter executes $SHELL inside repository' \ 'git -C repo1 rev-parse HEAD >expected && - SHELL="git rev-parse HEAD" $VCSH enter foo >output && + test_env SHELL="git rev-parse HEAD" $VCSH enter foo >output && test_cmp expected output' test_expect_success 'Enter implied for single non-command argument' \ @@ -75,9 +75,9 @@ test_expect_success 'Enter can be abbreviated (ente, ent, en)' \ 'git -C repo1 rev-parse HEAD HEAD HEAD >expected && { - echo "git rev-parse HEAD" | SHELL=/bin/sh $VCSH ente foo && - echo "git rev-parse HEAD" | SHELL=/bin/sh $VCSH ent foo && - echo "git rev-parse HEAD" | SHELL=/bin/sh $VCSH en foo + echo "git rev-parse HEAD" | test_env SHELL=/bin/sh $VCSH ente foo && + echo "git rev-parse HEAD" | test_env SHELL=/bin/sh $VCSH ent foo && + echo "git rev-parse HEAD" | test_env SHELL=/bin/sh $VCSH en foo } >output && test_cmp expected output' From 96c3e0da09168f47b9520c219cb3e8641dd9eb46 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 24 Dec 2017 18:46:35 -0500 Subject: [PATCH 147/151] make sure clone doesn't overwrite existing files --- t/clone.t | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/t/clone.t b/t/clone.t index f9317f53..52a961c8 100755 --- a/t/clone.t +++ b/t/clone.t @@ -20,6 +20,14 @@ test_setup 'Create upstream repos' \ test_expect_success 'Clone requires a remote' \ 'test_must_fail $VCSH clone' +test_expect_success 'Clone refuses to overwrite existing files' \ + 'echo success >A.t && + test_when_finished "rm -f A.t" && + test_might_fail $VCSH clone repo temp && + test_when_finished "doit | $VCSH delete temp" && + echo success >expected && + test_cmp expected A.t' + test_expect_success 'Clone uses existing repo name by default' \ '$VCSH clone ./repo && test_when_finished "doit | $VCSH delete repo" && From 605522687580453e680dc974b514f08e9eab2bd4 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 24 Dec 2017 18:49:00 -0500 Subject: [PATCH 148/151] remove stray test_pause --- t/external-vars.t | 1 - 1 file changed, 1 deletion(-) diff --git a/t/external-vars.t b/t/external-vars.t index 5820e9a5..83d0c6f9 100755 --- a/t/external-vars.t +++ b/t/external-vars.t @@ -19,7 +19,6 @@ test_expect_failure 'No interference from $VCSH_COMMAND_RETURN_CODE' \ test_expect_failure 'No interference from $VCSH_CONFLICT' \ 'test_env VCSH_CONFLICT=1 $VCSH clone repo bar && - test_pause && doit | $VCSH delete bar' test_expect_failure 'No interference from $VCSH_OPTION_CONFIG' \ From b0f2992f8fa86b0503fc7471f3887eaa20cd35e2 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 24 Dec 2017 19:31:30 -0500 Subject: [PATCH 149/151] remove vestigial check for socat --- t/status.t | 5 ----- 1 file changed, 5 deletions(-) diff --git a/t/status.t b/t/status.t index 05c68eed..e54a9281 100755 --- a/t/status.t +++ b/t/status.t @@ -25,11 +25,6 @@ test_expect_success 'Terse status correct for empty repo' \ '$VCSH status --terse >output && test_must_be_empty output' -test_setup 'Check for socat (needed for pseudo-tty)' \ - 'if which socat; then - test_set_prereq SOCAT - fi' - test_setup 'Create and add a file' \ 'touch a && $VCSH run foo git add a' From 4ebaa4526dd3cfa1aa933484b0e6c2d5ac9a204f Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 24 Dec 2017 21:08:36 -0500 Subject: [PATCH 150/151] add test for cloning empty repo --- t/clone.t | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/t/clone.t b/t/clone.t index 52a961c8..a93230de 100755 --- a/t/clone.t +++ b/t/clone.t @@ -6,7 +6,9 @@ test_description='Clone command' . "$TEST_DIRECTORY/environment.sh" test_setup 'Create upstream repos' \ - 'test_create_repo repo && + 'test_create_repo empty && + + test_create_repo repo && test_commit -C repo A && git -C repo checkout -b branchb && test_commit -C repo A2 && @@ -20,6 +22,10 @@ test_setup 'Create upstream repos' \ test_expect_success 'Clone requires a remote' \ 'test_must_fail $VCSH clone' +test_expect_success 'Warn about cloning empty repo' \ + 'test_when_finished "doit | $VCSH delete empty" && + test_might_fail $VCSH clone empty 2>&1 | test_grep "remote is empty"' + test_expect_success 'Clone refuses to overwrite existing files' \ 'echo success >A.t && test_when_finished "rm -f A.t" && From fb95d5819d0f6f829c30c81ad62be97fea3ed7c4 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 24 Dec 2017 21:09:00 -0500 Subject: [PATCH 151/151] add some write-gitignore tests --- t/write-gitignore.t | 121 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100755 t/write-gitignore.t diff --git a/t/write-gitignore.t b/t/write-gitignore.t new file mode 100755 index 00000000..6070f47d --- /dev/null +++ b/t/write-gitignore.t @@ -0,0 +1,121 @@ +#!/bin/sh + +# XXX Distinction between recursive/exact for VCSH_GITIGNORE is unclear; +# currently they are equivalent because ls-files doesn't show directories. + +test_description='write-gitignore command' + +. ./test-lib.sh +. "$TEST_DIRECTORY/environment.sh" + +test_expect_success 'parameter is required' \ + 'test_must_fail $VCSH write-gitignore' + +test_expect_success 'empty parameter not allowed' \ + 'test_must_fail $VCSH write-gitignore ""' + +test_expect_success 'fails if no repositories' \ + 'test_must_fail $VCSH write-gitignore nope' + +test_setup 'create repository "foo"' \ + '$VCSH init foo && + + mkdir dir dir2 && + touch a b c dir/d dir/e dir2/f dir2/g && + $VCSH foo add a b dir/d && + $VCSH foo commit -m "commit"' + +test_expect_success 'given repository must exist' \ + 'test_must_fail $VCSH write-gitignore fail' + +test_expect_success 'does nothing with VCSH_GITIGNORE=none' \ + 'test_might_fail test_env VCSH_GITIGNORE=none $VCSH write-gitignore foo && + test_must_fail test -e .gitignore.d/foo' + +test_expect_success 'command succeeds' \ + '$VCSH write-gitignore foo && + test_when_finished "rm -rf .gitignore.d/"' + +test_expect_success 'current files not ignored' \ + '$VCSH write-gitignore foo && + test_when_finished "rm -rf .gitignore.d/"&& + test_must_fail $VCSH foo check-ignore a && + test_must_fail $VCSH foo check-ignore b && + test_must_fail $VCSH foo check-ignore dir/d' + +test_expect_success 'other existing files ignored' \ + '$VCSH write-gitignore foo && + test_when_finished "rm -rf .gitignore.d/"&& + $VCSH foo check-ignore c && + $VCSH foo check-ignore dir/e && + $VCSH foo check-ignore dir2/f && + $VCSH foo check-ignore dir2/g' + +test_expect_success 'can be abbreviated "write"' \ + '$VCSH write foo && + test_when_finished "rm -rf .gitignore.d/"&& + test_must_fail $VCSH foo check-ignore a && + test_must_fail $VCSH foo check-ignore b && + test_must_fail $VCSH foo check-ignore dir/d && + $VCSH foo check-ignore c && + $VCSH foo check-ignore dir/e && + $VCSH foo check-ignore dir2/f && + $VCSH foo check-ignore dir2/g' + +test_expect_success 'can be abbreviated "writ"' \ + '$VCSH writ foo && + test_when_finished "rm -rf .gitignore.d/"&& + test_must_fail $VCSH foo check-ignore a && + test_must_fail $VCSH foo check-ignore b && + test_must_fail $VCSH foo check-ignore dir/d && + $VCSH foo check-ignore c && + $VCSH foo check-ignore dir/e && + $VCSH foo check-ignore dir2/f && + $VCSH foo check-ignore dir2/g' + +test_expect_success 'can be abbreviated "wri"' \ + '$VCSH wri foo && + test_when_finished "rm -rf .gitignore.d/"&& + test_must_fail $VCSH foo check-ignore a && + test_must_fail $VCSH foo check-ignore b && + test_must_fail $VCSH foo check-ignore dir/d && + $VCSH foo check-ignore c && + $VCSH foo check-ignore dir/e && + $VCSH foo check-ignore dir2/f && + $VCSH foo check-ignore dir2/g' + +test_expect_success 'can be abbreviated "wr"' \ + '$VCSH wr foo && + test_when_finished "rm -rf .gitignore.d/"&& + test_must_fail $VCSH foo check-ignore a && + test_must_fail $VCSH foo check-ignore b && + test_must_fail $VCSH foo check-ignore dir/d && + $VCSH foo check-ignore c && + $VCSH foo check-ignore dir/e && + $VCSH foo check-ignore dir2/f && + $VCSH foo check-ignore dir2/g' + +test_expect_success 'files added later ignored' \ + '$VCSH write-gitignore foo && + test_when_finished "rm -rf .gitignore.d/"&& + touch x && + test_when_finished "rm -f x" && + $VCSH foo check-ignore x' + +test_expect_success 'works for files with space characters' \ + 'fname="$(printf '\''hello\tthere\nworld'\'')" && + touch "$fname" && + $VCSH foo add "$fname" && + $VCSH foo commit -m "weird chars" && + $VCSH write-gitignore foo && + test_when_finished "rm -rf .gitignore.d/"&& + test_must_fail $VCSH foo check-ignore "$fname"' + +test_expect_success 'fails if .gitignore cannot be replaced' \ + 'mkdir -p .gitignore.d && + touch .gitignore.d/foo && + chmod a-w .gitignore.d .gitignore.d/foo && + test_when_finished "chmod u+w .gitignore.d .gitignore.d/foo" && + test_must_fail $VCSH write-gitignore foo' + +test_done