Skip to content

Commit 3d26860

Browse files
committed
Make test directory modifcation easier
Many of the tests used relative paths for determining the test directories. This made verification of output very difficult if the directory were to change. I plan to add tests for directories that have spaces and additional character patterns and this will allow these tests to be added easier.
1 parent ce6724b commit 3d26860

15 files changed

+43
-41
lines changed

test/branch-all.t

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ clone-foo-and-bar
1212

1313
(
1414
cd $OWNER/foo
15-
git subrepo clone --quiet ../../../$UPSTREAM/bar one
16-
git subrepo clone --quiet ../../../$UPSTREAM/bar two
15+
git subrepo clone --quiet $UPSTREAM/bar one
16+
git subrepo clone --quiet $UPSTREAM/bar two
1717
add-new-files two/file
1818
)
1919

test/clone.t

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ clone-foo-and-bar
2828
{
2929
clone_output="$(
3030
cd $OWNER/foo
31-
git subrepo clone ../../../$UPSTREAM/bar
31+
git subrepo clone $UPSTREAM/bar
3232
)"
3333

3434
# Check output is correct:
3535
is "$clone_output" \
36-
"Subrepo '../../../tmp/upstream/bar' (master) cloned into 'bar'." \
36+
"Subrepo '$UPSTREAM/bar' (master) cloned into 'bar'." \
3737
'subrepo clone command output is correct'
3838

3939
remote_output="$(
@@ -50,7 +50,7 @@ clone-foo-and-bar
5050

5151
clone_output_empty="$(
5252
cd $OWNER/empty
53-
catch git subrepo clone ../../../$UPSTREAM/bar
53+
catch git subrepo clone $UPSTREAM/bar
5454
)"
5555

5656
# Check output is correct:
@@ -74,7 +74,7 @@ gitrepo=$OWNER/foo/bar/.gitrepo
7474
foo_clone_commit="$(cd $OWNER/foo; git rev-parse HEAD^)"
7575
bar_head_commit="$(cd $OWNER/bar; git rev-parse HEAD)"
7676
test-gitrepo-comment-block
77-
test-gitrepo-field "remote" "../../../$UPSTREAM/bar"
77+
test-gitrepo-field "remote" "$UPSTREAM/bar"
7878
test-gitrepo-field "branch" "master"
7979
test-gitrepo-field "commit" "$bar_head_commit"
8080
test-gitrepo-field "parent" "$foo_clone_commit"

test/encode.t

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ source test/setup
66

77
use Test::More
88

9-
109
export round=0
1110
test_round() {
1211
clone-foo-and-bar
@@ -19,12 +18,12 @@ test_round() {
1918

2019
clone_output="$(
2120
cd $OWNER/foo
22-
git subrepo clone ../../../$UPSTREAM/bar -- "$normalize_dir"
21+
git subrepo clone $UPSTREAM/bar -- "$normalize_dir"
2322
)"
2423

2524
# Check output is correct:
2625
is "$clone_output" \
27-
"Subrepo '../../../tmp/upstream/bar' (master) cloned into '$normalize_dir'." \
26+
"Subrepo '$UPSTREAM/bar' (master) cloned into '$normalize_dir'." \
2827
'subrepo clone command output is correct'
2928

3029
test-exists "$OWNER/foo/$normalize_dir/"
@@ -42,7 +41,7 @@ test_round() {
4241
cd $OWNER/foo
4342
git subrepo pull -- "$normalize_dir"
4443
)" \
45-
"Subrepo '$normalize_dir' pulled from '../../../tmp/upstream/bar' (master)." \
44+
"Subrepo '$normalize_dir' pulled from '$UPSTREAM/bar' (master)." \
4645
'subrepo pull command output is correct'
4746
}
4847

@@ -61,7 +60,7 @@ test_round() {
6160
cd $OWNER/foo
6261
git subrepo push -- "$normalize_dir"
6362
)" \
64-
"Subrepo '$normalize_dir' pushed to '../../../tmp/upstream/bar' (master)." \
63+
"Subrepo '$normalize_dir' pushed to '$UPSTREAM/bar' (master)." \
6564
'subrepo push command output is correct'
6665
}
6766
}
@@ -86,6 +85,7 @@ test_round '_under_scores_'
8685
test_round '.str%a\nge...'
8786
test_round '~////......s:a^t?r a*n[g@{e.lock'
8887

