summaryrefslogtreecommitdiffstats
path: root/test/Glob
diff options
context:
space:
mode:
Diffstat (limited to 'test/Glob')
-rw-r--r--test/Glob/BuildDir.py71
-rw-r--r--test/Glob/Repository.py117
-rw-r--r--test/Glob/basic.py59
-rw-r--r--test/Glob/source.py88
-rw-r--r--test/Glob/strings.py72
-rw-r--r--test/Glob/subdir.py60
-rw-r--r--test/Glob/subst.py60
7 files changed, 527 insertions, 0 deletions
diff --git a/test/Glob/BuildDir.py b/test/Glob/BuildDir.py
new file mode 100644
index 0000000..274ca49
--- /dev/null
+++ b/test/Glob/BuildDir.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Verify that default use of the Glob() function within a BuildDir()
+finds the local file Nodes.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.subdir('src')
+
+test.write('SConstruct', """\
+BuildDir('var1', 'src')
+BuildDir('var2', 'src')
+
+SConscript('var1/SConscript')
+SConscript('var2/SConscript')
+""")
+
+test.write(['src', 'SConscript'], """\
+env = Environment()
+
+def concatenate(target, source, env):
+ fp = open(str(target[0]), 'wb')
+ for s in source:
+ fp.write(open(str(s), 'rb').read())
+ fp.close()
+
+env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
+
+f_in = Glob('f*.in')
+f_in.sort(lambda a,b: cmp(a.name, b.name))
+env.Concatenate('f.out', f_in)
+""")
+
+test.write(['src', 'f1.in'], "src/f1.in\n")
+test.write(['src', 'f2.in'], "src/f2.in\n")
+test.write(['src', 'f3.in'], "src/f3.in\n")
+
+test.run(arguments = '.')
+
+test.must_match(['var1', 'f.out'], "src/f1.in\nsrc/f2.in\nsrc/f3.in\n")
+test.must_match(['var2', 'f.out'], "src/f1.in\nsrc/f2.in\nsrc/f3.in\n")
+
+test.pass_test()
diff --git a/test/Glob/Repository.py b/test/Glob/Repository.py
new file mode 100644
index 0000000..6cef443
--- /dev/null
+++ b/test/Glob/Repository.py
@@ -0,0 +1,117 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Verify that the Glob() function finds files in repositories.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.subdir('work',
+ 'repository',
+ ['repository', 'src'],
+ ['repository', 'src', 'sub1'],
+ ['repository', 'src', 'sub2'])
+
+work_aaa = test.workpath('work', 'aaa')
+work_bbb = test.workpath('work', 'bbb')
+work_ccc = test.workpath('work', 'ccc')
+work_src_xxx = test.workpath('work', 'src', 'xxx')
+work_src_yyy = test.workpath('work', 'src', 'yyy')
+
+opts = "-Y " + test.workpath('repository')
+
+test.write(['repository', 'SConstruct'], """\
+def cat(env, source, target):
+ target = str(target[0])
+ source = map(str, source)
+ f = open(target, "wb")
+ for src in source:
+ f.write(open(src, "rb").read())
+ f.close()
+
+env = Environment(BUILDERS={'Build':Builder(action=cat)})
+env.Build('aaa.out', Glob('a*.in'))
+env.Build('bbb.out', Glob('b*.in'))
+env.Build('ccc.out', Glob('c*.in'))
+SConscript('src/SConscript', "env")
+""")
+
+test.write(['repository', 'aaa.in'], "repository/aaa.in\n")
+test.write(['repository', 'bbb.in'], "repository/bbb.in\n")
+test.write(['repository', 'ccc.in'], "repository/ccc.in\n")
+
+test.write(['repository', 'src', 'SConscript'], """
+Import("env")
+env.Build('xxx.out', Glob('x*.in'))
+env.Build('yyy.out', Glob('yy?.in'))
+zzz_in = Glob('*/zzz.in')
+zzz_in.sort(lambda a,b: cmp(a.abspath, b.abspath))
+env.Build('zzz.out', zzz_in)
+""")
+
+test.write(['repository', 'src', 'xxx.in'], "repository/src/xxx.in\n")
+test.write(['repository', 'src', 'yyy.in'], "repository/src/yyy.in\n")
+test.write(['repository', 'src', 'sub1', 'zzz.in'], "repository/src/sub1/zzz.in\n")
+test.write(['repository', 'src', 'sub2', 'zzz.in'], "repository/src/sub2/zzz.in\n")
+
+#
+# Make the repository non-writable,
+# so we'll detect if we try to write into it accidentally.
+test.writable('repository', 0)
+
+#
+test.run(chdir = 'work', options = opts, arguments = 'aaa.out')
+
+test.must_match(['work', 'aaa.out'], "repository/aaa.in\n")
+test.must_not_exist(test.workpath('work', 'bbb.out'))
+test.must_not_exist(test.workpath('work', 'ccc.out'))
+test.must_not_exist(test.workpath('work', 'src', 'xxx.out'))
+test.must_not_exist(test.workpath('work', 'src', 'yyy.out'))
+
+test.run(chdir = 'work', options = opts, arguments = 'bbb.out src')
+
+test.must_match(['work', 'bbb.out'], "repository/bbb.in\n")
+test.must_not_exist(test.workpath('work', 'ccc.out'))
+test.must_match(['work', 'src', 'xxx.out'], "repository/src/xxx.in\n")
+test.must_match(['work', 'src', 'yyy.out'], "repository/src/yyy.in\n")
+
+expect = """\
+repository/src/sub1/zzz.in
+repository/src/sub2/zzz.in
+"""
+
+test.must_match(['work', 'src', 'zzz.out'], expect)
+
+#
+test.run(chdir = 'work', options = opts, arguments = '.')
+
+test.must_match(['work', 'ccc.out'], "repository/ccc.in\n")
+
+#
+test.pass_test()
diff --git a/test/Glob/basic.py b/test/Glob/basic.py
new file mode 100644
index 0000000..2e7427a
--- /dev/null
+++ b/test/Glob/basic.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Verify basic operation of the Glob() function.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """\
+env = Environment()
+
+def concatenate(target, source, env):
+ fp = open(str(target[0]), 'wb')
+ for s in source:
+ fp.write(open(str(s), 'rb').read())
+ fp.close()
+
+env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
+
+f_in = Glob('f*.in')
+f_in.sort(lambda a,b: cmp(a.name, b.name))
+env.Concatenate('f.out', f_in)
+""")
+
+test.write('f1.in', "f1.in\n")
+test.write('f2.in', "f2.in\n")
+test.write('f3.in', "f3.in\n")
+
+test.run(arguments = '.')
+
+test.must_match('f.out', "f1.in\nf2.in\nf3.in\n")
+
+test.pass_test()
diff --git a/test/Glob/source.py b/test/Glob/source.py
new file mode 100644
index 0000000..b82e1d9
--- /dev/null
+++ b/test/Glob/source.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Verify that use of the Glob() function within a BuildDir() returns the
+file Nodes in the source directory when the source= keyword argument is
+specified (and duplicate=0 is specified for the BuildDir()).
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.subdir('src', 'var1', 'var2')
+
+test.write('SConstruct', """\
+env = Environment()
+
+def concatenate(target, source, env):
+ fp = open(str(target[0]), 'wb')
+ for s in source:
+ fp.write(open(str(s), 'rb').read())
+ fp.close()
+
+env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
+
+Export("env")
+
+BuildDir('var1', 'src', duplicate=0)
+BuildDir('var2', 'src', duplicate=0)
+
+SConscript('var1/SConscript')
+SConscript('var2/SConscript')
+""")
+
+test.write(['var1', 'SConscript'], """\
+Import("env")
+
+f_in = Glob('f[45].in', source=True)
+f_in.sort(lambda a,b: cmp(a.name, b.name))
+env.Concatenate('f.out', f_in)
+""")
+
+test.write(['var2', 'SConscript'], """\
+Import("env")
+
+f_in = Glob('f[67].in')
+f_in.sort(lambda a,b: cmp(a.name, b.name))
+env.Concatenate('f.out', f_in)
+""")
+
+test.write(['src', 'f1.in'], "src/f1.in\n")
+test.write(['src', 'f2.in'], "src/f2.in\n")
+
+test.write(['src', 'f4.in'], "src/f4.in\n")
+test.write(['src', 'f5.in'], "src/f5.in\n")
+test.write(['src', 'f6.in'], "src/f6.in\n")
+test.write(['src', 'f7.in'], "src/f7.in\n")
+
+test.run(arguments = '.')
+
+test.must_match(['var1', 'f.out'], "src/f4.in\nsrc/f5.in\n")
+test.must_match(['var2', 'f.out'], "src/f6.in\nsrc/f7.in\n")
+
+test.pass_test()
diff --git a/test/Glob/strings.py b/test/Glob/strings.py
new file mode 100644
index 0000000..d9f8ff1
--- /dev/null
+++ b/test/Glob/strings.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Verify that use of the Glob() function with the strings= option works
+when they're used in the same SConscript file (and therefore the same
+directory) as input to a Builder call.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.subdir('src')
+
+test.write('SConstruct', """\
+BuildDir('var1', 'src')
+BuildDir('var2', 'src')
+
+SConscript('var1/SConscript')
+SConscript('var2/SConscript')
+""")
+
+test.write(['src', 'SConscript'], """\
+env = Environment()
+
+def concatenate(target, source, env):
+ fp = open(str(target[0]), 'wb')
+ for s in source:
+ fp.write(open(str(s), 'rb').read())
+ fp.close()
+
+env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
+
+f_in = Glob('f*.in', strings=True)
+f_in.sort()
+env.Concatenate('f.out', f_in)
+""")
+
+test.write(['src', 'f1.in'], "src/f1.in\n")
+test.write(['src', 'f2.in'], "src/f2.in\n")
+test.write(['src', 'f3.in'], "src/f3.in\n")
+
+test.run(arguments = '.')
+
+test.must_match(['var1', 'f.out'], "src/f1.in\nsrc/f2.in\nsrc/f3.in\n")
+test.must_match(['var2', 'f.out'], "src/f1.in\nsrc/f2.in\nsrc/f3.in\n")
+
+test.pass_test()
diff --git a/test/Glob/subdir.py b/test/Glob/subdir.py
new file mode 100644
index 0000000..b4e89e8
--- /dev/null
+++ b/test/Glob/subdir.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Verify that Glob() works to find Nodes underneath an explicitly-
+named subdirectory.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.subdir('subdir')
+
+test.write('SConstruct', """\
+env = Environment()
+
+def concatenate(target, source, env):
+ fp = open(str(target[0]), 'wb')
+ for s in source:
+ fp.write(open(str(s), 'rb').read())
+ fp.close()
+
+env['BUILDERS']['Concatenate'] = Builder(action=concatenate)
+
+f_in = Glob('subdir/*.in')
+f_in.sort(lambda a,b: cmp(a.name, b.name))
+env.Concatenate('f.out', f_in)
+""")
+
+test.write(['subdir', 'file.in'], "subdir/file.in\n")
+
+test.run(arguments = '.')
+
+test.must_match('f.out', "subdir/file.in\n")
+
+test.pass_test()
diff --git a/test/Glob/subst.py b/test/Glob/subst.py
new file mode 100644
index 0000000..e6aa3ca
--- /dev/null
+++ b/test/Glob/subst.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Verify the ability to Glob() using a pattern from a construction variable
+expansion.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """\
+env = Environment(PATTERN = 'f*.in')
+
+def copy(target, source, env):
+ fp = open(str(target[0]), 'wb')
+ for s in source:
+ fp.write(open(str(s), 'rb').read())
+ fp.close()
+
+env['BUILDERS']['Copy'] = Builder(action=copy)
+
+f_in = env.Glob('$PATTERN')
+f_in.sort(lambda a,b: cmp(a.name, b.name))
+env.Copy('f.out', f_in)
+""")
+
+test.write('f1.in', "f1.in\n")
+test.write('f2.in', "f2.in\n")
+test.write('f3.in', "f3.in\n")
+
+test.run(arguments = '.')
+
+test.must_match('f.out', "f1.in\nf2.in\nf3.in\n")
+
+test.pass_test()