brew
https://github.com/homebrew/brew
Ruby
🍺 The missing package manager for macOS
Formula.test
Test (is required for new formula and makes us happy).
The block will create, run in and delete a temporary directory.
We are fine if the executable does not error out, so we know linking
and building the software was ok.
<pre>system bin/"foobar", "--version"</pre>
<pre>(testpath/"test.file").write <<-EOS.undent
writing some test file, if you need to
EOS
assert_equal "OK", shell_output("test_command test.file").strip</pre>
Need complete control over stdin, stdout?
<pre>require "open3"
Open3.popen3("#{bin}/example", "argument") do |stdin, stdout, _|
stdin.write("some text")
stdin.close
assert_equal "result", stdout.read
end</pre>
The test will fail if it returns false, or if an exception is raised.
Failed assertions and failed `system` commands will raise exceptions.Edit
git clone [email protected]:homebrew/brew.git
cd brew
open Library/Homebrew/formula.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-Formula-test-for-pr
# Commit to gitgit add Library/Homebrew/formula.rbgit commit -m "better docs for Formula.test"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-Formula-test-for-pr
hub pull-request
# Celebrate!