88+
8989
done_testing
9090

9191
teardown

test/error.t

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ clone-foo-and-bar
1414
{
1515
is "$(
1616
cd $OWNER/bar
17-
git subrepo --quiet clone ../../../$UPSTREAM/foo
17+
git subrepo --quiet clone $UPSTREAM/foo
1818
add-new-files foo/file
1919
git subrepo --quiet branch foo
2020
catch git subrepo branch foo
@@ -129,7 +129,7 @@ clone-foo-and-bar
129129
cd $OWNER/bar
130130
touch me
131131
git add me
132-
catch git subrepo clone ../../../$UPSTREAM/foo
132+
catch git subrepo clone $UPSTREAM/foo
133133
)" \
134134
"git-subrepo: Can't clone subrepo. Working tree has changes." \
135135
"Error OK: check no working tree changes"

test/fetch.t

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ subrepo-clone-bar-into-foo
2424
cd $OWNER/foo
2525
git subrepo fetch bar
2626
)" \
27-
"Fetched 'bar' from '../../../tmp/upstream/bar' (master)." \
27+
"Fetched 'bar' from '$UPSTREAM/bar' (master)." \
2828
'subrepo fetch command output is correct'
2929
}
3030

test/gitignore.t

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ subrepo-clone-bar-into-foo
3232
cd $OWNER/foo
3333
git subrepo pull bar
3434
)" \
35-
"Subrepo 'bar' pulled from '../../../tmp/upstream/bar' (master)." \
35+
"Subrepo 'bar' pulled from '$UPSTREAM/bar' (master)." \
3636
'subrepo pull command output is correct'
3737
}
3838

@@ -49,7 +49,7 @@ gitrepo=$OWNER/foo/bar/.gitrepo
4949
foo_pull_commit="$(cd $OWNER/foo; git rev-parse HEAD^)"
5050
bar_head_commit="$(cd $OWNER/bar; git rev-parse HEAD)"
5151
test-gitrepo-comment-block
52-
test-gitrepo-field "remote" "../../../$UPSTREAM/bar"
52+
test-gitrepo-field "remote" "$UPSTREAM/bar"
5353
test-gitrepo-field "branch" "master"
5454
test-gitrepo-field "commit" "$bar_head_commit"
5555
test-gitrepo-field "parent" "$foo_pull_commit"

test/pull-message.t

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ subrepo-clone-bar-into-foo
2323
cd $OWNER/foo
2424
git subrepo pull -m 'Hello World' bar
2525
)" \
26-
"Subrepo 'bar' pulled from '../../../tmp/upstream/bar' (master)." \
26+
"Subrepo 'bar' pulled from '$UPSTREAM/bar' (master)." \
2727
'subrepo pull command output is correct'
2828
}
2929

@@ -47,7 +47,7 @@ subrepo-clone-bar-into-foo
4747
cd $OWNER/foo
4848
GIT_EDITOR='echo cowabunga >' git subrepo pull -e bar
4949
)" \
50-
"Subrepo 'bar' pulled from '../../../tmp/upstream/bar' (master)." \
50+
"Subrepo 'bar' pulled from '$UPSTREAM/bar' (master)." \
5151
'subrepo pull command output is correct'
5252
}
5353

@@ -71,7 +71,7 @@ subrepo-clone-bar-into-foo
7171
cd $OWNER/foo
7272
GIT_EDITOR=true git subrepo pull -e -m original bar
7373
)" \
74-
"Subrepo 'bar' pulled from '../../../tmp/upstream/bar' (master)." \
74+
"Subrepo 'bar' pulled from '$UPSTREAM/bar' (master)." \
7575
'subrepo pull command output is correct'
7676
}
7777

