Skip to content

Add global null message handler #2233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions jbmc/unit/java-testing-utils/load_java_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

#include "load_java_class.h"

#include <testing-utils/free_form_cmdline.h>
#include <testing-utils/catch.hpp>
#include <iostream>
#include <testing-utils/catch.hpp>
#include <testing-utils/free_form_cmdline.h>
#include <testing-utils/message.h>

#include <util/config.h>
#include <util/suffix.h>
Expand Down Expand Up @@ -94,13 +95,16 @@ symbol_tablet load_java_class(
std::string filename=java_class_name + ".class";

// Construct a lazy_goto_modelt
null_message_handlert message_handler;
lazy_goto_modelt lazy_goto_model(
[] (goto_model_functiont &function, const abstract_goto_modelt &model) { }, // NOLINT (*)
[] (goto_modelt &goto_model) { return false; }, // NOLINT (*)
[] (const irep_idt &name) { return false; },
[] (const irep_idt &function_name, symbol_table_baset &symbol_table, goto_functiont &function, bool body_available) { return false; }, // NOLINT (*)
message_handler);
[](goto_model_functiont &function, const abstract_goto_modelt &model) {},
[](goto_modelt &goto_model) { return false; },
[](const irep_idt &name) { return false; },
[](
const irep_idt &function_name,
symbol_table_baset &symbol_table,
goto_functiont &function,
bool body_available) { return false; },
null_message_handler);

// Configure the path loading
config.java.classpath.clear();
Expand All @@ -115,7 +119,7 @@ symbol_tablet load_java_class(
std::istringstream java_code_stream("ignored");

// Configure the language, load the class files
language.set_message_handler(message_handler);
language.set_message_handler(null_message_handler);
language.get_language_options(command_line);
language.parse(java_code_stream, filename);
language.typecheck(lazy_goto_model.symbol_table, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

#include <algorithm>
#include <functional>
#include <util/message.h>
#include <util/config.h>

#include <java-testing-utils/require_parse_tree.h>

#include <testing-utils/catch.hpp>
#include <java_bytecode/java_bytecode_parser.h>
#include <testing-utils/catch.hpp>
#include <testing-utils/message.h>

#include <java_bytecode/java_bytecode_parse_tree.h>
#include <java_bytecode/java_types.h>
Expand All @@ -29,14 +29,13 @@ SCENARIO(
{
// NOLINTNEXTLINE(whitespace/braces)
run_test_with_compilers([](const std::string &compiler) {
null_message_handlert message_handler;
GIVEN(
"A class with a static lambda variables from " + compiler + " compiler.")
{
optionalt<java_bytecode_parse_treet> parse_tree = java_bytecode_parse(
"./java_bytecode/java_bytecode_parse_lambdas/lambda_examples/" +
compiler + "_classes/StaticLambdas.class",
message_handler);
null_message_handler);
WHEN("Parsing that class")
{
REQUIRE(parse_tree);
Expand Down Expand Up @@ -341,13 +340,12 @@ SCENARIO(
{
run_test_with_compilers(
[](const std::string &compiler) { // NOLINT(whitespace/braces)
null_message_handlert message_handler;
GIVEN("A method with local lambdas from " + compiler + " compiler.")
{
optionalt<java_bytecode_parse_treet> parse_tree = java_bytecode_parse(
"./java_bytecode/java_bytecode_parse_lambdas/lambda_examples/" +
compiler + "_classes/LocalLambdas.class",
message_handler);
null_message_handler);
WHEN("Parsing that class")
{
REQUIRE(parse_tree);
Expand Down Expand Up @@ -648,15 +646,14 @@ SCENARIO(
{
run_test_with_compilers(
[](const std::string &compiler) { // NOLINT(whitespace/braces)
null_message_handlert message_handler;
GIVEN(
"A class that has lambdas as member variables from " + compiler +
" compiler.")
{
optionalt<java_bytecode_parse_treet> parse_tree = java_bytecode_parse(
"./java_bytecode/java_bytecode_parse_lambdas/lambda_examples/" +
compiler + "_classes/MemberLambdas.class",
message_handler);
null_message_handler);
WHEN("Parsing that class")
{
REQUIRE(parse_tree);
Expand Down Expand Up @@ -982,7 +979,6 @@ SCENARIO(
{
run_test_with_compilers(
[](const std::string &compiler) { // NOLINT(whitespace/braces)
null_message_handlert message_handler;
GIVEN(
"An inner class with member variables as lambdas that capture outer "
"variables from " +
Expand All @@ -991,7 +987,7 @@ SCENARIO(
optionalt<java_bytecode_parse_treet> parse_tree = java_bytecode_parse(
"./java_bytecode/java_bytecode_parse_lambdas/lambda_examples/" +
compiler + "_classes/OuterMemberLambdas$Inner.class",
message_handler);
null_message_handler);
WHEN("Parsing that class")
{
REQUIRE(parse_tree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

\*******************************************************************/

#include <testing-utils/catch.hpp>
#include <java-testing-utils/load_java_class.h>
#include <testing-utils/catch.hpp>
#include <testing-utils/message.h>

#include <goto-programs/goto_convert_functions.h>
#include <goto-programs/remove_virtual_functions.h>
Expand Down Expand Up @@ -84,9 +85,8 @@ TEST_CASE(
journalling_symbol_tablet symbol_table =
journalling_symbol_tablet::wrap(raw_symbol_table);

null_message_handlert null_output;
goto_functionst functions;
goto_convert(symbol_table, functions, null_output);
goto_convert(symbol_table, functions, null_message_handler);

const std::string function_name = "java::Main.replaceNondet:()V";
goto_functionst::goto_functiont &goto_function =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

\*******************************************************************/

#include <testing-utils/catch.hpp>
#include <java-testing-utils/load_java_class.h>
#include <testing-utils/catch.hpp>
#include <testing-utils/message.h>

#include <goto-programs/goto_convert_functions.h>
#include <goto-programs/remove_virtual_functions.h>
Expand Down Expand Up @@ -53,9 +54,8 @@ SCENARIO(
WHEN("The entry point function is generated")
{
symbol_tablet new_table(symbol_table);
null_message_handlert null_output;
goto_functionst new_goto_functions;
goto_convert(new_table, new_goto_functions, null_output);
goto_convert(new_table, new_goto_functions, null_message_handler);
remove_virtual_functions(new_table, new_goto_functions);

bool found_function = false;
Expand Down Expand Up @@ -129,7 +129,7 @@ SCENARIO(
options.set_option("cover", "location");
REQUIRE_FALSE(
instrument_cover_goals(
options, new_table, new_goto_functions, null_output));
options, new_table, new_goto_functions, null_message_handler));

auto function = new_goto_functions.function_map.find(function_name);
REQUIRE(function != new_goto_functions.function_map.end());
Expand Down
8 changes: 4 additions & 4 deletions jbmc/unit/pointer-analysis/custom_value_set_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Author: Chris Smowton, chris@smowton.net
\*******************************************************************/

#include <testing-utils/catch.hpp>
#include <testing-utils/message.h>

#include <goto-programs/goto_inline.h>
#include <goto-programs/initialize_goto_model.h>
Expand Down Expand Up @@ -170,7 +171,6 @@ SCENARIO("test_value_set_analysis",
{
config.set_arch("none");
config.main = "";
null_message_handlert null_output;
cmdlinet command_line;

// This classpath is the default, but the config object
Expand All @@ -181,8 +181,8 @@ SCENARIO("test_value_set_analysis",

register_language(new_java_bytecode_language);

goto_modelt goto_model=
initialize_goto_model(command_line, null_output);
goto_modelt goto_model =
initialize_goto_model(command_line, null_message_handler);

null_message_handlert message_handler;
remove_java_new(goto_model, message_handler);
Expand All @@ -191,7 +191,7 @@ SCENARIO("test_value_set_analysis",

// Fully inline the test program, to avoid VSA conflating
// constructor callsites confusing the results we're trying to check:
goto_function_inline(goto_model, TEST_FUNCTION_NAME, null_output);
goto_function_inline(goto_model, TEST_FUNCTION_NAME, null_message_handler);

const goto_programt &test_function=
goto_model.goto_functions.function_map.at(TEST_PREFIX "test:()V").body;
Expand Down
10 changes: 5 additions & 5 deletions unit/json/json_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

#include <json/json_parser.h>
#include <testing-utils/catch.hpp>
#include <testing-utils/message.h>

SCENARIO("Loading JSON files")
{
null_message_handlert message_handler;
GIVEN("A invalid JSON file and a valid JSON file")
{
const std::string valid_json_path = "./json/valid.json";
Expand All @@ -21,7 +21,7 @@ SCENARIO("Loading JSON files")
{
jsont invalid_json;
const auto invalid_parse_error =
parse_json(invalid_json_path, message_handler, invalid_json);
parse_json(invalid_json_path, null_message_handler, invalid_json);
THEN("An error state should be returned")
{
REQUIRE(invalid_parse_error);
Expand All @@ -30,7 +30,7 @@ SCENARIO("Loading JSON files")
{
jsont valid_json;
const auto valid_parse_error =
parse_json(valid_json_path, message_handler, valid_json);
parse_json(valid_json_path, null_message_handler, valid_json);
THEN("The JSON file should be parsed correctly")
{
REQUIRE_FALSE(valid_parse_error);
Expand All @@ -45,7 +45,7 @@ SCENARIO("Loading JSON files")
{
jsont valid_json;
const auto valid_parse_error =
parse_json(valid_json_path, message_handler, valid_json);
parse_json(valid_json_path, null_message_handler, valid_json);
THEN("The JSON file should be parsed correctly")
{
REQUIRE_FALSE(valid_parse_error);
Expand All @@ -56,7 +56,7 @@ SCENARIO("Loading JSON files")
{
jsont invalid_json;
const auto invalid_parse_error =
parse_json(invalid_json_path, message_handler, invalid_json);
parse_json(invalid_json_path, null_message_handler, invalid_json);
THEN("An error state should be returned")
{
REQUIRE(invalid_parse_error);
Expand Down
1 change: 1 addition & 0 deletions unit/testing-utils/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
SRC = \
c_to_expr.cpp \
free_form_cmdline.cpp \
message.cpp \
require_expr.cpp \
require_symbol.cpp \
run_test_with_compilers.cpp \
Expand Down
14 changes: 14 additions & 0 deletions unit/testing-utils/message.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*******************************************************************\

Module: Unit test utilities

Author: Diffblue Ltd.

\*******************************************************************/

/// \file
/// Global instance of `null_message_handlert`.

#include "message.h"

null_message_handlert null_message_handler;
16 changes: 16 additions & 0 deletions unit/testing-utils/message.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*******************************************************************\

Module: Unit test utilities

Author: DiffBlue Limited. All rights reserved.

\*******************************************************************/

#ifndef CPROVER_TESTING_UTILS_MESSAGE_H
#define CPROVER_TESTING_UTILS_MESSAGE_H

#include <util/message.h>

extern null_message_handlert null_message_handler;

#endif // CPROVER_TESTING_UTILS_MESSAGE_H