Access to downloadable files in the test block of the formula

I am creating a Homebrew formula for the C library, which includes its own test suite. As part of the test block for the formula, I would like to run the tests that are included in the downloaded files. Testing is done as a make ( make test ) target. However, the Homebrew test blocks run in their own temporary directory, and the downloaded files are not in the path. That is, the following does not work because it cannot find the files:

 test do system "make", "test" end 

How can I access the location where the files were originally downloaded and unpacked? I could not find information about this in the docs. Or is there a better solution for Homebrew tests in this case?

+7
ruby homebrew
source share
1 answer

The test do block is designed to verify that the formula is set correctly, and not to run test samples. If the tests do not take too long, you can run them as part of the installation:

 def install # ... system "make", "test" # ... end 

To answer your question, there is no reliable way to get the original unpacked directory, because it was destroyed after installation, and the user may have deleted the cached tarball (e.g. brew cleanup ), so you have to reload it.

The solution is to copy the necessary test files somewhere during the install step, then use them directly or copy them in the current directory during testing, for example:

 def install # ... libexec.install "tests" end test do cp_r (libexec/"tests"), "." cd "tests" do # I'm assuming the Makefile paths can be given # as variables here. system "make", "test", "LIB=#{lib}", "INCLUDE=#{include}" end end 
+1
source share

All Articles