Commit Graph

89 Commits (master)

Author SHA1 Message Date
Oleksandr Redko 014ae9a7a4 Replace deprecated io/ioutil with io and os 2024-12-10 14:21:03 +02:00
Bracken f2227519d6
Merge branch 'master' into fix/suite-test-failures 2024-10-06 16:48:07 +01:00
Bracken Dawson fed9ee68dc Document suite's lack of support for t.Parallel 2024-10-04 12:24:15 +02:00
Steven Hartland e943930404 fix(suite): test failures
Fix TestFailfastSuite when run with go test flag -count=X where X
greater than 1.
2024-09-09 10:09:18 +01:00
ccoVeille 85d8bb6eea
fix typos in comments, tests and github templates 2024-02-24 23:48:24 +01:00
Arjun Mahishi c41592ba5f suite: fix deadlock in suite.Require()/Assert()
As pointed out in issue #1520, if the suite is not initialised properly
(buy calling the Run function), then calling suite.Require() or
suite.Assert() will result in a deadlock.

This commit fixes that by panicking if the suite is not initialised
properly. This is justified because, the suite is intended to be
triggered in the right way. If the user does not do that, this panic will
nudge them in the right direction.

It has to be a panic because, at this point, we don't have access to any
testing.T context to gracefully call a t.Fail(). Also, these two
functions are not expected to return an error.

