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.

Source | Google | Stack overflow

Edit

git clone [email protected]:homebrew/brew.git

cd brew

open Library/Homebrew/formula.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-Formula-test-for-pr


# Commit to git

git add Library/Homebrew/formula.rbgit commit -m "better docs for Formula.test"


# Open pull request

gem 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!