mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Document how to use test fixtures
This commit is contained in:
parent
fa980e9c42
commit
67ff3c53fe
@ -278,6 +278,20 @@ Some advice for specific cases:
|
|||||||
A good example is [`tinyxml2`](https://github.com/Homebrew/homebrew-core/blob/master/Formula/tinyxml2.rb), which writes a small C++ source file into the test directory, compiles and links it against the tinyxml2 library and finally checks that the resulting program runs successfully.
|
A good example is [`tinyxml2`](https://github.com/Homebrew/homebrew-core/blob/master/Formula/tinyxml2.rb), which writes a small C++ source file into the test directory, compiles and links it against the tinyxml2 library and finally checks that the resulting program runs successfully.
|
||||||
* If the formula is for a GUI program, try to find some function that runs as command-line only, like a format conversion, reading or displaying a config file, etc.
|
* If the formula is for a GUI program, try to find some function that runs as command-line only, like a format conversion, reading or displaying a config file, etc.
|
||||||
* If the software cannot function without credentials or requires a virtual machine, docker instance, etc. to run, a test could be to try to connect with invalid credentials (or without credentials) and confirm that it fails as expected.
|
* If the software cannot function without credentials or requires a virtual machine, docker instance, etc. to run, a test could be to try to connect with invalid credentials (or without credentials) and confirm that it fails as expected.
|
||||||
|
* Homebrew comes with a number of [standard test fixtures](https://github.com/Homebrew/brew/tree/master/Library/Homebrew/test/support/fixtures), including numerous sample images, sounds, and documents in various formats. You can get the file path to a test fixture with `test_fixtures("test.svg")`.
|
||||||
|
* If your test requires a test file that isn't a standard test fixture, you can install it from a source repository during the `test` phase with a resource block, like this:
|
||||||
|
```ruby
|
||||||
|
resource("testdata") do
|
||||||
|
url "https://example.com/input.foo"
|
||||||
|
sha256 "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
||||||
|
end
|
||||||
|
|
||||||
|
test do
|
||||||
|
resource("testdata").stage do
|
||||||
|
assert_match "OK", shell_output("#{bin}/foo build-foo input.foo")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
### Manuals
|
### Manuals
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user