Skip to content

Commit 84ab9cf

Browse files
committed
coverage: Expand mp_printf coverage.
Test l and ll sized objects. Ensure hex test values have a letter so 'x' vs 'X' is tested. Test p and P pointer printing. Signed-off-by: Jeff Epler <jepler@gmail.com>
1 parent 6fd38ff commit 84ab9cf

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

ports/unix/coverage.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,20 @@ static mp_obj_t extra_coverage(void) {
204204
mp_printf(&mp_plat_print, "%d %+d % d\n", -123, 123, 123); // sign
205205
mp_printf(&mp_plat_print, "%05d\n", -123); // negative number with zero padding
206206
mp_printf(&mp_plat_print, "%ld\n", 123); // long
207-
mp_printf(&mp_plat_print, "%lx\n", 0x123); // long hex
208-
mp_printf(&mp_plat_print, "%X\n", 0x1abcdef); // capital hex
207+
mp_printf(&mp_plat_print, "%lx\n", 0x123fl); // long hex
208+
mp_printf(&mp_plat_print, "%lX\n", 0x123fl); // capital long hex
209+
#if ((ULLONG_MAX >> 17) >> 17) != 0
210+
mp_printf(&mp_plat_print, "%llx\n", LLONG_MAX); // long long hex
211+
mp_printf(&mp_plat_print, "%llX\n", LLONG_MAX); // capital long long hex
212+
mp_printf(&mp_plat_print, "%llu\n", ULLONG_MAX); // unsigned long long
213+
#else
214+
// fake for platforms without 64-bit long long ints
215+
mp_printf(&mp_plat_print, "7fffffffffffffff\n", LLONG_MAX);
216+
mp_printf(&mp_plat_print, "7FFFFFFFFFFFFFFF\n", LLONG_MAX);
217+
mp_printf(&mp_plat_print, "18446744073709551615\n", ULLONG_MAX);
218+
#endif
219+
mp_printf(&mp_plat_print, "%p\n", (void *)0x789f); // pointer
220+
mp_printf(&mp_plat_print, "%P\n", (void *)0x789f); // pointer uppercase
209221
mp_printf(&mp_plat_print, "%.2s %.3s '%4.4s' '%5.5q' '%.3q'\n", "abc", "abc", "abc", MP_QSTR_True, MP_QSTR_True); // fixed string precision
210222
mp_printf(&mp_plat_print, "%.*s\n", -1, "abc"); // negative string precision
211223
mp_printf(&mp_plat_print, "%b %b\n", 0, 1); // bools
@@ -216,8 +228,8 @@ static mp_obj_t extra_coverage(void) {
216228
#endif
217229
mp_printf(&mp_plat_print, "%d\n", 0x80000000); // should print signed
218230
mp_printf(&mp_plat_print, "%u\n", 0x80000000); // should print unsigned
219-
mp_printf(&mp_plat_print, "%x\n", 0x80000000); // should print unsigned
220-
mp_printf(&mp_plat_print, "%X\n", 0x80000000); // should print unsigned
231+
mp_printf(&mp_plat_print, "%x\n", 0x8000000f); // should print unsigned
232+
mp_printf(&mp_plat_print, "%X\n", 0x8000000f); // should print unsigned
221233
mp_printf(&mp_plat_print, "abc\n%"); // string ends in middle of format specifier
222234
mp_printf(&mp_plat_print, "%%\n"); // literal % character
223235
mp_printf(&mp_plat_print, ".%-3s.\n", "a"); // left adjust
@@ -505,7 +517,7 @@ static mp_obj_t extra_coverage(void) {
505517
mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), mp_obj_new_str_from_cstr("abc"), mp_obj_new_str_from_cstr("abc"));
506518

507519
// mp_obj_int_get_checked with mp_obj_int_t that has a value that is a small integer
508-
mp_printf(&mp_plat_print, "%d\n", mp_obj_int_get_checked(mp_obj_int_new_mpz()));
520+
mp_printf(&mp_plat_print, "%d\n", mp_obj_int_get_checked(MP_OBJ_FROM_PTR(mp_obj_int_new_mpz())));
509521

510522
// mp_obj_int_get_uint_checked with non-negative small-int
511523
mp_printf(&mp_plat_print, "%d\n", (int)mp_obj_int_get_uint_checked(MP_OBJ_NEW_SMALL_INT(1)));
@@ -844,7 +856,7 @@ static mp_obj_t extra_coverage(void) {
844856
mp_obj_streamtest_t *s2 = mp_obj_malloc(mp_obj_streamtest_t, &mp_type_stest_textio2);
845857

846858
// return a tuple of data for testing on the Python side
847-
mp_obj_t items[] = {(mp_obj_t)&str_no_hash_obj, (mp_obj_t)&bytes_no_hash_obj, MP_OBJ_FROM_PTR(s), MP_OBJ_FROM_PTR(s2)};
859+
mp_obj_t items[] = {MP_OBJ_FROM_PTR(&str_no_hash_obj), MP_OBJ_FROM_PTR(&bytes_no_hash_obj), MP_OBJ_FROM_PTR(s), MP_OBJ_FROM_PTR(s2)};
848860
return mp_obj_new_tuple(MP_ARRAY_SIZE(items), items);
849861
}
850862
MP_DEFINE_CONST_FUN_OBJ_0(extra_coverage_obj, extra_coverage);

tests/ports/unix/extra_coverage.py.exp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22
-123 +123 123
33
-0123
44
123
5-
123
6-
1ABCDEF
5+
123f
6+
123F
7+
7fffffffffffffff
8+
7FFFFFFFFFFFFFFF
9+
18446744073709551615
10+
789f
11+
789F
712
ab abc ' abc' ' True' 'Tru'
813

914
false true
1015
(null)
1116
-2147483648
1217
2147483648
13-
80000000
14-
80000000
18+
8000000f
19+
8000000F
1520
abc
1621
%
1722
.a .

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy