@@ -59,8 +59,9 @@ void executeSimulation()
5959 // verify is the binary exists
6060 if (!std::filesystem::exists (exe_path)) {
6161 std::cerr << " Executable not found: " << exe_path << std::endl;
62- FAIL () << " Could not find simulation executable." ;
63- return ;
62+ std::cerr << " Please build the project before running the test." << std::endl;
63+ // throw std::runtime_error("Executable not found.");
64+ throw ;
6465 }
6566
6667 script = exe_path.string () + " cuboid.json" ;
@@ -72,12 +73,10 @@ void executeSimulation()
7273 }
7374 else
7475 {
75- std::cerr << " Simulation failed with response code: " << response << std::endl;
76+ std::cerr << " MPM-Geomechanics.exe simulation failed with response code: " << response << std::endl;
7677 std::cerr << " Please check if simulation program exists and try again." << std::endl;
77- FAIL () << " Could not execute simulation." ;
78- // raise
79-
80- return ;
78+ // throw std::runtime_error("MPM-Geomechanics.exe simulation failed. Check the executable and try again.");
79+ throw ;
8180 }
8281
8382 std::string filename = " time-energy.csv" ;
@@ -93,22 +92,29 @@ void executeSimulation()
9392 }
9493 catch (const std::exception& e)
9594 {
96- std::cerr << " Exception during simulation execution: " << e.what () << std::endl ;
97- FAIL () << " Simulation execution failed due to exception. " ;
95+ // throw std::runtime_error( e.what()) ;
96+ throw ;
9897 }
9998}
10099
101100TEST (ENERGY_COMPARISON, ENERGY_SUM)
102101{
103- executeSimulation ();
102+ try {
103+ executeSimulation ();
104104
105- double main_energy = sum_energy (" analytical_energy.csv" );
106- double test_energy = sum_energy (" time-energy.csv" );
105+ double main_energy = sum_energy (" analytical_energy.csv" );
106+ double test_energy = sum_energy (" time-energy.csv" );
107107
108- if (main_energy == -1.0 || test_energy == -1.0 ) {
109- FAIL () << " Could not calculate energy from one or both files." ;
110- }
108+ if (main_energy == -1.0 || test_energy == -1.0 ) {
109+ std::cerr << " Could not calculate energy from one or both files." << std::endl;
110+ FAIL () << " Could not calculate energy from one or both files." ;
111+ }
111112
112- EXPECT_EQ (main_energy, test_energy);
113+ EXPECT_EQ (main_energy, test_energy);
114+ } catch (const std::exception& e) {
115+ std::cerr << " Exception during test execution: " << e.what () << std::endl;
116+ FAIL () << " Exception during test execution: " << e.what () << std::endl;
117+ throw std::runtime_error (" Exception during test execution." );
118+ }
113119}
114120
0 commit comments