tests/unix/extra_coverage: Add test for str/bytes with invalid hash.
This commit is contained in:
parent
5f3bda422a
commit
58f3861358
@ -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')))
|
||||
|
@ -35,3 +35,8 @@ ementation
|
||||
12345678
|
||||
0
|
||||
0
|
||||
('0123456789', b'0123456789')
|
||||
7300
|
||||
7300
|
||||
7300
|
||||
7300
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user