Fixes #1520
2024-02-18 23:55:01 +05:30
Olivier Mengué 2be68b5e9e suite: fix recoverAndFailOnPanic to report at the right location
Add calls to t.Helper() to fix the location where the panic is reported
as a test failure.
2024-01-31 16:01:43 +01:00
Olivier Mengué db8608ed63
suite: fix subtest names (fix #1501) (#1504)
* suite: fix TestSubtestPanic failure (#1501)

The subtest of TestSubtestPanic is expected to fail, but that must not
make the testuite of package 'suite' to fail. So call Skip to make 'go
test' to ignore that expected failure.

* suite: fix subtests names

We are doing dirty things with testing.InternalTest. It looks like test
names should have the same prefix as the parent test, like if they were
true subtests (testing.T.Run).

So until we drop our usage of testing.InternamTest, let's rename the
tests.

Also added a few checks of the testing.RunTests result.
2023-11-09 10:44:27 +10:00
Linus Barth 7df1a82a31 test: add suite tests for panicking of subtests 2023-10-30 22:51:08 +01:00
Linus Barth a4a54a4597 fix: panic behavior for subtests
This fix adds panic handling for subtests which will achieve:
- subtests will fail for the correct test context when panicking
- the test execution is not stopped; the next subtest will be executed
2023-10-30 22:51:08 +01:00
Linus Barth 65318c364a improve: tests for asserting test names in subtests 2023-10-30 22:51:08 +01:00
Linus Barth 130d340262 improve: move comment to msgAndArgs-param in test 2023-10-30 22:51:08 +01:00
Linus Barth 855d1c6784 test: testing.T correctness in subtests setup/teardown 2023-10-30 22:51:08 +01:00
Linus Barth 82022eeb0d test: call order of setup/teardown for subtests 2023-10-30 22:51:08 +01:00
Linus Barth 4526456fa4 improve: defer-style in Suite.Run() 2023-10-30 22:51:08 +01:00
Linus Barth 737a765d89 fix: SetupSubTest and TearDownSubTest execution order
There were two problems with the order of execution in the Suite.Run() method:
- One could not access the correct testing context ("s.T()") inside the SetupSubTest and TearDownSubTest methods. If the testing context was used for e.g. assertions of mocks in the TearDownSubTest, the results would not be "attached" to the correct test in the test output.
- The behavior was different to the order of execution for "root" tests (see lines 167-201) regarding the SetupTest and TearDownTest methods. This could confuse users of the library.

Also the logic to be deferred was joined together. This was fine beforehand because a panic in the TearDownSubTest would have had no influence on the "suite.SetT(oldT)". Now since a panic in the TearDownSubTest would lead to omitting the "suite.SetT(oldT)" this defer was split into two separate defers.
2023-10-30 22:51:08 +01:00
Oleksandr Redko 351d2776c6 Revert some changes 2023-10-30 22:41:11 +01:00
Oleksandr Redko 375474cd3c suite: refactor test assertions 2023-10-30 22:41:11 +01:00
Harald Nordgren 4c93d8f201
EqualExportedValues: Handle nested pointer, slice and map fields (#1379)
* EqualExportedValues: Handle pointer and slice fields

* Update assert/assertions.go

Co-authored-by: Michael Pu <michael.pu123@gmail.com>

* Reduce redundant calls to 'copyExportedFields'

* Update comments

* Add support for maps

* Update Go version support to 1.19 and onward

* Re-generate after rebasing

---------

Co-authored-by: Michael Pu <michael.pu123@gmail.com>
2023-05-11 07:42:04 +10:00
Vadym Tishchenko 1333b5d3bd
Add sub-tests to Suite (#1246)
Co-authored-by: Vadym Tishchenko <v.tishchenko@evopay.com.ua>
2022-11-02 21:46:59 +10:00
nicoche 1b73601ae8
suite: correctly set stats on test panic (#1195) 2022-06-23 19:40:15 +10:00
Weizhen Wang 106ec21d14 use RWMutex
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
2022-05-04 20:46:29 +10:00
Weizhen Wang a409ccf19e fix data race in the suit
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
2022-05-04 20:46:29 +10:00
ariley d76ac5e41f Fix comment 2020-05-05 08:16:34 +10:00
ariley 1bbde5e52a Change Require to Error 2020-05-05 08:16:34 +10:00
ariley f96052c82a Remove 1.8 and 1.9 tests. Updated failfast test 2020-05-05 08:16:34 +10:00
ariley 93bea66f75 Added TestSuiteWithFailfast 2020-05-05 08:16:34 +10:00
ariley cd58006fe6 Change how tearDownAllSuite is run to aviod deadlock when running with failfast 2020-05-05 08:16:34 +10:00
ariley 097ec799df Change how tearDownAllSuite is run to aviod deadlock when running with failfast 2020-05-05 08:16:34 +10:00
Boyan 2566b66989 Resolve conflicts 2020-04-24 07:38:44 +10:00
Aaron N. Brock f238e4b70a Move teardown defers to before setup 2020-04-24 07:38:44 +10:00
ariley f43aa3c488 Change to guard clause 2020-04-23 15:52:53 +02:00
ariley a41f2db807 Add warning in log when no tests are run within a suite 2020-04-23 15:52:53 +02:00
Esdras Beleza de Noronha 961bfee4b1 Add function to return if all tests in a suite passed 2020-03-11 19:42:32 +11:00
Esdras Beleza de Noronha f37e428318 Use comma ok idiom 2020-03-11 19:42:32 +11:00
Esdras Beleza de Noronha 89909913cc Fix var block with only one variable 2020-03-11 19:42:32 +11:00
Esdras Beleza de Noronha 9feda7c901 Change imports for consistency 2020-03-11 19:42:32 +11:00
Esdras Beleza de Noronha fdf3f01101 Update documentation 2020-03-11 19:42:32 +11:00
Esdras Beleza e8910bb335 Add stats to suites and tests 2020-03-11 19:42:32 +11:00
Boyan 3ebf1ddaeb Revert PR #867 2020-02-20 07:56:11 +11:00
Corey McGregor 624f997379 fix(suite): Add Fatalf method to suite.TestingT for gomock compatibility 2020-02-19 07:05:10 +11:00
Boyan Soubachov 55d8b5740c Add interface tests for suite.T 2020-02-06 07:41:25 +11:00
Chris K 9dfcf7c562 suite: make suite.TestingT satisfy mock.TestingT
...by adding Logf method.
2020-02-05 20:52:22 +11:00
Keynan Pratt ea72eb9159 added Log/Skip methods as required by CI tests 2020-01-29 11:08:28 +11:00
Keynan Pratt dca7be2281 updated TestingSuite interface to use TestingT 2020-01-29 11:08:28 +11:00
Keynan Pratt d3e61647c0 removed Helper method from TestingT interface 2020-01-29 11:08:28 +11:00
Keynan Pratt 045d838faf changed dependency to interface, s.t. consumers can easily mock the testing.T type 2020-01-29 11:08:28 +11:00
devdinu 3c60a0e014 Merging suite_order_test in suite test, removing anonymous defer func call 2020-01-16 14:06:22 +11:00
Dinesh Kumar e7b6c14305 Remove parallel as that makes goroutines deadlock 2020-01-16 14:06:22 +11:00
Dinesh Kumar 0d3c8ce9f8 fixing suite teardown ordering issue
(cherry picked from commit 92c097a5af7b4bbbe3a66c2e7484f68194cd555a)
2020-01-16 14:06:22 +11:00