diff options
-rw-r--r-- | tests/unix/extra_coverage.py | 9 | ||||
-rw-r--r-- | tests/unix/extra_coverage.py.exp | 5 | ||||
-rw-r--r-- | unix/coverage.c | 9 |
3 files changed, 21 insertions, 2 deletions
diff --git a/tests/unix/extra_coverage.py b/tests/unix/extra_coverage.py index 8f330f1da2..72bcc9994a 100644 --- a/tests/unix/extra_coverage.py +++ b/tests/unix/extra_coverage.py @@ -5,4 +5,11 @@ except NameError: import sys sys.exit() -extra_coverage() +data = extra_coverage() + +# test hashing of str/bytes that have an invalid hash +print(data) +print(hash(data[0])) +print(hash(data[1])) +print(hash(bytes(data[0], 'utf8'))) +print(hash(str(data[1], 'utf8'))) diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp index 44749c45ea..ea73a54e4c 100644 --- a/tests/unix/extra_coverage.py.exp +++ b/tests/unix/extra_coverage.py.exp @@ -35,3 +35,8 @@ ementation 12345678 0 0 +('0123456789', b'0123456789') +7300 +7300 +7300 +7300 diff --git a/unix/coverage.c b/unix/coverage.c index ce1da50e2f..c84a653f75 100644 --- a/unix/coverage.c +++ b/unix/coverage.c @@ -1,12 +1,17 @@ #include <stdio.h> #include "py/obj.h" +#include "py/objstr.h" #include "py/runtime.h" #include "py/repl.h" #include "py/mpz.h" #if defined(MICROPY_UNIX_COVERAGE) +// str/bytes objects without a valid hash +STATIC const mp_obj_str_t str_no_hash_obj = {{&mp_type_str}, 0, 10, (const byte*)"0123456789"}; +STATIC const mp_obj_str_t bytes_no_hash_obj = {{&mp_type_bytes}, 0, 10, (const byte*)"0123456789"}; + // function to run extra tests for things that can't be checked by scripts STATIC mp_obj_t extra_coverage(void) { // mp_printf (used by ports that don't have a native printf) @@ -109,7 +114,9 @@ STATIC mp_obj_t extra_coverage(void) { mp_printf(&mp_plat_print, "%d\n", mpz_as_uint_checked(&mpz, &value)); } - return mp_const_none; + // return a tuple of data for testing on the Python side + mp_obj_t items[] = {(mp_obj_t)&str_no_hash_obj, (mp_obj_t)&bytes_no_hash_obj}; + return mp_obj_new_tuple(MP_ARRAY_SIZE(items), items); } MP_DEFINE_CONST_FUN_OBJ_0(extra_coverage_obj, extra_coverage); |