LArSoft
v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
|
Environment for a test. More...
#include "unit_test_base.h"
Classes | |
struct | Options_t |
Test environment options. More... | |
Public Types | |
using | Configuration_t = ConfigurationClass |
Public Member Functions | |
BasicTesterEnvironment (bool bSetup=true) | |
Constructor: sets everything up and declares the test started. More... | |
virtual | ~BasicTesterEnvironment () |
Destructor: closing remarks. More... | |
BasicTesterEnvironment (Configuration_t const &configurer, bool bSetup=true) | |
Setup from a configuration. More... | |
BasicTesterEnvironment (Configuration_t &&configurer, bool bSetup=true) | |
Setup from a configuration. More... | |
Configuration retrieval | |
fhicl::ParameterSet const & | Parameters () const |
Returns the full configuration. More... | |
fhicl::ParameterSet | ServiceParameters (std::string service_name) const |
Returns the configuration of the specified service. More... | |
fhicl::ParameterSet | TesterParameters (std::string test_name) const |
Returns the configuration of the specified test. More... | |
fhicl::ParameterSet | TesterParameters () const |
Returns the configuration of the main test (undefined if no main test) More... | |
Static Public Member Functions | |
static fhicl::ParameterSet | CompileParameterSet (std::string cfg) |
Compiles a parameter set from a string. More... | |
Protected Member Functions | |
Configuration_t const & | Config () const |
Returns a read-only version of the configuration. More... | |
virtual void | Setup () |
The complete initialization, ran at construction by default. More... | |
virtual void | Configure () |
Reads and translates the configuration. More... | |
virtual fhicl::ParameterSet | DefaultParameters () const |
Creates a full configuration for the test. More... | |
virtual void | SetupMessageFacility (fhicl::ParameterSet const &pset, std::string appl_name="") const |
Sets up the message facility. More... | |
virtual void | SetupMessageFacility () const |
Sets up the message facility. More... | |
Static Protected Member Functions | |
static fhicl::ParameterSet | ParseParameters (std::string config_path) |
Fills the test configuration from file or from default. More... | |
Private Member Functions | |
void | ParseEnvironmentOptions () |
Parses the configuration, looking for the test environment options. More... | |
Private Attributes | |
Configuration_t | config |
instance of the configurer More... | |
Options_t | options |
options for the test environment More... | |
fhicl::ParameterSet | params |
full configuration of the test More... | |
Environment for a test.
ConfigurationClass | a class providing compile-time configuration |
The test environment is set up on construction.
The environment provides:
This class or a derived one can be used as global fixture for unit tests.
Unfortunately Boost does not give any control on the initialization of the object, so everything must be ready to go as hard coded. The ConfigurationClass class tries to alleviate that. That is another, small static class that BasicTesterEnvironment uses to get its parameters.
The requirements for the ConfigurationClass are:
std::string ApplicationName()
: the application namestd::string ConfigurationPath()
: path to the configuration filestd::string MainTesterParameterSetName()
: name of the configuration of the main test (commodity)std::string DefaultTesterConfiguration()
returning a FHiCL string to be parsed to extract the default test configurationWhether the configuration comes from a file or from the two provided defaults, it is always expected within the parameter set paths: the default configuration must also contain that path.
Note that there is no room for polymorphism here since the setup happens on construction. Some methods are declared virtual in order to allow to tweak some steps of the set up, but it's not trivial to create a derived class that works correctly: the derived class must declare a new default constructor, and that default constructor must call the protected constructor (BasicTesterEnvironment<ConfigurationClass>(no_setup))
Definition at line 560 of file unit_test_base.h.
using testing::BasicTesterEnvironment< ConfigurationClass >::Configuration_t = ConfigurationClass |
Definition at line 563 of file unit_test_base.h.
|
inline |
Constructor: sets everything up and declares the test started.
bSetup | (default: true ) call Setup() after construction |
The configuration is from a default-constructed ConfigurationClass. This is suitable for use as Boost unit test fixture.
Definition at line 572 of file unit_test_base.h.
|
inline |
Setup from a configuration.
configurer | an instance of ConfigurationClass |
bSetup | (default: true ) call Setup() after construction |
The configuration is from the specified configurer class.
This constructor allows to use a non-default-constructed configuration. This can't be used (at best of my knowledge) when using this class as Boost unit test fixture.
In the r-value-reference constructor, the configurer is moved.
Definition at line 591 of file unit_test_base.h.
|
inline |
Setup from a configuration.
configurer | an instance of ConfigurationClass |
bSetup | (default: true ) call Setup() after construction |
The configuration is from the specified configurer class.
This constructor allows to use a non-default-constructed configuration. This can't be used (at best of my knowledge) when using this class as Boost unit test fixture.
In the r-value-reference constructor, the configurer is moved.
Definition at line 596 of file unit_test_base.h.
|
virtual |
Destructor: closing remarks.
Definition at line 1057 of file unit_test_base.h.
|
static |
Compiles a parameter set from a string.
Definition at line 1069 of file unit_test_base.h.
References fhicl::ParameterSet::make().
|
inlineprotected |
Returns a read-only version of the configuration.
Definition at line 638 of file unit_test_base.h.
|
protectedvirtual |
Reads and translates the configuration.
Fills the configuration.
The complete configuration (message facility and services) is read and saved, hence accessible by Parameters() method.
The configuration file path is taken by default from the first argument of the test. If that first argument is not present or empty, the default configuration path is received from the configurer. If the configuration path is still empty, a hard-coded configuration is used; otherwise, the FHiCL file specified in that path is parsed and used as full configuration.
Definition at line 1117 of file unit_test_base.h.
|
inlineprotectedvirtual |
Creates a full configuration for the test.
Definition at line 650 of file unit_test_base.h.
References lar::standalone::SetupMessageFacility().
|
inline |
Returns the full configuration.
Definition at line 609 of file unit_test_base.h.
|
private |
Parses the configuration, looking for the test environment options.
Definition at line 1196 of file unit_test_base.h.
References fhicl::ParameterSet::get().
|
staticprotected |
Fills the test configuration from file or from default.
Returns the configuration from a FHiCL file.
If a FHiCL configuration file is specified, the configuration of the test is read from it according to the parameter set path of the test. Otherwise, it is parsed from the default one provided by the configurer.Parses from file and returns a FHiCL data structure
config_path | full path of the FHiCL configuration file |
Definition at line 1083 of file unit_test_base.h.
References fhicl::ParameterSet::make(), and fhicl::parse_document().
|
inline |
Returns the configuration of the specified service.
Definition at line 612 of file unit_test_base.h.
References fhicl::ParameterSet::get().
|
protectedvirtual |
The complete initialization, ran at construction by default.
Reimplemented in testing::GeometryTesterEnvironment< ConfigurationClass >.
Definition at line 1160 of file unit_test_base.h.
References lar::standalone::SetupMessageFacility().
|
protectedvirtual |
Sets up the message facility.
Sets the message facility up.
Message facility configuration is expected in "services.message" parameter set. If not there, the default configuration is used.
Definition at line 1130 of file unit_test_base.h.
References fhicl::ParameterSet::get_if_present(), MF_LOG_TRACE, mf::SetApplicationName(), mf::SetContextIteration(), mf::SetContextSinglet(), mf::StartMessageFacility(), and fhicl::ParameterSet::to_indented_string().
|
inlineprotectedvirtual |
Sets up the message facility.
Sets the message facility up.
Message facility configuration is expected in "services.message" parameter set. If not there, the default configuration is used.
Definition at line 659 of file unit_test_base.h.
References lar::standalone::SetupMessageFacility().
|
inline |
Returns the configuration of the specified test.
Definition at line 618 of file unit_test_base.h.
References fhicl::ParameterSet::get().
|
inline |
Returns the configuration of the main test (undefined if no main test)
Definition at line 624 of file unit_test_base.h.
|
private |
instance of the configurer
Definition at line 681 of file unit_test_base.h.
|
private |
options for the test environment
Definition at line 682 of file unit_test_base.h.
|
private |
full configuration of the test
Definition at line 687 of file unit_test_base.h.