Просмотр исходного кода

update some tests and added a little to the docs

Kolten Pearson 2 лет назад
Родитель
Сommit
897362075b
4 измененных файлов с 17 добавлено и 19 удалено
  1. 1 1
      c_bindings/pocketpy_c.cpp
  2. 12 10
      c_bindings/test.c
  3. 3 8
      c_bindings/test_answers.txt
  4. 1 0
      docs/LuaC-API/stack.md

+ 1 - 1
c_bindings/pocketpy_c.cpp

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

+ 12 - 10
c_bindings/test.c

@@ -71,7 +71,7 @@ int test_return_none(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;
 }
 
@@ -307,10 +307,8 @@ int main(int argc, char** argv) {
     // testing code going to standard error, can ignore next error
     pkpy_clear_error(vm, NULL);
 
-    //with the current way execptions are handled, this will fail and pass the
-    //error clean through, ignoring the python handling
-    //
-    //maybe worth fixing someday, but for now it is functionating as implemented
+    //errors
+    //this should be catchable
     check(pkpy_vm_run(vm, "try : test_error_propagate(); except NameError : pass"));
 
     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
     //we can revisit it
     //
-    check(pkpy_vm_run(vm, "def error_from_python() : raise NotImplementedError()"));
-    check(pkpy_push_function(vm, test_nested_error, 0));
-    check(pkpy_set_global(vm, "test_nested_error"));
-    error(pkpy_vm_run(vm, "test_nested_error()"));
+    //check(pkpy_vm_run(vm, "def error_from_python() : raise NotImplementedError()"));
+    //check(pkpy_push_function(vm, test_nested_error, 0));
+    //check(pkpy_set_global(vm, "test_nested_error"));
+    //error(pkpy_vm_run(vm, "test_nested_error()"));
 
     check(pkpy_vm_run(vm, "import math"));
     check(pkpy_get_global(vm, "math"));
@@ -353,6 +351,10 @@ int main(int argc, char** argv) {
     check(pkpy_setattr(vm, "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;
 }

+ 3 - 8
c_bindings/test_answers.txt

@@ -54,7 +54,7 @@ successfully errored with this message:
 Traceback (most recent call last):
   File "<c-bound>", line 1
     test_error_propagate()
-NameError: does not exist
+NameError: catch me
 successfully errored with this message: 
 Traceback (most recent call last):
   File "<c-bound>", line 1
@@ -63,13 +63,8 @@ NameError: testing error throwing from python
 successfully errored with this message: 
 Traceback (most recent call last):
 _: 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
 2
+successfully errored with this message: 
+TypeError: expected 'int', but got 'float'

+ 1 - 0
docs/LuaC-API/stack.md

@@ -17,6 +17,7 @@ Pop `n` items from the stack.
 #### `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*);`
+The provided function should return the number of return values it leaves on the stack 
 
 #### `bool pkpy_push_int(pkpy_vm*, int)`