Commit graph

25 commits

Author SHA1 Message Date
Paul Duffin
85034e92b6 Add FixtureIgnoreErrors
Bug: 182885307
Test: m nothing
Change-Id: Ib7e70b624db2f70374b755e97757ed21462b485a
2021-03-17 16:18:17 +00:00
Paul Duffin
50deaae872 Add OptionalFixturePreparer
Sometimes it is necessary to optionally add a preparer. e.g. There are
many parameterized tests where one of the parameters is some additional
test setup but not every test provides it so it will default to the
"zero" value of whatever type is used for the test setup parameter
Migrating those tests to use test fixtures will typically require that
the test setup parameter be changed to a FixturePreparer, which by
default will be nil.

Attempting to use a nil FixturePreparer in the test fixtures will fail
so the OptionalFixturePreparer was added to wrap a possibly nil
FixturePreparer and thereby avoiding complicating each test with
similar logic.

Bug: 182885307
Test: m nothing
Change-Id: Ia12b2af2105fdc69af4e0b909a37a7b86f1af299
2021-03-17 16:10:56 +00:00
Paul Duffin
dff5ff064e Use test specific build dir when needed
If a FixtureFactory was created with a nil buildDirSupplier then this
change will cause it to create a test specific directory instead. This
will allow packages whose tests have been fully converted to the test
fixture model to remove the need for the package level buildDir
variable.

Bug: 182885307
Test: m nothing
Change-Id: Ifa70acadbd90356fadbe39675bac3214d925aa2f
2021-03-16 12:35:04 +00:00
Paul Duffin
d7aea1dbe5 Remove TestHelper
Bug: 181070625
Test: m nothing
Change-Id: Idc39c8621424e25c1b4310c72ed2943d34a66bbc
2021-03-13 16:02:30 +00:00
Paul Duffin
c81854a642 Stop error handler relying on testing.T being embedded in TestResult
This change is in preparation for removing testing.T from TestResult.

Bug: 181070625
Test: m nothing
Change-Id: Iac627cc3c9f922ec4a41ce657442e4139fe7defb
2021-03-13 16:00:51 +00:00
Paul Duffin
e84b1338c5 Migrate from result methods to function Asserts
Bug: 181070625
Test: m nothing
Change-Id: Iadb85270290acb52c55f2ad70c9f145f1c34b611
2021-03-12 22:24:51 +00:00
Paul Duffin
0550055007 Separate TestHelper from fixtures
Although they are intended to be used together they are separate pieces
of functionality so should be separate.

Bug: 181070625
Test: m nothing
Change-Id: I3b2ccf66748a3c53b63c112256a8eb20e0448179
2021-03-12 14:25:33 +00:00
Paul Duffin
3fdb1bd9a2 Remove unused TestResult methods
Left over from a previous incarnation of the fixture mechanism.

Bug: 181070625
Test: m nothing
Change-Id: Ifb3811b7b030613cbff93994f7d370d402b1e73d
2021-03-12 14:25:33 +00:00
Paul Duffin
6e9a4007b5 Prevent mock filesystem files being overridden by accident
Bug: 181070625
Test: m nothing
Change-Id: Ib12b5cbe9af980706620d7d7d85bcfe31f36b07f
2021-03-11 19:21:12 +00:00
Paul Duffin
1ef166e411 Correct error in documentation of AssertDeepEquals
Bug: 181070625
Test: m nothing
Change-Id: Ie9bb46a7c29e800822d4bc67b23a457e17e5e29a
2021-03-11 14:34:10 +00:00
Paul Duffin
93706aeef2 Add AssertStringListContains to TestHelper
Bug: 181070625
Test: m nothing
Change-Id: I5b36b748a2f0b7c189aa9e12cf0ad0f663c92a9a
2021-03-11 07:26:19 +00:00
Paul Duffin
67e848ab04 Merge changes Ib2c6ac28,I7c76ed6d,I00415f10,I4be2a16c,I6f269c9c, ...
* changes:
  Support test fixtures in sh package
  Support test fixtures in bpf package
  Support test fixtures in cc package
  Add temporary RunTestWithConfig method to simplify migration
  Support test fixtures in etc package
  Convert license tests to use test fixtures
2021-03-10 21:52:17 +00:00
Paul Duffin
3b2636fdf3 Merge "Remove duplicate sdk.TestHelper" 2021-03-10 19:59:56 +00:00
Paul Duffin
a3cb2b396f Remove duplicate sdk.TestHelper
As part of the work on the new fixture mechanism some of the TestHelper
functionality was moved into the android/fixture.go package. This moves
the rest and removes the now duplicated TestHelper from the sdk
package.

Also removed some unnecessary & operators.

Bug: 181070625
Test: m nothing
Change-Id: Ia09a5d05e4fab3a4e28cf44b2d947a33541e3925
2021-03-10 14:07:20 +00:00
Paul Duffin
72018ad136 Add temporary RunTestWithConfig method to simplify migration
Bug: 181070625
Test: m nothing
Change-Id: I4be2a16cff750bbe05010ff427cec1831e260267
2021-03-09 23:06:00 +00:00
Paul Duffin
46e37741a9 Rename SetErrorHandler to ExtendWithErrorHandler
Bug: 181070625
Test: m nothing
Change-Id: Iacab525cb47fbd7ff54e5a95ec230ac6c71f20eb
2021-03-09 14:14:48 +00:00
Paul Duffin
2e0323dd1b Allow customization of product variables in a test fixture
Adds FixtureModifyProductVariables.

Bug: 181070625
Test: m nothing
Change-Id: Iad7e125ed722d99dc1e62479b04b625075b89d58
2021-03-09 14:14:48 +00:00
Paul Duffin
bbccfcfb70 Allow customization of the env configuration in a test fixture
Adds FixtureModifyEnv and FixtureMergeEnv.

Bug: 181070625
Test: m nothing
Change-Id: I1b6eb88907efa2476d96912961fea2df2d902659
2021-03-09 14:14:48 +00:00
Paul Duffin
fa29885380 Avoid accidentally sharing preparers slice across factories
Previously, there was a bug that caused tests which ran successfully on
their own to fail when run together in parallel. They each extended the
same factory and ended up sharing the preparers slice which meant that
they overwrote each other's preparers causing the tests to fail.

This change fixes that by creating a new slice for each factory.

Bug: 181070625
Test: m nothing
Change-Id: If340c125c5b03a9d5c36a59ff4da4ec189808f9b
2021-03-08 22:45:09 +00:00
Paul Duffin
942481b3f5 Add Errs to TestResult
Makes the error handler a little cleaner.

Bug: 181070625
Test: m nothing
Change-Id: I0f9050a98346d7d214eed570957d9810aaf26def
2021-03-05 18:20:33 +00:00
Paul Duffin
ea8a386346 Make error handlers treat any failures as fatal
A lot of existing tests that expect errors to be reported do not check
the returned result. This change treats failures of the error handler
in that situation as fatal.

The default error handler already behaved that way. The others did not.

FixtureExpectsAllErrorsToMatchAPattern uses
CheckErrorsAgainstExpectations and it was safe to just make that func
treat any unmatching errors as fatal as all the existing usages are at
the end of test functions.

FixtureExpectsAtLeastOneErrorMatchingPattern uses the
FailIfNoMatchingErrors function which is used in a number of places
(including CheckErrorsAgainstExpectations) that do not want to treat
a test failure as fatal. So, that was modified to return false if no
matching error was found and the error handler treated that as fatal.

Bug: 181070625
Test: m nothing
Change-Id: I6e4df53f93250348bc050d4ff098134e6314ae30
2021-03-05 18:20:33 +00:00
Paul Duffin
52323b5113 Avoid SetErrorHandler mutating FixtureFactory
A FixtureFactory is supposed to be immutable to allow them to be safely
shared but unfortunately the implementation of SetErrorHandler broke
that constraint. That made it very easy to mistakenly add an error
handler specific to a test to a shared factory breaking other tests
that use that factory.

This change causes SetErrorHandler to create a new instance of the
factory to avoid that.

Bug: 181070625
Test: m nothing
Change-Id: Ia5356a04189099c88880a2a521af29ab72560f30
2021-03-05 18:20:33 +00:00
Paul Duffin
a560d5a91d Rename FixturePreparers to GroupFixturePreparers
FixturePreparers is a bad name for a method that creates a collection
of FixturePreparers for a couple of reasons:
* Conventionally it would be used as the name for []FixturePreparer if
  it is necessary to add behavior to that.
* There are many different types of collection, particularly when order
  matters.

Bug: 181070625
Test: m nothing
Change-Id: I55394ff369375dcac2d7b72e4d803a4818762d36
2021-03-05 18:20:33 +00:00
Paul Duffin
cfd3374da0 Add error handling to test fixtures
Adds support for customizing the error handling behavior of test
fixtures and converts a test to use it.

Bug: 181070625
Test: m nothing
Change-Id: I736c41311819d57d8688fc3b0e021dbb50c491c1
2021-03-02 20:17:19 +00:00
Paul Duffin
358161232c Add test fixture support
Adds the test fixture support and converts a few tests to exercise the
code and show how it works.

Bug: 181070625
Test: m nothing
Change-Id: I0a2b40fff93b6041f9aa8c4ef0aba91da1bc8bf3
2021-02-26 23:01:50 +00:00