Skip to content

Commit 3ed6e36

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

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

unit/testing-utils/require_symbol.cpp

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

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)