Skip to content

Commit 7829c6e

Browse files
committed
coverage: Expand mp_printf coverage.
Test l and ll sized objects. When the platform's `mp_int_t` is not 64 bits, dummy values are printed instead so the test result can match across all platforms. 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 7829c6e

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

ports/unix/coverage.c

Lines changed: 36 additions & 4 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 (sizeof(mp_int_t) == 8) {
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 narrower mp_int_t
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+
}
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,11 +228,31 @@ 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
236+
237+
// Check that all kinds of mp_printf arguments are parsed out
238+
// correctly, by having a char argument before and after each main type
239+
// of value that can be formatted.
240+
mp_printf(&mp_plat_print, "%c%%%c\n", '<', '>');
241+
mp_printf(&mp_plat_print, "%c%p%c\n", '<', (void *)0xaaaa, '>');
242+
mp_printf(&mp_plat_print, "%c%b%c\n", '<', true, '>');
243+
mp_printf(&mp_plat_print, "%c%d%c\n", '<', 0xaaaa, '>');
244+
mp_printf(&mp_plat_print, "%c%ld%c\n", '<', 0xaaaal, '>');
245+
mp_printf(&mp_plat_print, "%c" INT_FMT "%c\n", '<', (mp_int_t)0xaaaa, '>');
246+
mp_printf(&mp_plat_print, "%c%s%c\n", '<', "test", '>');
247+
mp_printf(&mp_plat_print, "%c%f%c\n", '<', MICROPY_FLOAT_CONST(1000.), '>');
248+
mp_printf(&mp_plat_print, "%c%q%c\n", '<', (qstr)MP_QSTR_True, '>');
249+
if (sizeof(mp_int_t) == 8) {
250+
mp_printf(&mp_plat_print, "%c%lld%c\n", '<', LLONG_MAX, '>');
251+
} else {
252+
mp_printf(&mp_plat_print, "<9223372036854775807>\n");
253+
}
254+
255+
224256
}
225257

226258
// GC

tests/ports/unix/extra_coverage.py.exp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,34 @@
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 .
23+
<%>
24+
<aaaa>
25+
<true>
26+
<43690>
27+
<43690>
28+
<43690>
29+
<test>
30+
<1000.000000>
31+
<True>
32+
<9223372036854775807>
1833
# GC
1934
0
2035
0

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