diff --git a/src/language/utils/ASTCheckpointsInfo.cpp b/src/language/utils/ASTCheckpointsInfo.cpp index 779290bba15c2c6de0f6d5d95cd5b2d0d6d4e823..fa1898e88e447883a0bcd0cd6eaec3be653fba5f 100644 --- a/src/language/utils/ASTCheckpointsInfo.cpp +++ b/src/language/utils/ASTCheckpointsInfo.cpp @@ -29,7 +29,7 @@ ASTCheckpointsInfo::_findASTCheckpoint(std::vector<size_t>& location, const ASTN ASTCheckpointsInfo::ASTCheckpointsInfo(const ASTNode& root_node) { - Assert(m_checkpoints_info_instance == nullptr, "Can only define one ASTCheckpointInfo"); + Assert(m_checkpoints_info_instance == nullptr, "Can only define one ASTCheckpointsInfo"); m_checkpoints_info_instance = this; Assert(root_node.is_root()); @@ -43,7 +43,7 @@ ASTCheckpointsInfo::ASTCheckpointsInfo(const ASTNode& root_node) const ASTCheckpointsInfo& ASTCheckpointsInfo::getInstance() { - Assert(m_checkpoints_info_instance != nullptr, "ASTCheckpointInfo is not defined!"); + Assert(m_checkpoints_info_instance != nullptr, "ASTCheckpointsInfo is not defined!"); return *m_checkpoints_info_instance; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8fd49bde44783c6af4237747b78c26359769b3ba..871bfbe45bded361f68b64b0a315f7daa9e508a7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,6 +19,7 @@ add_executable (unit_tests test_ArraySubscriptProcessor.cpp test_ASTBuilder.cpp test_ASTCheckpoint.cpp + test_ASTCheckpointsInfo.cpp test_ASTDotPrinter.cpp test_ASTExecutionStack.cpp test_ASTModulesImporter.cpp diff --git a/tests/test_ASTCheckpointsInfo.cpp b/tests/test_ASTCheckpointsInfo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..61eb5c00f311f73994b3ba2f60d28f857fd149c7 --- /dev/null +++ b/tests/test_ASTCheckpointsInfo.cpp @@ -0,0 +1,83 @@ +#include <catch2/catch_approx.hpp> +#include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers_predicate.hpp> + +#include <utils/pugs_config.hpp> + +#include <dev/ParallelChecker.hpp> +#include <language/ast/ASTBuilder.hpp> +#include <language/ast/ASTExecutionStack.hpp> +#include <language/ast/ASTModulesImporter.hpp> +#include <language/ast/ASTNodeDataTypeBuilder.hpp> +#include <language/ast/ASTNodeDeclarationToAffectationConverter.hpp> +#include <language/ast/ASTNodeExpressionBuilder.hpp> +#include <language/ast/ASTNodeTypeCleaner.hpp> +#include <language/ast/ASTSymbolTableBuilder.hpp> +#include <language/modules/MathModule.hpp> +#include <language/utils/ASTCheckpointsInfo.hpp> +#include <language/utils/CheckpointResumeRepository.hpp> +#include <utils/ExecutionStatManager.hpp> + +class ASTCheckpointsInfoTester +{ + private: + ASTCheckpointsInfo m_ast_checkpoint_info; + + public: + ASTCheckpointsInfoTester(const ASTNode& root_node) : m_ast_checkpoint_info(root_node) {} + ~ASTCheckpointsInfoTester() = default; +}; + +// clazy:excludeall=non-pod-global-static + +TEST_CASE("ASTCheckpointsInfo", "[utils/checkpointing]") +{ +#ifndef NDEBUG + REQUIRE_THROWS_WITH(ASTCheckpointsInfo::getInstance(), "ASTCheckpointsInfo is not defined!"); +#endif // NDEBUG + + std::string data = R"( +for(let i:N, i=0; i<7; ++i) { + checkpoint(); + + if (i == 2) { + checkpoint(); + } + + if (i == 5) { + checkpoint_and_exit(); + } +} +)"; + + ExecutionStatManager::create(); + + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; + auto ast = ASTBuilder::build(input); + + ASTModulesImporter{*ast}; + ASTNodeTypeCleaner<language::import_instruction>{*ast}; + + ASTSymbolTableBuilder{*ast}; + ASTNodeDataTypeBuilder{*ast}; + + ASTNodeDeclarationToAffectationConverter{*ast}; + ASTNodeTypeCleaner<language::var_declaration>{*ast}; + ASTNodeTypeCleaner<language::fct_declaration>{*ast}; + + ASTNodeExpressionBuilder{*ast}; + ExecutionPolicy exec_policy; + ASTExecutionStack::create(); + ASTCheckpointsInfoTester ast_cp_info_tester{*ast}; + ASTExecutionStack::destroy(); + ExecutionStatManager::destroy(); + ast->m_symbol_table->clearValues(); + + REQUIRE(ASTCheckpointsInfo::getInstance().getASTCheckpoint(0).getASTLocation() == std::vector<size_t>{0, 3, 0}); + REQUIRE(ASTCheckpointsInfo::getInstance().getASTCheckpoint(1).getASTLocation() == std::vector<size_t>{0, 3, 1, 1}); + REQUIRE(ASTCheckpointsInfo::getInstance().getASTCheckpoint(2).getASTLocation() == std::vector<size_t>{0, 3, 2, 1}); + +#ifndef NDEBUG + REQUIRE_THROWS_WITH(ASTCheckpointsInfoTester(*ast), "Can only define one ASTCheckpointsInfo"); +#endif // NDEBUG +}