Skip to content

Commit 47ef8f0

Browse files
committed
Replace assert() with print()+return in test_audit_tuple
1 parent 45fe3c5 commit 47ef8f0

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

Programs/_testembed.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,11 +1278,14 @@ static int _test_audit(Py_ssize_t setValue)
12781278
printf("Set event failed");
12791279
return 4;
12801280
}
1281-
assert(!PyErr_Occurred());
1281+
if (PyErr_Occurred()) {
1282+
printf("Exception raised");
1283+
return 5;
1284+
}
12821285

12831286
if (sawSet != 42) {
12841287
printf("Failed to see *userData change\n");
1285-
return 5;
1288+
return 6;
12861289
}
12871290

12881291
return 0;
@@ -1300,45 +1303,53 @@ static int test_audit(void)
13001303

13011304
static int test_audit_tuple(void)
13021305
{
1306+
#define ASSERT(TEST, EXITCODE) \
1307+
if (!(TEST)) { \
1308+
printf("ERROR test failed at %s:%i\n", __FILE__, __LINE__); \
1309+
return (EXITCODE); \
1310+
}
1311+
13031312
Py_ssize_t sawSet = 0;
13041313

13051314
// we need at least one hook, otherwise code checking for
13061315
// PySys_AuditTuple() is skipped.
13071316
PySys_AddAuditHook(_audit_hook, &sawSet);
13081317
_testembed_Py_InitializeFromConfig();
13091318

1310-
assert(!PyErr_Occurred());
1319+
ASSERT(!PyErr_Occurred(), 0);
13111320

13121321
// pass Python tuple object
13131322
PyObject *tuple = Py_BuildValue("(i)", 444);
13141323
if (tuple == NULL) {
13151324
goto error;
13161325
}
1317-
assert(PySys_AuditTuple("_testembed.set", tuple) == 0);
1318-
assert(!PyErr_Occurred());
1319-
assert(sawSet == 444);
1326+
ASSERT(PySys_AuditTuple("_testembed.set", tuple) == 0, 10);
1327+
ASSERT(!PyErr_Occurred(), 11);
1328+
ASSERT(sawSet == 444, 12);
13201329
Py_DECREF(tuple);
13211330

13221331
// pass Python int object
13231332
PyObject *int_arg = PyLong_FromLong(555);
13241333
if (int_arg == NULL) {
13251334
goto error;
13261335
}
1327-
assert(PySys_AuditTuple("_testembed.set", int_arg) == -1);
1328-
assert(PyErr_ExceptionMatches(PyExc_TypeError));
1336+
ASSERT(PySys_AuditTuple("_testembed.set", int_arg) == -1, 20);
1337+
ASSERT(PyErr_ExceptionMatches(PyExc_TypeError), 21);
13291338
PyErr_Clear();
13301339
Py_DECREF(int_arg);
13311340

13321341
// NULL is accepted and means "no arguments"
1333-
assert(PySys_AuditTuple("_testembed.test_audit_tuple", NULL) == 0);
1334-
assert(!PyErr_Occurred());
1342+
ASSERT(PySys_AuditTuple("_testembed.test_audit_tuple", NULL) == 0, 30);
1343+
ASSERT(!PyErr_Occurred(), 31);
13351344

13361345
Py_Finalize();
13371346
return 0;
13381347

13391348
error:
13401349
PyErr_Print();
13411350
return 1;
1351+
1352+
#undef ASSERT
13421353
}
13431354

13441355
static volatile int _audit_subinterpreter_interpreter_count = 0;

0 commit comments

Comments
 (0)