Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access downloaded files in a formula's test block

Tags:

homebrew

ruby

I'm creating a Homebrew formula for a C library that includes its own test suite. As part of the test block for the formula, I'd like to run the tests that are included with the downloaded files. The tests run as a make target (make test). However, Homebrew test blocks run in their own temporary directory and the downloaded files are not in the path. That is, the following doesn't work because it can't find the files:

test do
  system "make", "test"
end

How can I access the location into which the files were originally downloaded and unpacked? I haven't been able to find any information about that in the docs. Or is there a better solution for Homebrew tests in this case?

like image 843
Alex A. Avatar asked Jun 05 '16 05:06

Alex A.


People also ask

How do I Test my Web app’s file download functionality?

You can test your web app’s File Download functionality in an Automate session. This guide shows you how to: Download files on remote desktop instances. Verify that the file downloaded successfully.

How do I Block download only for office files?

If you're the Microsoft 365 admin in your organization, you can control whether Block download appears only for Office files or other supported files by changing the BlockDownloadLinksFileType setting in the Set-SPOTenant or Set-SPOSite PowerShell cmdlets (ServerRendered (Office Only) and WebPreviewable (All supported files).

How do I check if a file has been downloaded successfully?

BrowserStack has a custom browserstack_executor script. You can use this to check whether the file downloaded successfully in an Automate session. The fileExists function will return a boolean value as a response. Verify that a specific file was downloaded


1 Answers

The test do block is meant to test if a formula has correctly been installed, not to run test suits. If the tests don’t take too long you can run them as part of the install:

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

To answer your question there’s no reliable way to get the original unpacked directory because it’s destroyed after install and the user may have deleted the cached tarball (with e.g. brew cleanup) so you’d have to re-download it.

A solution is to copy the necessary test files somewhere during the install step then use them directly or copy them in the current directory when testing, e.g.:

def install
  # ...
  libexec.install "tests"
end

test do
  cp_r (libexec/"tests"), "."
  cd "tests" do
    # I’m assuming the Makefile's paths can be given
    # as variables here.
    system "make", "test", "LIB=#{lib}", "INCLUDE=#{include}"
  end
end
like image 56
bfontaine Avatar answered Nov 20 '22 22:11

bfontaine