test/pull-new-branch.t

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ gitrepo=$OWNER/foo/bar/.gitrepo
2121
foo_pull_commit=$(cd "$OWNER/foo"; git rev-parse HEAD^)
2222
bar_head_commit=$(cd "$OWNER/bar"; git rev-parse HEAD)
2323
test-gitrepo-comment-block
24-
test-gitrepo-field remote "../../../$UPSTREAM/bar"
24+
test-gitrepo-field remote "$UPSTREAM/bar"
2525
test-gitrepo-field branch master
2626
test-gitrepo-field commit "$bar_head_commit"
2727
test-gitrepo-field parent "$foo_pull_commit"
@@ -37,7 +37,7 @@ gitrepo=$OWNER/foo/bar/.gitrepo
3737
foo_pull_commit=$(cd "$OWNER/foo"; git rev-parse HEAD^)
3838
bar_head_commit=$(cd "$OWNER/bar"; git rev-parse HEAD)
3939
test-gitrepo-comment-block
40-
test-gitrepo-field remote "../../../$UPSTREAM/bar"
40+
test-gitrepo-field remote "$UPSTREAM/bar"
4141
test-gitrepo-field branch branch1
4242
test-gitrepo-field commit "$bar_head_commit"
4343
test-gitrepo-field parent "$foo_pull_commit"

test/pull.t

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ subrepo-clone-bar-into-foo
2323
cd $OWNER/foo
2424
git subrepo pull bar
2525
)" \
26-
"Subrepo 'bar' pulled from '../../../tmp/upstream/bar' (master)." \
26+
"Subrepo 'bar' pulled from '$UPSTREAM/bar' (master)." \
2727
'subrepo pull command output is correct'
2828
}
2929

@@ -40,7 +40,7 @@ gitrepo=$OWNER/foo/bar/.gitrepo
4040
foo_pull_commit="$(cd $OWNER/foo; git rev-parse HEAD^)"
4141
bar_head_commit="$(cd $OWNER/bar; git rev-parse HEAD)"
4242
test-gitrepo-comment-block
43-
test-gitrepo-field "remote" "../../../$UPSTREAM/bar"
43+
test-gitrepo-field "remote" "$UPSTREAM/bar"
4444
test-gitrepo-field "branch" "master"
4545
test-gitrepo-field "commit" "$bar_head_commit"
4646
test-gitrepo-field "parent" "$foo_pull_commit"
@@ -63,7 +63,7 @@ gitrepo=$OWNER/foo/bar/.gitrepo
6363
{
6464
is "$(
6565
cd $OWNER/foo
66-
git subrepo pull bar
66+
git subrepo pull bar
6767
)" \
6868
"Subrepo 'bar' is up to date." \
6969
'subrepo detects that we dont need to pull'

test/push-new-branch.t

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ clone-foo-and-bar
1414
cd $OWNER/foo
1515

1616
# Clone the subrepo into a subdir
17-
git subrepo clone ../../../$UPSTREAM/bar
17+
git subrepo clone $UPSTREAM/bar
1818

1919
# Make a commit:
2020
add-new-files bar/FooBar
@@ -29,7 +29,7 @@ clone-foo-and-bar
2929

3030
# Test the output:
3131
is "$message" \
32-
"Subrepo 'bar' pushed to '../../../tmp/upstream/bar' (newbar)." \
32+
"Subrepo 'bar' pushed to '$UPSTREAM/bar' (newbar)." \
3333
'First push message is correct '
3434
}
3535

test/push-no-changes.t

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ clone-foo-and-bar
1313
{
1414
is "$(
1515
cd $OWNER/bar
16-
git subrepo --quiet clone ../../../$UPSTREAM/foo
16+
git subrepo --quiet clone $UPSTREAM/foo
1717
catch git subrepo push foo
1818
)" \
1919
"Subrepo 'foo' has no new commits to push." \

test/push-squash.t

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ clone-foo-and-bar
1414
cd $OWNER/foo
1515

1616
# Clone the subrepo into a subdir
17-
git subrepo clone ../../../$UPSTREAM/bar
17+
git subrepo clone $UPSTREAM/bar
1818

1919
# Make a series of commits:
2020
add-new-files bar/FooBar1
@@ -33,7 +33,7 @@ clone-foo-and-bar
3333

3434
# Test the output:
3535
is "$message" \
36-
"Subrepo 'bar' pushed to '../../../tmp/upstream/bar' (master)." \
36+
"Subrepo 'bar' pushed to '$UPSTREAM/bar' (master)." \
3737
'push message is correct'
3838
}
3939

test/push.t

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ clone-foo-and-bar
1616
cd $OWNER/foo
1717

1818
# Clone the subrepo into a subdir
19-
git subrepo clone ../../../$UPSTREAM/bar
19+
git subrepo clone $UPSTREAM/bar
2020

