Skip to content

Commit 1a78afe

Browse files
committed
feat(steps-lib): add file_exists helper function
1 parent 9f104ae commit 1a78afe

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

ci/steps/steps-lib.sh

+10
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,13 @@ directory_exists() {
2525
echo 1
2626
fi
2727
}
28+
29+
# Checks whether a file exists.
30+
file_exists() {
31+
local file="${1:-}"
32+
if test -f "${file:-}"; then
33+
echo 0
34+
else
35+
echo 1
36+
fi
37+
}

test/scripts/steps-lib.bats

+10
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@ source "$SCRIPT"
2323
@test "directory_exists should 0 if directory exists" {
2424
run directory_exists "$(pwd)"
2525
[ "$output" = 0 ]
26+
}
27+
28+
@test "file_exists should 1 if file doesn't exist" {
29+
run file_exists "hello-asfd.sh"
30+
[ "$output" = 1 ]
31+
}
32+
33+
@test "file_exists should 0 if file exists" {
34+
run file_exists "steps-lib.bats"
35+
[ "$output" = 0 ]
2636
}

0 commit comments

Comments
 (0)