Skip to content

Commit

Permalink
Add tests to increase code coverage
Browse files Browse the repository at this point in the history
The removal of several useless copies in the project lead to
the decrease of code-coverage.
  • Loading branch information
tristan0x committed Sep 19, 2023
1 parent 97dab1e commit 6adfd7b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
13 changes: 5 additions & 8 deletions src/codegen/codegen_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ namespace codegen {
using namespace ast;

using visitor::DefUseAnalyzeVisitor;
using visitor::DUChain;
using visitor::DUState;
using visitor::RenameVisitor;
using visitor::SymtabVisitor;
using visitor::VarUsageVisitor;

using symtab::syminfo::NmodlType;
using SymbolType = std::shared_ptr<symtab::Symbol>;

namespace codegen_utils = nmodl::codegen::utils;
//using SymbolType = std::shared_ptr<symtab::Symbol>;

/****************************************************************************************/
/* Overloaded visitor routines */
Expand Down Expand Up @@ -455,12 +452,12 @@ int CodegenCppVisitor::position_of_int_var(const std::string& name) const {
* representation (1e+20, 1E-15) then keep it as it is.
*/
std::string CodegenCppVisitor::format_double_string(const std::string& s_value) {
return codegen_utils::format_double_string<CodegenCppVisitor>(s_value);
return utils::format_double_string<CodegenCppVisitor>(s_value);
}


std::string CodegenCppVisitor::format_float_string(const std::string& s_value) {
return codegen_utils::format_float_string<CodegenCppVisitor>(s_value);
return utils::format_float_string<CodegenCppVisitor>(s_value);

Check warning on line 460 in src/codegen/codegen_cpp_visitor.cpp

View check run for this annotation

Codecov / codecov/patch

src/codegen/codegen_cpp_visitor.cpp#L460

Added line #L460 was not covered by tests
}


Expand Down Expand Up @@ -788,7 +785,7 @@ void CodegenCppVisitor::update_index_semantics() {
}


std::vector<SymbolType> CodegenCppVisitor::get_float_variables() const {
std::vector<CodegenCppVisitor::SymbolType> CodegenCppVisitor::get_float_variables() const {
// sort with definition order
auto comparator = [](const SymbolType& first, const SymbolType& second) -> bool {
return first->get_definition_order() < second->get_definition_order();
Expand All @@ -798,7 +795,7 @@ std::vector<SymbolType> CodegenCppVisitor::get_float_variables() const {
auto states = info.state_vars;

// each state variable has corresponding Dstate variable
for (auto& state: states) {
for (const auto& state: states) {
auto name = "D" + state->get_name();
auto symbol = make_symbol(name);
if (state->is_array()) {
Expand Down
2 changes: 1 addition & 1 deletion src/symtab/symbol_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ std::shared_ptr<Symbol> SymbolTable::lookup_in_scope(const std::string& name) co
return symbol;
}

/// lookup in current sytab as well as all parent symbol tables
/// lookup in current symtab as well as all parent symbol tables
std::shared_ptr<Symbol> ModelSymbolTable::lookup(const std::string& name) {
if (current_symtab == nullptr) {
throw std::logic_error("Lookup with previous symtab = nullptr ");
Expand Down
29 changes: 26 additions & 3 deletions test/unit/symtab/symbol_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ SCENARIO("Symbol table allows operations like insert, lookup") {
THEN("table size increases") {
REQUIRE(table->symbol_count() == 1);
}
THEN("lookup returns a inserted symbol") {
THEN("lookup returns an inserted symbol") {
REQUIRE(table->lookup("alpha") != nullptr);
REQUIRE(table->lookup("beta") == nullptr);
}
Expand Down Expand Up @@ -228,6 +228,29 @@ SCENARIO("Symbol table allows operations like insert, lookup") {
REQUIRE(next_table->lookup("alpha") == nullptr);
REQUIRE(next_table->lookup_in_scope("alpha") != nullptr);
}
THEN("children can figure if it is in global scope or not") {
REQUIRE(next_table->global_scope() == table->global_scope());
}
}
WHEN("pretty-printing a symbol table to a stream") {
std::ostringstream oss;
table->print(oss, 0);
auto text = oss.str();
THEN("nothing is written when the table is empty") {
REQUIRE(text.empty());
}
table->insert(symbol);
table->print(oss, 0);
text = oss.str();
THEN("the symbol present in the table can be found in the written string") {
REQUIRE(text.find(symbol->get_name()) != std::string::npos);
}
}
WHEN("creating a clone of symbol table") {
auto clone = table->clone();
THEN("clone has the same name") {
REQUIRE(clone->name() == table->name());
}
}
WHEN("query for symbol with and without properties") {
auto symbol1 = std::make_shared<Symbol>("alpha");
Expand Down Expand Up @@ -313,7 +336,7 @@ SCENARIO("Global symbol table (ModelSymbol) allows scope based operations") {
Catch::Matchers::ContainsSubstring("Can not insert"));
}
}
WHEN("enter scope multipel times") {
WHEN("enter scope multiple times") {
auto program1 = std::make_shared<ast::Program>();
auto program2 = std::make_shared<ast::Program>();
mod_symtab.enter_scope("scope1", program1.get(), false, old_symtab);
Expand All @@ -333,7 +356,7 @@ SCENARIO("Global symbol table (ModelSymbol) allows scope based operations") {
REQUIRE(symbol->get_properties() == properties);
}
}
WHEN("added same symbol with exisiting property") {
WHEN("added same symbol with existing property") {
mod_symtab.enter_scope("scope", program.get(), true, old_symtab);
mod_symtab.insert(symbol1);
mod_symtab.insert(symbol2);
Expand Down

0 comments on commit 6adfd7b

Please sign in to comment.