Skip to content

Commit 7c04b5c

Browse files
authored
Merge pull request diffblue#1699 from NathanJPhillips/feature/reset-main-in-tests
Allow callers of load_java_class to pass the name of the main function
2 parents 8236db4 + 591511a commit 7c04b5c

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

unit/testing-utils/load_java_class.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,39 @@
1919

2020
#include <java_bytecode/java_bytecode_language.h>
2121

22-
/// Go through the process of loading, typechecking and finalising loading a
22+
/// Go through the process of loading, type-checking and finalising loading a
2323
/// specific class file to build the symbol table.
2424
/// \param java_class_name: The name of the class file to load. It should not
2525
/// include the .class extension.
2626
/// \param class_path: The path to load the class from. Should be relative to
2727
/// the unit directory.
28+
/// \param main: The name of the main function or "" to use the default
29+
/// behaviour to find a main function.
2830
/// \return The symbol table that is generated by parsing this file.
2931
symbol_tablet load_java_class(
3032
const std::string &java_class_name,
31-
const std::string &class_path)
33+
const std::string &class_path,
34+
const std::string &main)
3235
{
3336
return load_java_class(
34-
java_class_name, class_path, new_java_bytecode_language());
37+
java_class_name, class_path, main, new_java_bytecode_language());
3538
}
3639

40+
/// Go through the process of loading, type-checking and finalising loading a
41+
/// specific class file to build the symbol table.
42+
/// \param java_class_name: The name of the class file to load. It should not
43+
/// include the .class extension.
44+
/// \param class_path: The path to load the class from. Should be relative to
45+
/// the unit directory.
46+
/// \param main: The name of the main function or "" to use the default
47+
/// behaviour to find a main function.
48+
/// \param java_lang: The language implementation to use for the loading,
49+
/// which will be destroyed by this function.
50+
/// \return The symbol table that is generated by parsing this file.
3751
symbol_tablet load_java_class(
3852
const std::string &java_class_name,
3953
const std::string &class_path,
54+
const std::string &main,
4055
std::unique_ptr<languaget> &&java_lang)
4156
{
4257
// We expect the name of the class without the .class suffix to allow us to
@@ -58,6 +73,7 @@ symbol_tablet load_java_class(
5873
command_line.set("java-cp-include-files", class_path);
5974
config.java.classpath.clear();
6075
config.java.classpath.push_back(class_path);
76+
config.main = main;
6177

6278
// Add the language to the model
6379
language_filet &lf=lazy_goto_model.add_language_file(filename);

unit/testing-utils/load_java_class.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919

2020
symbol_tablet load_java_class(
2121
const std::string &java_class_name,
22-
const std::string &class_path);
22+
const std::string &class_path,
23+
const std::string &main = "");
2324

2425
symbol_tablet load_java_class(
2526
const std::string &java_class_name,
2627
const std::string &class_path,
28+
const std::string &main,
2729
std::unique_ptr<languaget> &&java_lang);
2830

2931
#endif // CPROVER_TESTING_UTILS_LOAD_JAVA_CLASS_H

0 commit comments

Comments
 (0)