Skip to content

Commit 28c6477

Browse files
author
thk123
committed
Adding utility for getting symbols out of the symbol table
1 parent 06ab440 commit 28c6477

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

unit/testing-utils/require_symbol.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*******************************************************************\
2+
3+
Module: Unit test utilities
4+
5+
Author: DiffBlue Limited. All rights reserved.
6+
7+
\*******************************************************************/
8+
9+
#include "require_symbol.h"
10+
#include "catch.hpp"
11+
12+
/// Verify whether a given identifier is found in the symbol table and return it
13+
/// \param symbol_table: The symbol table to look in
14+
/// \param symbol_identifier: The name of the symbol
15+
const symbolt &require_symbol::require_symbol_exists(
16+
const symbol_tablet &symbol_table,
17+
const irep_idt &symbol_identifier)
18+
{
19+
const symbolt *found_symbol = symbol_table.lookup(symbol_identifier);
20+
INFO("Looking for symbol: " + id2string(symbol_identifier));
21+
REQUIRE(found_symbol != nullptr);
22+
return *found_symbol;
23+
}

unit/testing-utils/require_symbol.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*******************************************************************\
2+
3+
Module: Unit test utilities
4+
5+
Author: DiffBlue Limited. All rights reserved.
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_TESTING_UTILS_REQUIRE_SYMBOL_H
10+
#define CPROVER_TESTING_UTILS_REQUIRE_SYMBOL_H
11+
12+
#include <util/symbol.h>
13+
#include <util/symbol_table.h>
14+
15+
/// \file
16+
/// Helper functions for getting symbols from the symbol table during unit tests
17+
18+
// NOLINTNEXTLINE(readability/namespace)
19+
namespace require_symbol
20+
{
21+
const symbolt &require_symbol_exists(
22+
const symbol_tablet &symbol_table,
23+
const irep_idt &symbol_identifier);
24+
}
25+
26+
#endif // CPROVER_TESTING_UTILS_REQUIRE_SYMBOL_H

0 commit comments

Comments
 (0)