5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
28 Test SWIG behavior with a live, installed SWIG.
36 # swig-python expects specific filenames.
37 # the platform specific suffix won't necessarily work.
38 if sys.platform == 'win32':
43 test = TestSCons.TestSCons()
45 swig = test.where_is('swig')
47 test.skip_test('Can not find installed "swig", skipping test.\n')
49 python, python_include, python_libpath, python_lib = \
50 test.get_platform_python_info()
51 Python_h = os.path.join(python_include, 'Python.h')
52 if not os.path.exists(Python_h):
53 test.skip_test('Can not find %s, skipping test.\n' % Python_h)
55 # handle testing on other platforms:
58 test.write("wrapper.py",
61 open('%s', 'wb').write("wrapper.py\\n")
62 os.system(" ".join(sys.argv[1:]))
63 """ % test.workpath('wrapper.out').replace('\\', '\\\\'))
65 test.write('SConstruct', """\
66 foo = Environment(SWIGFLAGS='-python',
67 CPPPATH=[r'%(python_include)s'],
68 LDMODULEPREFIX='%(ldmodule_prefix)s',
69 LDMODULESUFFIX='%(_dll)s',
71 LIBPATH=[r'%(python_libpath)s'],
72 LIBS='%(python_lib)s',
76 if sys.version[0] == '1':
77 # SWIG requires the -classic flag on pre-2.0 Python versions.
78 foo.Append(SWIGFLAGS = ' -classic')
80 swig = foo.Dictionary('SWIG')
81 bar = foo.Clone(SWIG = [r'%(python)s', 'wrapper.py', swig])
82 foo.LoadableModule(target = 'foo', source = ['foo.c', 'foo.i'])
83 bar.LoadableModule(target = 'bar', source = ['bar.c', 'bar.i'])
86 test.write("foo.c", """\
90 return "This is foo.c!";
94 test.write("foo.i", """\
97 /* Put header files here (optional) */
99 * This duplication shouldn't be necessary, I guess, but it seems
100 * to suppress "cast to pointer from integer of different size"
101 * warning messages on some systems.
103 extern char *foo_string();
106 extern char *foo_string();
109 test.write("bar.c", """\
113 return "This is bar.c!";
117 test.write("bar.i", """\
120 /* Put header files here (optional) */
122 * This duplication shouldn't be necessary, I guess, but it seems
123 * to suppress "cast to pointer from integer of different size"
124 * warning messages on some systems.
126 extern char *bar_string();
129 extern char *bar_string();
132 test.run(arguments = ldmodule_prefix+'foo' + _dll)
134 test.must_not_exist(test.workpath('wrapper.out'))
136 test.run(program = python, stdin = """\
138 print foo.foo_string()
143 test.up_to_date(arguments = ldmodule_prefix+'foo' + _dll)
145 test.run(arguments = ldmodule_prefix+'bar' + _dll)
147 test.must_match('wrapper.out', "wrapper.py\n")
149 test.run(program = python, stdin = """\
152 print foo.foo_string()
153 print bar.bar_string()
159 test.up_to_date(arguments = '.')
166 # indent-tabs-mode:nil
168 # vim: set expandtab tabstop=4 shiftwidth=4: