Package testing; setup and teardown

I have a package that wraps a vendor library. There is one main object that is exposed (a simulator) and the changeable parts are all available by performing functions on the main object, made to look C++ ish with getproperty.

I’d like to have some testing workflow like this:

m = MainApp()
m.Init("simulator_setup.ini")

v = m.GetViewer()
# ... test the viewer

m = nothing # set the main thing up for garbage collection

# now start on next thing
m = MainApp()
m.Init("different_setup.ini")

b = m.SomeOtherSubsystem()
# ... test the subsystem
# ... etc., etc

I have seen a suggestion here that recommends using do blocks. I can see how that would get me test setup, but I can’t see how that would get me test teardown. What I was hoping for was something like dynamic-wind in Racket … i.e., setup runs, my test runs, then teardown runs.

Perhaps this is already possible and easy in Julia, but I just haven’t figured it out yet?

I didn’t really get what your question is. The thread you linked seems to demonstrate the use of do blocks quite nicely and your code example could be rephrased rather easily like so

function mytest(testcode, setupfile)
    m = MainApp()
    m.Init(setupfile)
    try
        testcode(m)
    finally
        # do cleanup
        # not cleanup present in your example
    end
end

mytest("simulator_setup.ini") do m
    v = m.GetViewer()
    # ... test the viewer
end

mytest("different_setup.ini") do m
    b = m.SomeOtherSubsystem()
    # ... test the subsystem
end

dynamic-wind gives quite different features which aren’t needed in Julia due to the lack of continuations (I think, I am not an expert with continuations or Racket).