Happy new year to everyone!
I have two technical questions I couldn’t find a solution for myself and I hope you can help me out.
Background: I want to “mock” a Natural module at runtime. A module “A” calls another module “B”, which accesses the database. I would like to test module “A” without it calling “B” and therefore accessing the database. I could pass a parameter with the module name to call to “A” (e.g. #P-TO-CALL and then do a CALLNAT #P-TO-CALL), but that means I would have to change “A”'s interface (add a parameter to “A”), which I don’t want. Furthermore, this technique would only work for subprograms and not for external subroutines, as dynamically calling a subroutine from a variable name is not possible (at least as far as I know).
So, I would like to be able to have “A” call “B” in production code and a mocked/fake/stub version of “B” that returns well-known values in test code. All from within a running Natural session. Finally, here are my two questions:
Is it possible to manipulate the target of a CALLNAT/PERFORM at runtime, so that another module instead of the given one is called? Perhaps I could teach Natural to call “C” whenever “CALLNAT B” is executed. If so, my second question would perhaps be irrelevant.
Does anyone know if it is possible to compile Natural sources programmatically from within a running Natural session AND call the newly compiled module directly afterwards?
Because I have absolutely no idea whether 1) is possible, I experimented with 2) a bit and found two ways of creating, saving and stowing Natural modules at runtime: either by putting Natural commands like READ, SAVE and STOW on the stack myself (using STACK TOP COMMAND etc.) or by using the corresponding User Exits like USR0210N (“Save, catalog or stow Natural object”), which - as far as I understand them - are only wrappers around the manual stack commands themselves. I’ve managed to create a new module and stow it, but unfortunately it can’t be called from within the same Natural session, as the documentation for USR0210N states:
Any help on how to “mock” a Natural module at runtime would be much appreciated!
PS: I’ve managed to program a working solution for mocking a Natural module in our Linux environment, but it calls a Bash script, that starts a second Natural batch session for compiling the module to mock. However, this solution is too slow (about 1s per mock) for production use.