Skip to content

Commit 3448e69

Browse files
committed
tests/unix: Add coverage test for new mp_obj_int_get_uint_checked func.
1 parent 176ab99 commit 3448e69

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

ports/unix/coverage.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,29 @@ STATIC mp_obj_t extra_coverage(void) {
334334
mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), MP_OBJ_NEW_SMALL_INT(1), MP_OBJ_NEW_SMALL_INT(1));
335335
// call mp_call_function_2_protected with invalid args
336336
mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), mp_obj_new_str("abc", 3), mp_obj_new_str("abc", 3));
337+
338+
// mp_obj_int_get_uint_checked with non-negative small-int
339+
mp_printf(&mp_plat_print, "%d\n", (int)mp_obj_int_get_uint_checked(MP_OBJ_NEW_SMALL_INT(1)));
340+
341+
// mp_obj_int_get_uint_checked with non-negative big-int
342+
mp_printf(&mp_plat_print, "%d\n", (int)mp_obj_int_get_uint_checked(mp_obj_new_int_from_ll(2)));
343+
344+
// mp_obj_int_get_uint_checked with negative small-int (should raise exception)
345+
nlr_buf_t nlr;
346+
if (nlr_push(&nlr) == 0) {
347+
mp_obj_int_get_uint_checked(MP_OBJ_NEW_SMALL_INT(-1));
348+
nlr_pop();
349+
} else {
350+
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
351+
}
352+
353+
// mp_obj_int_get_uint_checked with negative big-int (should raise exception)
354+
if (nlr_push(&nlr) == 0) {
355+
mp_obj_int_get_uint_checked(mp_obj_new_int_from_ll(-2));
356+
nlr_pop();
357+
} else {
358+
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
359+
}
337360
}
338361

339362
// warning

tests/unix/extra_coverage.py.exp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ data
5454
# runtime utils
5555
TypeError: unsupported type for __abs__: 'str'
5656
TypeError: unsupported types for __divmod__: 'str', 'str'
57+
1
58+
2
59+
OverflowError: overflow converting long int to machine word
60+
OverflowError: overflow converting long int to machine word
5761
Warning: test
5862
# format float
5963
?

0 commit comments

Comments
 (0)