Testing¶
Test libs¶
mock_envmock_toolchainmock_target
mock_env¶
assert_handle_fatalusesthrow std::exceptioninstead ofstd::terminateWe can now use the CppUTest
CHECK_THROWSAPI when a failure occurs
-
void buildcc::env::assert_handle_fatal()¶
During Release -> NOT THREADED : std::exit THREADED : throw std::exception (it is wrong to exit when in a threaded state. We want to handle the exception and gracefully exit) During Unit Test -> throw std::exception.
Command::Executeis mocked out to CppUMock.actualCall("execute")APIWe can redirect stdout and stderr through the actual call, with our own information to match expectations using the CppUMock
.withOutputParameterOfTypeAPIProvided with the
CommandExpect_Executemocked APIThe
commandandworking_directoryparams are not used
-
void buildcc::env::m::CommandExpect_Execute(unsigned int calls, bool expectation, std::vector<std::string> *stdout_data = nullptr, std::vector<std::string> *stderr_data = nullptr)¶
Command::Executeexpectation API- Parameters:
calls – Number of times the actual
Command::ExecuteAPI is calledexpectation – Return value of the actual
Command::ExecuteAPIstdout_data – Data passed into stdout_data is redirected into the actual
Command::ExecuteAPI to check for expectations. SeeVectorStringCopierstderr_data – Data passed into stderr_data is redirected into the actual
Command::ExecuteAPI to check for expectations. SeeVectorStringCopier
All of the logging APIs have been stubbed out since they are unnecessary for unit tests and very noisy when getting output
A better alternative would be debugging unit tests or adding the CppUTest
UT_PRINTstatement instead
mock_toolchain¶
Does not override any classes / functions
mock_target¶
-
void buildcc::m::CustomGeneratorRunner(CustomGenerator &custom_generator)¶
Runs the generator using Taskflow with 1 thread CppUTest cannot mock with multiple threads.
-
void buildcc::m::CustomGeneratorExpect_IdRemoved(unsigned int calls, CustomGenerator *generator)¶
-
void buildcc::m::CustomGeneratorExpect_IdAdded(unsigned int calls, CustomGenerator *generator)¶
-
void buildcc::m::CustomGeneratorExpect_IdUpdated(unsigned int calls, CustomGenerator *generator)¶
From the Serialization Schema generator we can see that our generator has 3 rebuild conditions
- Inputs
Removed state (input file is removed)
Added state (input file is added)
Updated state (input file is updated)
- Outputs
Changed (output file is added or removed)
- Commands
Changed (command is added or removed)
-
void buildcc::m::TargetRunner(Target &target)¶
Runs the target using Taskflow with 1 thread CppUTest cannot mock with multiple threads.
From the Serialization Schema target we can see that our generator has multiple rebuild conditions
Anything associated with Path has 3 states i.e Added, Removed or Updated
Everything else has only 2 states i.e Added or Removed
Tests¶
envtoolchaintargetargsregisterplugins
env¶
test_env_util
test_task_state
test_command
toolchain¶
test_toolchain_verify
target¶
test_path
test_builder_interface
test_target_config
test_target_state
test_generator
test_compile_object
test_base_target
test_target_pch
test_target_source
test_target_source_out_of_root
test_target_include_dir
test_target_lib_dep
test_target_external_lib
test_target_flags
test_target_user_deps
test_target_lock
test_target_sync
test_target_failure_states
args¶
test_args
test_register
test_persistent_storage
plugins¶
Note
Incomplete implementation and tests