update some tests and added a little to the docs

This commit is contained in:
Kolten Pearson 2023-06-03 21:23:01 -06:00
parent 6ffcbce647
commit 897362075b
4 changed files with 17 additions and 19 deletions

View File

@ -562,4 +562,4 @@ void* pkpy_get_id(pkpy_vm* vm_handle, int index) {
PyObject* o = vm->c_data->at(index); PyObject* o = vm->c_data->at(index);
if(is_tagged(o)) return nullptr; if(is_tagged(o)) return nullptr;
return (void*) o; return (void*) o;
} }

View File

@ -71,7 +71,7 @@ int test_return_none(pkpy_vm* vm) {
} }
int test_error_propagate(pkpy_vm* vm) { int test_error_propagate(pkpy_vm* vm) {
pkpy_get_global(vm, "does not exist"); pkpy_error(vm, "NameError", "catch me");
return 1; return 1;
} }
@ -307,10 +307,8 @@ int main(int argc, char** argv) {
// testing code going to standard error, can ignore next error // testing code going to standard error, can ignore next error
pkpy_clear_error(vm, NULL); pkpy_clear_error(vm, NULL);
//with the current way execptions are handled, this will fail and pass the //errors
//error clean through, ignoring the python handling //this should be catchable
//
//maybe worth fixing someday, but for now it is functionating as implemented
check(pkpy_vm_run(vm, "try : test_error_propagate(); except NameError : pass")); check(pkpy_vm_run(vm, "try : test_error_propagate(); except NameError : pass"));
error(pkpy_error(vm, "_", "test direct error mechanism")); error(pkpy_error(vm, "_", "test direct error mechanism"));
@ -330,10 +328,10 @@ int main(int argc, char** argv) {
//at such a time this interferes with a real world use case of the bindings //at such a time this interferes with a real world use case of the bindings
//we can revisit it //we can revisit it
// //
check(pkpy_vm_run(vm, "def error_from_python() : raise NotImplementedError()")); //check(pkpy_vm_run(vm, "def error_from_python() : raise NotImplementedError()"));
check(pkpy_push_function(vm, test_nested_error, 0)); //check(pkpy_push_function(vm, test_nested_error, 0));
check(pkpy_set_global(vm, "test_nested_error")); //check(pkpy_set_global(vm, "test_nested_error"));
error(pkpy_vm_run(vm, "test_nested_error()")); //error(pkpy_vm_run(vm, "test_nested_error()"));
check(pkpy_vm_run(vm, "import math")); check(pkpy_vm_run(vm, "import math"));
check(pkpy_get_global(vm, "math")); check(pkpy_get_global(vm, "math"));
@ -353,6 +351,10 @@ int main(int argc, char** argv) {
check(pkpy_setattr(vm, "pi")); check(pkpy_setattr(vm, "pi"));
check(pkpy_vm_run(vm, "print(math.pi)")); check(pkpy_vm_run(vm, "print(math.pi)"));
pkpy_vm_destroy(vm);
//should give a type error
check(pkpy_push_float(vm, 2.0));
error(pkpy_to_int(vm, -1, &r_int));
return 0; return 0;
} }

View File

@ -54,7 +54,7 @@ successfully errored with this message:
Traceback (most recent call last): Traceback (most recent call last):
File "<c-bound>", line 1 File "<c-bound>", line 1
test_error_propagate() test_error_propagate()
NameError: does not exist NameError: catch me
successfully errored with this message: successfully errored with this message:
Traceback (most recent call last): Traceback (most recent call last):
File "<c-bound>", line 1 File "<c-bound>", line 1
@ -63,13 +63,8 @@ NameError: testing error throwing from python
successfully errored with this message: successfully errored with this message:
Traceback (most recent call last): Traceback (most recent call last):
_: test direct error mechanism _: test direct error mechanism
successfully errored with this message:
Traceback (most recent call last):
File "<c-bound>", line 1
test_nested_error()
File "<c-bound>", line 1
def error_from_python() : raise NotImplementedError()
NotImplementedError
pi: 3.14 pi: 3.14
pi: 3.14 pi: 3.14
2 2
successfully errored with this message:
TypeError: expected 'int', but got 'float'

View File

@ -17,6 +17,7 @@ Pop `n` items from the stack.
#### `bool pkpy_push_function(pkpy_vm*, pkpy_function, int argc)` #### `bool pkpy_push_function(pkpy_vm*, pkpy_function, int argc)`
Push a function onto the stack. The function is of `typedef int (*pkpy_function)(pkpy_vm*);` Push a function onto the stack. The function is of `typedef int (*pkpy_function)(pkpy_vm*);`
The provided function should return the number of return values it leaves on the stack
#### `bool pkpy_push_int(pkpy_vm*, int)` #### `bool pkpy_push_int(pkpy_vm*, int)`