2121
# Make a series of commits:
2222
add-new-files bar/FooBar
@@ -44,7 +44,7 @@ clone-foo-and-bar
4444

4545
# Test the output:
4646
is "$message" \
47-
"Subrepo 'bar' pushed to '../../../tmp/upstream/bar' (master)." \
47+
"Subrepo 'bar' pushed to '$UPSTREAM/bar' (master)." \
4848
'push message is correct'
4949
}
5050

@@ -83,7 +83,7 @@ gitrepo=$OWNER/foo/bar/.gitrepo
8383
{
8484
foo_pull_commit="$(cd $OWNER/foo; git rev-parse HEAD^)"
8585
bar_head_commit="$(cd $OWNER/bar; git rev-parse HEAD)"
86-
test-gitrepo-field "remote" "../../../$UPSTREAM/bar"
86+
test-gitrepo-field "remote" "$UPSTREAM/bar"
8787
test-gitrepo-field "branch" "master"
8888
test-gitrepo-field "commit" "$bar_head_commit"
8989
test-gitrepo-field "parent" "$foo_pull_commit"
@@ -105,7 +105,7 @@ gitrepo=$OWNER/foo/bar/.gitrepo
105105

106106
# Test the output:
107107
is "$message" \
108-
"Subrepo 'bar' pushed to '../../../tmp/upstream/bar' (master)." \
108+
"Subrepo 'bar' pushed to '$UPSTREAM/bar' (master)." \
109109
'push message is correct'
110110
}
111111

@@ -140,7 +140,7 @@ test-exists \
140140

141141
# Test the output:
142142
is "$message" \
143-
"Subrepo 'bar' pushed to '../../../tmp/upstream/bar' (master)." \
143+
"Subrepo 'bar' pushed to '$UPSTREAM/bar' (master)." \
144144
'Seqential pushes are correct'
145145
}
146146

test/reclone.t

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ clone-foo-and-bar
1010

1111
(
1212
cd $OWNER/foo
13-
git subrepo --quiet clone ../../../$UPSTREAM/bar
13+
git subrepo --quiet clone $UPSTREAM/bar
1414
)
1515

1616
test-exists \
@@ -19,22 +19,22 @@ test-exists \
1919
export XYZ=1
2020
is "$(
2121
cd $OWNER/foo
22-
git subrepo --force clone ../../../$UPSTREAM/bar
22+
git subrepo --force clone $UPSTREAM/bar
2323
)" \
2424
"Subrepo 'bar' is up to date." \
2525
"No reclone if same commit"
2626

2727
(
2828
cd $OWNER/foo
29-
git subrepo --quiet clone --force ../../../$UPSTREAM/bar --branch=refs/tags/A
29+
git subrepo --quiet clone --force $UPSTREAM/bar --branch=refs/tags/A
3030
)
3131

3232
test-exists \
3333
"!$OWNER/foo/bar/bard/"
3434

3535
(
3636
cd $OWNER/foo
37-
git subrepo --quiet clone -f ../../../$UPSTREAM/bar --branch=master
37+
git subrepo --quiet clone -f $UPSTREAM/bar --branch=master
3838
)
3939

4040
test-exists \

test/setup

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ set -e
88
# Set the GIT_SUBREPO_ROOT for testing.
99
source "$PWD"/.rc
1010

11+
# Get the location of this script
12+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
13+
1114
BASHLIB="$(
1215
find "$PWD"/ -type d -name bin -o -type d -name lib | tr '\n' ':'
1316
)"
@@ -18,8 +21,7 @@ source bash+ :std
1821

1922
source 'lib/git-subrepo'
2023

21-
# TODO: Move to test/tmp
22-
export TMP="tmp"
24+
export TMP="$SCRIPT_DIR/tmp"
2325
rm -fr $TMP
2426

2527
#export GIT_EXEC_PATH="$PWD/lib:$(git --exec-path)"
@@ -58,7 +60,7 @@ clone-foo-and-bar() {
5860
subrepo-clone-bar-into-foo() {
5961
(
6062
cd $OWNER/foo
61-
git subrepo clone ../../../$UPSTREAM/bar
63+
git subrepo clone $UPSTREAM/bar
6264
) &> /dev/null || die
6365
}
6466

0 commit comments

Comments
 (0)