Skip to content
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

Add a method to the Lattice object that just throws and catches an ex… #297

Draft
wants to merge 5 commits into
base: devel3
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions src/synergia/lattice/lattice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,4 @@ Lattice::set_variable(std::string const& name, std::string const& val)
{
tree.set_variable(name, val);
}

2 changes: 2 additions & 0 deletions src/synergia/lattice/lattice.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,6 @@ class Lattice {

};



#endif /* LATTICE_H_ */
3 changes: 3 additions & 0 deletions src/synergia/lattice/lattice_pywrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ PYBIND11_MODULE(lattice, m)
"filename"_a, "line"_a )

.def( "__repr__", &Lattice::as_string )

;


Expand Down Expand Up @@ -497,6 +498,8 @@ PYBIND11_MODULE(lattice, m)
&MadX_reader::parse_file,
"Parse a lattice file",
"filename"_a )
.def("do_not_call_this_function", &MadX_reader::do_not_call_this_function, "evil function")

;

}
Expand Down
24 changes: 24 additions & 0 deletions src/synergia/lattice/madx_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,24 @@ namespace {
catch (...) {
}
}

void
evil_function()
{
try {
throw std::runtime_error("evil function called!!!");
}
#if 1
catch (...) { // this parallels extract_reference_particle()
// Now it is even failing on regular ubuntu
}
#else // This one doesn't cause trouble on ubuntu-clang
catch (const std::exception& e) {
std::cerr << "exception caught\n" << std::endl;
// std::cerr << e.what() << '\n';
}
#endif
}
}

void
Expand Down Expand Up @@ -362,3 +380,9 @@ MadX_reader::get_dynamic_lattice(std::string const& line_name,
extract_reference_particle(lattice, mx);
return lattice;
}

void
MadX_reader::do_not_call_this_function()
{
evil_function();
}
3 changes: 3 additions & 0 deletions src/synergia/lattice/madx_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ class MadX_reader {

static Lattice get_dynamic_lattice(std::string const& line_name,
synergia::MadX const& mx);

void do_not_call_this_function();

};
#endif /* MADX_READER_CC_ */
5 changes: 5 additions & 0 deletions src/synergia/lattice/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ if(BUILD_PYTHON_BINDINGS)
add_py_test(test_lattice.py)
add_py_test(test_dynamic_lattice.py)
add_py_test(test_parse_matrix.py)
add_py_test(test_evil_function.py)
endif()

add_executable(test_lattice test_lattice.cc ${test_main})
Expand All @@ -16,6 +17,10 @@ add_executable(test_madx_parser test_madx_parser.cc ${test_main})
target_link_libraries(test_madx_parser PRIVATE synergia_lattice ${testing_libs})
add_mpi_test(test_madx_parser 1)

add_executable(test_evil_function test_evil_function.cc ${test_main})
target_link_libraries(test_evil_function PRIVATE synergia_lattice ${testing_libs})
add_mpi_test(test_evil_function 1)

copy_file(foo.dbx test_madx_parser)

add_executable(test_dynamic_lattice test_dynamic_lattice.cc ${test_main})
Expand Down
16 changes: 16 additions & 0 deletions src/synergia/lattice/tests/test_evil_function.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>

#include "catch2/matchers/catch_matchers.hpp"
#include "synergia/lattice/lattice.h"
#include "synergia/lattice/madx_reader.h"

#include "synergia/utils/cereal_files.h"

const std::string name("foo");

TEST_CASE("call_evil_function")
{
MadX_reader reader;
REQUIRE_NOTHROW(reader.do_not_call_this_function());
}
16 changes: 16 additions & 0 deletions src/synergia/lattice/tests/test_evil_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python
import pytest
import synergia
from synergia.lattice import Lattice, Lattice_element
from synergia.foundation import Reference_particle

name = "foo"

def test_evil_functon():
reader = synergia.lattice.MadX_reader()
try:
reader.do_not_call_this_function()
except:
raise Runtime_Error('I told you not to call this function!!!')

assert True