Testing#

Test libs#

  • mock_env

  • mock_toolchain

  • mock_target

mock_env#

  • assert_handle_fatal uses throw std::exception instead of std::terminate

  • We can now use the CppUTest CHECK_THROWS API 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::Execute is mocked out to CppUMock .actualCall("execute") API

  • We can redirect stdout and stderr through the actual call, with our own information to match expectations using the CppUMock .withOutputParameterOfType API

  • Provided with the CommandExpect_Execute mocked API

  • The command and working_directory params 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::Execute expectation API

Parameters
  • 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_PRINT statement instead

class VectorStringCopier : public MockNamedValueCopier#

Public Functions

inline void copy(void *out, const void *in) override#

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.

void buildcc::m::TargetExpect_SourceRemoved(unsigned int calls, Target *target)#
void buildcc::m::TargetExpect_SourceAdded(unsigned int calls, Target *target)#
void buildcc::m::TargetExpect_SourceUpdated(unsigned int calls, Target *target)#
void buildcc::m::TargetExpect_PathRemoved(unsigned int calls, Target *target)#
void buildcc::m::TargetExpect_PathAdded(unsigned int calls, Target *target)#
void buildcc::m::TargetExpect_PathUpdated(unsigned int calls, Target *target)#
void buildcc::m::TargetExpect_DirChanged(unsigned int calls, Target *target)#
void buildcc::m::TargetExpect_FlagChanged(unsigned int calls, Target *target)#
void buildcc::m::TargetExpect_ExternalLibChanged(unsigned int calls, Target *target)#

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#

  • env

  • toolchain

  • target

  • args

  • register

  • plugins

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