Simple debugging: @testset, @debug, @assert

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 @test and @debug capabilities.]

  1. I sometimes want to carry out an “expensive” test:
@testset begin
  for i in 1:n
     somevalue = func_of(i)
    @test arr[i] == somevalue

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.

  1. Debug print: I guess @debug is 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.

2.2: Is @debug totally independent of the Test package so that you need to control @test and @debug separately?

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)"
  1. Is @assert redundant once you start to use @test? I’ve just started to explore @test and @debug. I’ve been using @assert for a long time but @assert doesn’t have a capability corresponding to @testset, so perhaps I should entirely migrate to the Test package . . . ?

Perhaps this is of interest for you GitHub - MasonProtter/ToggleableAsserts.jl: Assertions that can be turned on or off with a switch, with no runtime penalty when they're off.