tester icon indicating copy to clipboard operation
tester copied to clipboard

add global function test()

Open dg opened this issue 5 years ago • 5 comments

This is similar to the test() function, which is actually used by all Nette libraries. In addition, the test name is passed to the function and it lists results.

image (https://github.com/nette/utils/blob/be6f0157dbb500c90ad0762a32a0681e087a6be3/tests/Utils/Arrays.insertBefore().phpt#L24-L72)

It also adds the beforeEach() and afterEach() functions.

What to consider

  • The function is only created if it does not exist, which should prevent collisions. Maybe it could be controlled in any other way.
  • switch whether to continue to the next test() function if assertion fails
  • switch to turn off output
  • output directly to STDOUT, so it cannot then be controlled by an output buffer
  • consider using the TestCase for before/after execution, similary to setUp/tearDown

dg avatar Aug 16 '20 15:08 dg

Uff, sorry, I just wated to send comment, not to start review. Just clicked the first green button I saw :)

milo avatar Feb 01 '21 08:02 milo

I'm in 👍

I proposed similar thing, Assert::block(callable ...), in the past, but I cannot find it now. And I can't recall why we didn't use it :o)

milo avatar Feb 01 '21 08:02 milo

switch to turn off output

I think this can be controlled by the same option as color output is.

milo avatar Feb 01 '21 08:02 milo

The function is only created if it does not exist, which should prevent collisions. Maybe it could be controlled in any other way.

Just thinking a loud... What about to do not load it in Environment::setup() but let user call explicitly Envitonemt::setupFunctions()? When comparing to Tracy's dump(), it just works fine without conflict, but dump() calls do not remain in code. On the other hand, tests are not prouduction evironment as well, so probably detection is OK.

milo avatar Feb 01 '21 08:02 milo

switch whether to continue to the next test() function if assertion fails

Something like deferred fail?

Maybe always when run directly by php test.phpt and not by Runner?

milo avatar Feb 01 '21 08:02 milo