[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Sourcing global variables in unit tests
From: |
Pavel Hofman |
Subject: |
Sourcing global variables in unit tests |
Date: |
Mon, 15 Apr 2019 18:29:44 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 |
Hi,
Please is there any way to source a script defining global variables in
unit test (%!test) and have these available in functions called within
the test?
This works:
%!test
%! global dataDir = '/tmp';
%! func_using_global_dataDir();
But this does not work, dataDir is not available in
func_using_global_dataDir():
%!test
%! source 'consts.m';
%! func_using_global_dataDir();
Where script consts.m contains
global dataDir = '/tmp';
Yet when consts.m is sourced from another script (in the main code, not
the unit script %! section), the global vars defined in consts.m are
available in the script as well as all functions called by the script.
Tested with Octave 4.2.2 in Linux.
Thanks a lot for any help or suggestion how to let a unit test
source/load a script with global constants used in functions tested by
that test. Otherwise the scope of unit tests would be severely limited
as all global variables (constants) used in the tested functions would
have to be redefined in the unit test.
With regards,
Pavel.
- Sourcing global variables in unit tests,
Pavel Hofman <=