brew log
Picking up where I left off (way back in this post)… here’s a discussion of the test coverage I added for brew log
.
Like brew home
, brew log
can be run with or without arguments. When run without any arguments, brew log
is akin to running git log
on the Homebrew repository, i.e., it returns the commit history of the entire Git repository. When run with an argument in the form of a formula’s name, e.g., brew log ack
, it returns the commit history for that formula.
My pull request for brew log
proved more challenging than its 33 lines of code and existing 75% test coverage lead me to believe.
As shown above, the previously existing test does all these things:
- changes directory (
FileUtils.cd
) into the directory containing the Homebrew Git repository.- (from within this directory) calls
shutup
(defined inHomebrew/test/testing_env.rb
) to shut up or suppress output from the commands that are enclosed betweendo
andend
:- calls
system
"git","init"
, which runsgit init
in a subshell:git init
initializes an empty Git repo by creating a/.git
directory with various subdirectories and files.
- calls
system "git","commit"
, which runsgit commit
in a subshell:git commit
records a commit that includes no new changes from its parent commit (which is allowed when--allow-empty
is passed), and uses the commit message,"This is a test commit"
.
- calls
- (from within this directory) calls
-
makes the assertion (with
assert_match
) that the recorded commit message is output whenbrew log
is run. - ensures (with
ensure
) the removal of the/.git
directory at the end of the test.
In my pull request, I aimed to add coverage for the behavior that brew log
exhibits when it’s called on a formula file or a shallow clone. My pull request broke a few things (oops) that were soon rectified by Martin’s follow-up PR (yay).
Here’s the incarnation of test_log_formula
that emerged (and was soon updated again with the refactoring of the integration tests file):
test_log_formula
does these things:
-
creates a
testball.rb
formula file in theHomebrew/homebrew-core
tap. - changes directory (
core_tap.path.cd
) into the directory containing theHomebrew/homebrew-core
tap, which is/usr/local/Library/Taps/homebrew/homebrew-core
.- (from within this directory) calls
shutup
and:- initializes an empty Git repo;
- adds all new or modified files to the index, which holds a snapshot of the repo’s current content; and
- records a commit and commit message.
- (from within this directory) calls
-
creates a
core_tap_url
variable and sets it equal to a string containing the file URI-formatted path to theHomebrew/homebrew-core
tap. -
creates a
shallow_tap
variable and sets it equal to a newly instantiatedTap
(namedHomebrew/homebrew-shallow
). - calls
shutup
and:- makes a shallow Git clone (
--depth=1
) of theHomebrew/homebrew-core
repo into the location whereHomebrew/homebrew-shallow
resides.
- makes a shallow Git clone (
-
makes a couple of assertions.
- ensures that all newly created files and directories are removed at the end of the test.
There you have it!