Use Test::Tap as a TAP testing base for Bash
masterprove utility. It serves as the foundation for test-more-bash.repository·master·Indexed 25 days ago
https://github.com/ingydotnet/git-subrepoA Git submodule alternative that allows cloning external repositories into subdirectories. It simplifies dependency management by squashing upstream history into single commits in the mainline while allowing collaborators to push and pull changes back to original remotes. The repository also includes Bash+ (a library for enhancing Bash programming) and Test::More/Test::Tap (TAP testing frameworks for Bash).
prove utility. It serves as the foundation for test-more-bash.Upgrade the git-subrepo software.
If you installed via the .rc file or by modifying your PATH, run:
git subrepo upgradeAlternatively, you can manually pull the latest code from the git-subrepo repository:
cd /path/to/git-subrepo
git pullIf you used make install, you must run make install again after performing a git pull on the source repository.
git subrepo upgradeTo use Test::Tap in your Bash tests, you must first source the tap.bash file. You must also call Test::Tap:init at the beginning of every test file or process.
source test/tap.bash
# Must be called first
Test::Tap:initAdd an external repository as a subrepo in a subdirectory of your current repository. This command fetches the remote repo and merges it into the specified subdirectory. The subrepo history is squashed into a single commit, and a .gitrepo file is created in the subdirectory to track reference information.
Usage:
git subrepo clone <remote-url> [<subdir>] [-b <branch>] [-f] [-m <msg>] [--file=<msg file>] [-e] [--method <merge|rebase>]
Options:
-b <branch>: Specify a branch name.-f (--force): Reclone (completely replace) an existing subdirectory.-m <msg>: Specify a commit message.--file=<msg file>: Use a file for the commit message.-e (--edit): Edit the commit message before committing.--method <merge|rebase>: Decide how the join process is performed (default is merge).Bash+ is a collection of libraries designed to enhance Bash programming. To install it, clone the repository and use the provided Makefile.
git clone git@github.com:ingydotnet/bashplusmake testsudo depending on your permissions):
make installgit clone git@github.com:ingydotnet/bashplus
make test
make installsource /etc/bash_completion.d/git).git-subrepo completion script:source /path/to/git-subrepo/share/completion.bashAdd the completion directory to your fpath in ~/.zshrc before the compinit function is called:
fpath=('/path/to/git-subrepo/share/zsh-completion' $fpath)Bash+ extends standard Bash by providing libraries for improved programming ergonomics. You can source standard libraries like :std and :array, and use the use keyword to import specific modules. Once imported, module methods can be called using object-oriented syntax (e.g., Module::Name.method).
source bash+ :std :array
use Foo::Bar this that
Array.new args "$@"
if args.empty?; then
die "I need args!"
fi
Foo::Bar.new foo args
this is awesomeYou can install git-subrepo using one of three methods. All methods require first cloning the repository:
git clone https://github.com/ingydotnet/git-subrepo /path/to/git-subrepoAdd the following line to your shell startup script (e.g., ~/.bashrc). This modifies your PATH and MANPATH and enables command completion:
source /path/to/git-subrepo/.rcManually add the lib and man directories to your environment:
export GIT_SUBREPO_ROOT="/path/to/git-subrepo"
export PATH="/path/to/git-subrepo/lib:$PATH"
export MANPATH="/path/to/git-subrepo/man:$MANPATH"Use make install to place the command next to your other git commands. Note that this method does not support the upgrade command or automatic command completion.
make installRequirements: Requires Git version >= 2.23.
git clone https://github.com/ingydotnet/git-subrepo /path/to/git-subrepo
echo 'source /path/to/git-subrepo/.rc' >> ~/.bashrcTo use Test::More in a Bash script, ensure your script uses the #!/usr/bin/env bash hashbang. You must set up the PATH to include the bin and lib directories of the test-more-bash installation and source the library.
Example test file structure:
#!/usr/bin/env bash
# Set up paths to the test-more-bash installation
TEST_MORE_PATH="/path/to/test-more-bash"
BASHLIB=`find $TEST_MORE_PATH -type d | grep -E /(bin|lib)$ | xargs -n1 printf "%s:"`
PATH="$BASHLIB$PATH"
# Load the library
source bash+ :std
use Test::More
# Define how many tests to expect
plan tests 8
# Example test cases
some-command
ok $? "some-command is ok"
pass "This will always pass"
fail "This will always fail"
is `echo foo` "foo" "foo is foo"
isnt foo bar "foo isnt bar"
like food "foo" "food is like foo"
unlike team "foo" "There's no foo in team"
# Diagnostic and notes
diag "A message for stderr"
note "A message for stdout"
# Array comparison
output=( $(ls) )
expected=(README lib bin)
cmp-array output expected "list files"To use the Bash+ framework within a Bash script, you must source the file rather than executing it as a standalone command. This loads the library functions into your current shell environment.
source bash+Remove temporary artifacts created by fetch and branch commands (such as temporary refs, branches, and remotes).
Usage:
git subrepo clean <subdir>|--all|--ALL [-f]
Options:
--all: Clean up after all current subrepos.--ALL: Remove any artifacts that were ever created by subrepo (even if the subrepo no longer exists in the current branch).-f (--force): Force removal of refs.Bash+ provides several ways to import functionality and use enhanced syntax for arrays and object-like structures.
You can source specific libraries using the source command with colon-separated names:
source bash+ :std :arrayAlternatively, you can use the use keyword for module-style imports:
use Foo::Bar this thatBash+ introduces patterns for handling arguments and creating new objects:
Array.new args "$@"if args.empty?; then ... fiFoo::Bar.new foo argsthis is awesome).source bash+ :std :array
use Foo::Bar this that
Array.new args "$@"
if args.empty?; then
die "I need args!"
fi
Foo::Bar.new foo args
this is awesome