@@ -1094,3 +1094,86 @@ TEST_SUITE("file") {
10941094 infile.close ();
10951095 }
10961096}
1097+
1098+
1099+ TEST_SUITE (" undo_and_redefinition" ) {
1100+ TEST_CASE (" RedefinitionAndUndoErrors" ) {
1101+ std::vector<const char *> Args = {/* "-v", "resource-dir", "..."*/ };
1102+ xcpp::interpreter interpreter ((int )Args.size (), Args.data ());
1103+ std::string code = R"(
1104+ int x = 5;
1105+ )" ;
1106+ nl::json user_expressions = nl::json::object ();
1107+ xeus::execute_request_config config;
1108+ config.silent = false ;
1109+ config.store_history = false ;
1110+ config.allow_stdin = false ;
1111+ nl::json header = nl::json::object ();
1112+ xeus::xrequest_context::guid_list id = {};
1113+ xeus::xrequest_context context (header, id);
1114+
1115+ // Execute first code: define int x = 5
1116+ std::promise<nl::json> promise1;
1117+ std::future<nl::json> future1 = promise1.get_future ();
1118+ auto callback1 = [&promise1](nl::json result) {
1119+ promise1.set_value (result);
1120+ };
1121+ interpreter.execute_request (
1122+ std::move (context),
1123+ std::move (callback1),
1124+ code,
1125+ std::move (config),
1126+ user_expressions
1127+ );
1128+ nl::json execute1 = future1.get ();
1129+ REQUIRE (execute1[" status" ] == " ok" );
1130+
1131+ code = R"( %undo)" ;
1132+ std::promise<nl::json> promise2;
1133+ std::future<nl::json> future2 = promise2.get_future ();
1134+ auto callback2 = [&promise2](nl::json result) {
1135+ promise2.set_value (result);
1136+ };
1137+ interpreter.execute_request (
1138+ std::move (context),
1139+ std::move (callback2),
1140+ code,
1141+ std::move (config),
1142+ user_expressions
1143+ );
1144+ nl::json execute2 = future2.get ();
1145+ REQUIRE (execute2[" status" ] == " ok" );
1146+
1147+ code = " int x = 10;" ;
1148+ std::promise<nl::json> promise3;
1149+ std::future<nl::json> future3 = promise3.get_future ();
1150+ auto callback3 = [&promise3](nl::json result) {
1151+ promise3.set_value (result);
1152+ };
1153+ interpreter.execute_request (
1154+ std::move (context),
1155+ std::move (callback3),
1156+ code,
1157+ std::move (config),
1158+ user_expressions
1159+ );
1160+ nl::json execute3 = future3.get ();
1161+ REQUIRE (execute3[" status" ] == " ok" );
1162+
1163+ code = " int x = 20;" ;
1164+ std::promise<nl::json> promise4;
1165+ std::future<nl::json> future4 = promise4.get_future ();
1166+ auto callback4 = [&promise4](nl::json result) {
1167+ promise4.set_value (result);
1168+ };
1169+ interpreter.execute_request (
1170+ std::move (context),
1171+ std::move (callback4),
1172+ code,
1173+ std::move (config),
1174+ user_expressions
1175+ );
1176+ nl::json execute4 = future4.get ();
1177+ REQUIRE (execute4[" status" ] == " error" );
1178+ }
1179+ }
0 commit comments