diff options
Diffstat (limited to 't/scripts')
-rwxr-xr-x | t/scripts/RunGuileTests.pl | 36 | ||||
-rw-r--r-- | t/scripts/__init__.py | 0 | ||||
-rw-r--r-- | t/scripts/t2conv.py | 67 | ||||
-rw-r--r-- | t/scripts/t4apply.py | 46 | ||||
-rw-r--r-- | t/scripts/t5smobs.py | 51 | ||||
-rw-r--r-- | t/scripts/t7except.py | 32 | ||||
-rw-r--r-- | t/scripts/test_auxiliary_functions.scm | 177 |
7 files changed, 409 insertions, 0 deletions
diff --git a/t/scripts/RunGuileTests.pl b/t/scripts/RunGuileTests.pl new file mode 100755 index 0000000..a61a18a --- /dev/null +++ b/t/scripts/RunGuileTests.pl @@ -0,0 +1,36 @@ +#!/usr/bin/perl -w +# Run Guile tests - filenames are given as arguments to the script. +######################################################################## +# +# Copyright (C) 2008 Omer Zak. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library, in a file named COPYING; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, +# Boston, MA 02111-1307 USA +# +# For licensing issues, contact <w1@zak.co.il>. +# +######################################################################## + +use strict; +use TAP::Harness; +my @tests = @ARGV; +my %args = ( + verbosity => 0, + timer => 1, + exec => ['/usr/bin/guile', '-s'], + ); +my $harness = TAP::Harness->new( \%args ); + $harness->runtests(@tests); + +# End of RunGuileTests.pl diff --git a/t/scripts/__init__.py b/t/scripts/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/scripts/__init__.py diff --git a/t/scripts/t2conv.py b/t/scripts/t2conv.py new file mode 100644 index 0000000..160c3b6 --- /dev/null +++ b/t/scripts/t2conv.py @@ -0,0 +1,67 @@ +#!/usr/bin/python +# Basic tests to validate conversions from Python to Guile and vice versa. +######################################################################## +# +# Copyright (C) 2008 Omer Zak. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library, in a file named COPYING; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, +# Boston, MA 02111-1307 USA +# +# For licensing issues, contact <w1@zak.co.il>. +# +######################################################################## + +def return_None(): + return None + +def return_True(): + return True + +def return_False(): + return False + +def return_Int1(): + return 1 + +def return_Int_5(): + return(-5) + +def return_BigInt(): + return(1048576*1048576*1048576*32) + +def return_BigInt_neg(): + return(-1048576*1048576*1048576*32) + +def return_String1(): + return("abcdefghi") + +def return_String2(): + return("01abCD%^") + +def return_String_Zero(): + return("bef" + chr(0) + chr(163) + "ore") + +if (__name__ == '__main__'): + print "return_None: ",return_None() + print "return_True: ",return_True() + print "return_False: ",return_False() + print "return_Int1: ",return_Int1() + print "return_Int_5: ",return_Int_5() + print "return_BigInt: ",return_BigInt() + print "return_BigInt_neg: ",return_BigInt_neg() + print "String1: ",return_String1() + print "String2: ",return_String2() + print "String_Zero: ",return_String_Zero(),repr(return_String_Zero()) + +# End of t2conv.py diff --git a/t/scripts/t4apply.py b/t/scripts/t4apply.py new file mode 100644 index 0000000..a716462 --- /dev/null +++ b/t/scripts/t4apply.py @@ -0,0 +1,46 @@ +#!/usr/bin/python +# Auxiliary functions for exercising python-apply. +######################################################################## +# +# Copyright (C) 2008 Omer Zak. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library, in a file named COPYING; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, +# Boston, MA 02111-1307 USA +# +# For licensing issues, contact <w1@zak.co.il>. +# +######################################################################## + +def return_args(*args,**kw): + return("positional: %s keywords: %s" % (repr(args),repr(kw))) + +class cl1(object): + def __init__(self,num=1,str="2"): + self.num = num + self.str = str + + def myfunc(self,arg="x"): + return(arg + self.str) + +class cl2(object): + def __init__(self,num=3): + self.num2 = num + self.mycl1 = cl1(10,str="Twenty") + + def cl2func(self,argx="y"): + return(str(self.num2) + argx) + +mainobj = cl2(33) + +# End of t4apply.py diff --git a/t/scripts/t5smobs.py b/t/scripts/t5smobs.py new file mode 100644 index 0000000..2f4b4a5 --- /dev/null +++ b/t/scripts/t5smobs.py @@ -0,0 +1,51 @@ +#!/usr/bin/python +# Auxiliary functions for exercising pysmobs. +######################################################################## +# +# Copyright (C) 2008 Omer Zak. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library, in a file named COPYING; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, +# Boston, MA 02111-1307 USA +# +# For licensing issues, contact <w1@zak.co.il>. +# +######################################################################## + +class opaq(object): + def __init__(self,arg1): + self.arg1 = arg1 + def transform(self): + self.arg1 = self.arg1 + self.arg1 + def __repr__(self): + return("opaq(%s)" % repr(self.arg1)) + +# Work around temporary problem in PyGuile. +def genopaq(arg): + return(opaq(arg)) + +class noisydelete(object): + def __init__(self,id): + self.id = id + def __del__(self): + print "# Deleting class instance %s" % self.id + #object.__del__() + def __repr__(self): + return(repr(self.id)) + def __cmp__(self,other): + if ((self.id == "me") and (other.id == 42)): + # Want to prove that this function has indeed been exercised. + return(0) + return(cmp(self.id,other.id)) + +# End of t5smobs.py diff --git a/t/scripts/t7except.py b/t/scripts/t7except.py new file mode 100644 index 0000000..d2f6948 --- /dev/null +++ b/t/scripts/t7except.py @@ -0,0 +1,32 @@ +#!/usr/bin/python +# Raising exception inside my own code +######################################################################## +# +# Copyright (C) 2008 Omer Zak. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library, in a file named COPYING; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, +# Boston, MA 02111-1307 USA +# +# For licensing issues, contact <w1@zak.co.il>. +# +######################################################################## + +import exceptions +class myexception(exceptions.Exception): + pass + +def raiser(arg="typical!"): + raise myexception("This is my exception",arg) + +# End of t7except.py diff --git a/t/scripts/test_auxiliary_functions.scm b/t/scripts/test_auxiliary_functions.scm new file mode 100644 index 0000000..f420fab --- /dev/null +++ b/t/scripts/test_auxiliary_functions.scm @@ -0,0 +1,177 @@ +#!/usr/bin/guile -s +!# +; Auxiliary functions, for use by test scripts +; Those functions are used by scripts from 20_* and on. +; Earlier scripts usually define their own versions of the +; functions. +; +; To use the functions, add +; (load "scripts/test_auxliary_functions.scm") +; at the beginning of your test script, after any (use-modules ...) +; calls. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; Copyright (C) 2008 Omer Zak. +; This library is free software; you can redistribute it and/or +; modify it under the terms of the GNU Lesser General Public +; License as published by the Free Software Foundation; either +; version 2.1 of the License, or (at your option) any later version. +; +; This library is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +; Lesser General Public License for more details. +; +; You should have received a copy of the GNU Lesser General Public License +; along with this library, in a file named COPYING; if not, write to the +; Free Software Foundation, Inc., 59 Temple Place, Suite 330, +; Boston, MA 02111-1307 USA +; +; For licensing issues, contact <w1@zak.co.il>. +; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +(use-modules (ice-9 regex)) ; regexp-substitute + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Functions from modules, unlikely to be generally useful +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; from 03_guile2python.t +(define invoke-python-func + (lambda (module func arg) + (python-apply (list module func) (list arg) '()))) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Functions likely to be generally useful +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Miscellaneous data manipulation ; +; functions ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; Returns a 3-element list of booleans. +(define equalities3? + (lambda (obj1 obj2) + (list (eq? obj1 obj2) (eqv? obj1 obj2) (equal? obj1 obj2)))) + +; Does one alist include another alist. +; Inclusion means that all keys of the included alist are in the +; including one, and the corresponding values are equal. +; The equality criteria used here is equal? (for both key and value). +(define alist-properly-included? + (lambda (included includor) + (if (null? included) #t + (let ((key (caar included)) + (value (cdar included)) + (rest (cdr included))) + (let ((includor-ref (assoc key includor))) + (cond ((not includor-ref) #f) + ((not (equal? (cdr includor-ref) value)) #f) + (else (alist-properly-included? rest includor)))))))) + +; Are two alists equal? +(define alist-equal? + (lambda (alista alistb) + (and (alist-properly-included? alista alistb) + (alist-properly-included? alistb alista)))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Modify actual results for easier ; +; comparison to expected results ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; Replace all hex addresses appearing in a string +; by a specific literal. +(define substitute-hex-addresses-for-gggggggg + (lambda (strarg) + (regexp-substitute/global #f + "0x[0-9a-f]{8}" + strarg + 'pre "0xgggggggg" 'post))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Running inside catch harness ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; Run a function, so that anything it writes to the current +; output port is captured, together with its return value. +; The return value to caller of capture-result-output is the +; pair of (return-value . output-string). + +(define capture-result-output + (lambda (func . args) + (let ((stdoutstr #f) + (retval #f)) + (set! stdoutstr + (with-output-to-string + (lambda () (set! retval + (apply func args))))) + (cons retval stdoutstr)))) + +; Run a function in an environment, in which any exceptions +; raised by it are caught; and anything it writes to the +; current output port is captured as well. +; The return value to caller of capture-result-output-catch +; is the pair of (return-value . output-string). +(define capture-result-output-catch + (lambda (func . args) + (let ((output-string #f) + (return-value #f)) + (set! output-string + (with-output-to-string + (lambda () (set! return-value + (catch #t + (lambda () (apply func args)) + (lambda (key . args2) + (object->string (list key args2)))))))) + (cons return-value output-string)))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Functions specific to PyGuile ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; Run python-eval under catch harness. +; template can be #f when no return value is expected, or #t when +; the default template is to be used. +(define catch-python-eval + (lambda (txt template) + (catch #t + (lambda () (python-eval txt template)) + (lambda (key . args) (object->string (list key args)))))) + +; Run python-import under catch harness. +(define catch-python-import + (lambda (arg) + (catch #t + (lambda () (python-import arg)) + (lambda (key . args) (object->string (list key args)))))) + +; Run python-apply under catch harness. +; The positional argument list must be supplied. +; The keyword argument list and the templates are optional. +(define catch-python-apply + (lambda (func posargs . kwargs-templates) + (catch #t + (lambda () (apply python-apply func posargs kwargs-templates)) + (lambda (key . args) (object->string (list key args)))))) + +; The following function is useful for checking how a SCM is +; actually converted into a PyObject using a template. +; The conversion is run under a catch harness. +(define catch-thunk-invoke-python-repr + (lambda (arg . template) + (catch #t + (lambda () + (if (null? template) + (python-apply '("__builtin__" "repr") arg '()) + (python-apply '("__builtin__" "repr") arg '() (car template)))) + (lambda (key . args2) (object->string (list key args2)))))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; End of test_axuliary_functions.scm |