Skip to content

Commit ff8aac2

Browse files
committed
refactor: Remove 'package_helpers'
This removes package_helpers and does related general cleanup. At this point, all the tests have been converted to use new style (not calling helper functions, but doing everything while CD'ed into the package directory)
1 parent 5db08d8 commit ff8aac2

File tree

6 files changed

+46
-66
lines changed

6 files changed

+46
-66
lines changed

pkg/lib/util/util.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ util.parse_package_full() {
1616
repoSpec="${repoSpec#http?(s)://}"
1717

1818
local site user repository
19-
if [[ "$repoSpec" = */*/* ]]; then
19+
if [[ "$repoSpec" == */*/* ]]; then
2020
IFS='/' read -r site user repository <<< "$repoSpec"
21-
elif [[ "$repoSpec" = */* ]]; then
21+
elif [[ "$repoSpec" == */* ]]; then
2222
site="github.com"
2323
IFS='/' read -r user repository <<< "$repoSpec"
2424
fi
2525

26-
if [[ "$repository" = *@* ]]; then
26+
if [[ "$repository" == *@* ]]; then
2727
IFS='@' read -r repository ref <<< "$repository"
2828
else
2929
ref=""
@@ -80,7 +80,7 @@ util.construct_clone_url() {
8080
else
8181
repoSpec="${repoSpec%.git}"
8282

83-
if [[ "$repoSpec" = */*/* ]]; then
83+
if [[ "$repoSpec" == */*/* ]]; then
8484
IFS='/' read -r site package <<< "$repoSpec"
8585
elif [[ "$repoSpec" = */* ]]; then
8686
site="github.com"
@@ -89,7 +89,7 @@ util.construct_clone_url() {
8989
die "Invalid repository '$repoSpec'"
9090
fi
9191

92-
if [[ "$package" = *@* ]]; then
92+
if [[ "$package" == *@* ]]; then
9393
IFS='@' read -r package ref <<< "$package"
9494
fi
9595

tests/do-list.bats

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
load 'util/init.sh'
44

55
@test "properly list for 2 installed packages" {
6-
create_package 'username/p1'
7-
create_package 'username2/p2'
8-
create_package 'username2/p3'
6+
test_util.create_package 'username/p1'
7+
test_util.create_package 'username2/p2'
8+
test_util.create_package 'username2/p3'
99
test_util.fake_clone 'username/p1'
1010
test_util.fake_clone 'username2/p2'
1111

@@ -18,7 +18,7 @@ load 'util/init.sh'
1818
}
1919

2020
@test "properly list for no installed packages" {
21-
create_package username/p1
21+
test_util.create_package 'username/p1'
2222

2323
run do-list
2424

@@ -27,14 +27,24 @@ load 'util/init.sh'
2727
}
2828

2929
@test "properly list outdated packages" {
30-
create_package username/outdated
31-
create_package username/uptodate
32-
test_util.fake_clone username/outdated
33-
test_util.fake_clone username/uptodate
34-
create_exec username/outdated "second"
30+
local pkg1='username/outdated'
31+
local pkg2='username/uptodate'
32+
33+
test_util.create_package "$pkg1"
34+
test_util.create_package "$pkg2"
35+
test_util.fake_clone "$pkg1"
36+
test_util.fake_clone "$pkg2"
37+
38+
# Make pkg1 outdated by commiting to it
39+
cd "$BPM_ORIGIN_DIR/$pkg1"; {
40+
mkdir -p bin
41+
touch "bin/exec"
42+
git add .
43+
git commit -m "Add exec"
44+
}; cd "$BPM_CWD"
3545

3646
run do-list --outdated
3747

3848
assert_success
39-
assert_output username/outdated
49+
assert_output 'username/outdated'
4050
}

tests/do-package-path.bats

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
load 'util/init.sh'
44

55
@test "prints the package path" {
6-
create_package username/package
7-
test_util.fake_clone username/package
6+
local pkg='username/package'
87

9-
run bpm-package-path username/package
8+
test_util.create_package "$pkg"
9+
test_util.fake_install "$pkg"
1010

11-
assert_success "$BPM_PACKAGES_PATH/username/package"
11+
run bpm-package-path "$pkg"
12+
13+
assert_success "$BPM_PACKAGES_PATH/$pkg"
1214
}

tests/util/init.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ shopt -s nullglob extglob
55

66
load 'vendor/bats-core/load'
77
load 'vendor/bats-assert/load'
8-
load 'util/package_helpers.sh'
98
load 'util/test_util.sh'
109

1110
export BPM_TEST_DIR="$BATS_TMPDIR/bpm"

tests/util/package_helpers.sh

Lines changed: 0 additions & 44 deletions
This file was deleted.

tests/util/test_util.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ test_util.setup_pkg() {
4242
touch 'README.md'
4343
git add .
4444
git commit -m "Initial commit"
45-
46-
cd "$BPM_ORIGIN_DIR/$pkg"
4745
}
4846

4947
# @description Commits changes and cd's out of the package directory
@@ -53,3 +51,18 @@ test_util.finish_pkg() {
5351
git commit --allow-empty -m "Make changes"
5452
cd "$BPM_CWD"
5553
}
54+
55+
test_util.create_package() {
56+
local pkg="$1"
57+
58+
mkdir -p "$BPM_ORIGIN_DIR/$pkg"
59+
cd "$BPM_ORIGIN_DIR/$pkg"
60+
61+
git init .
62+
touch 'README.md'
63+
touch 'bpm.toml'
64+
git add .
65+
git commit -m "Initial commit"
66+
67+
cd "$BPM_CWD"
68+
}

0 commit comments

Comments
 (0)