-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib/path: Add @go.add_parent_dir_if_relative_path
The need for this became apparent while creating the upcoming `@go.copy_files_safely`.
- Loading branch information
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#! /usr/bin/env bats | ||
|
||
load ../environment | ||
|
||
setup() { | ||
test_filter | ||
@go.create_test_go_script \ | ||
'. "$_GO_USE_MODULES" "path"' \ | ||
'declare result' \ | ||
'@go.add_parent_dir_if_relative_path "$@"' \ | ||
'printf "%s\n" "$result"' | ||
} | ||
|
||
teardown() { | ||
@go.remove_test_go_rootdir | ||
} | ||
|
||
@test "$SUITE: converts a relative path to an absolute path based on PWD" { | ||
run "$TEST_GO_SCRIPT" 'result' 'foo' | ||
assert_success "$TEST_GO_ROOTDIR/foo" | ||
} | ||
|
||
@test "$SUITE: adds a parent to a relative path" { | ||
run "$TEST_GO_SCRIPT" --parent 'foo' 'result' 'bar' | ||
assert_success 'foo/bar' | ||
} | ||
|
||
@test "$SUITE: leaves an absolute path unmodified" { | ||
run "$TEST_GO_SCRIPT" --parent 'foo' 'result' '/bar/baz' | ||
assert_success '/bar/baz' | ||
} |