I want to insert simple test code here and there into my small programs and am wondering what the best practice is. [What I write below likely includes some error due to my misunderstanding. I’m struggling to understand the
- I sometimes want to carry out an “expensive” test:
@testset begin for i in 1:n somevalue = func_of(i) @test arr[i] == somevalue end end
I want to disable this code in my “production” runs because this test consumes some significant CPU time. Reading the official documentation of
Test, I haven’t been able to find the switch to disable the test code globally. I guess there is a global switch to disable all test code.
- Debug print: I guess
@debugis the way to go, but I have a few questions.
2.1: How to enable and disable the debug print globally? Again, the official documentation doesn’t include a simple example.
@debug totally independent of the
Test package so that you need to control
2.3: How to disable only the printout while still evaluating the expression? For example, this code
@debug readline(istream) # discard the line
doesn’t work. I always need to skip the line and I’d like to look at the skipped line when debugging my code, but
@debug disable the function call itself when not in the debugging mode. I guess there is a simple way to do this:
@evaluate_and_print_when_debugging begin some calculation "debug message: the calculated value is $(someval)" end
@assertredundant once you start to use
@test? I’ve just started to explore
@debug. I’ve been using
@assertfor a long time but
@assertdoesn’t have a capability corresponding to
@testset, so perhaps I should entirely migrate to the
Testpackage . . . ?