summaryrefslogtreecommitdiff
path: root/test/Chmod.py
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2004-04-19 03:33:01 +0000
committerSteven Knight <knight@baldmt.com>2004-04-19 03:33:01 +0000
commit4573f82503e4ea29b53390a6036ebc2c5d424c86 (patch)
treec557752339d4b183d7f6105b165b785aafddcac6 /test/Chmod.py
parent2b875f31e86ca90efb76fd81009876fc57266d31 (diff)
downloadscons-4573f82503e4ea29b53390a6036ebc2c5d424c86.tar.gz
Ant-like tasks: Chmod(), Copy(), Delete(), Mkdir(), Move(), Touch().
Diffstat (limited to 'test/Chmod.py')
-rw-r--r--test/Chmod.py133
1 files changed, 133 insertions, 0 deletions
diff --git a/test/Chmod.py b/test/Chmod.py
new file mode 100644
index 00000000..517b83d3
--- /dev/null
+++ b/test/Chmod.py
@@ -0,0 +1,133 @@
+#!/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 Chmod() Action works.
+"""
+
+import os
+import os.path
+import stat
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """
+Execute(Chmod('f1', 0777))
+Execute(Chmod('d2', 0777))
+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()
+Cat = Action(cat)
+env = Environment()
+env.Command('bar.out', 'bar.in', [Cat,
+ Chmod("f3", 0755),
+ Chmod("d4", 0755)])
+env = Environment(FILE = 'f5')
+env.Command('f6.out', 'f6.in', [Chmod('$FILE', 0775), Cat])
+env.Command('f7.out', 'f7.in', [Cat,
+ Chmod('Chmod-$SOURCE', 0775),
+ Chmod('${TARGET}-Chmod', 0775)])
+""")
+
+test.write('f1', "f1\n")
+test.subdir('d2')
+test.write(['d2', 'file'], "d2/file\n")
+test.write('bar.in', "bar.in\n")
+test.write('f3', "f3\n")
+test.subdir('d4')
+test.write(['d4', 'file'], "d4/file\n")
+test.write('f5', "f5\n")
+test.write('f6.in', "f6.in\n")
+test.write('f7.in', "f7.in\n")
+test.write('Chmod-f7.in', "Chmod-f7.in\n")
+test.write('f7.out-Chmod', "f7.out-Chmod\n")
+
+os.chmod(test.workpath('f1'), 0700)
+os.chmod(test.workpath('d2'), 0700)
+os.chmod(test.workpath('f3'), 0700)
+os.chmod(test.workpath('d4'), 0700)
+os.chmod(test.workpath('f5'), 0700)
+os.chmod(test.workpath('Chmod-f7.in'), 0700)
+os.chmod(test.workpath('f7.out-Chmod'), 0700)
+
+expect = test.wrap_stdout(read_str = 'Chmod("f1", 0777)\nChmod("d2", 0777)\n',
+ build_str = """\
+cat("bar.out", "bar.in")
+Chmod("f3", 0755)
+Chmod("d4", 0755)
+Chmod("f5", 0775)
+cat("f6.out", "f6.in")
+cat("f7.out", "f7.in")
+Chmod("Chmod-f7.in", 0775)
+Chmod("f7.out-Chmod", 0775)
+""")
+test.run(options = '-n', arguments = '.', stdout = expect)
+
+s = stat.S_IMODE(os.stat(test.workpath('f1'))[stat.ST_MODE])
+test.fail_test(s != 0700)
+s = stat.S_IMODE(os.stat(test.workpath('d2'))[stat.ST_MODE])
+test.fail_test(s != 0700)
+test.must_not_exist('bar.out')
+s = stat.S_IMODE(os.stat(test.workpath('f3'))[stat.ST_MODE])
+test.fail_test(s != 0700)
+s = stat.S_IMODE(os.stat(test.workpath('d4'))[stat.ST_MODE])
+test.fail_test(s != 0700)
+s = stat.S_IMODE(os.stat(test.workpath('f5'))[stat.ST_MODE])
+test.fail_test(s != 0700)
+test.must_not_exist('f6.out')
+test.must_not_exist('f7.out')
+s = stat.S_IMODE(os.stat(test.workpath('Chmod-f7.in'))[stat.ST_MODE])
+test.fail_test(s != 0700)
+s = stat.S_IMODE(os.stat(test.workpath('f7.out-Chmod'))[stat.ST_MODE])
+test.fail_test(s != 0700)
+
+test.run()
+
+s = stat.S_IMODE(os.stat(test.workpath('f1'))[stat.ST_MODE])
+test.fail_test(s != 0777)
+s = stat.S_IMODE(os.stat(test.workpath('d2'))[stat.ST_MODE])
+test.fail_test(s != 0777)
+test.must_match('bar.out', "bar.in\n")
+s = stat.S_IMODE(os.stat(test.workpath('f3'))[stat.ST_MODE])
+test.fail_test(s != 0755)
+s = stat.S_IMODE(os.stat(test.workpath('d4'))[stat.ST_MODE])
+test.fail_test(s != 0755)
+s = stat.S_IMODE(os.stat(test.workpath('f5'))[stat.ST_MODE])
+test.fail_test(s != 0775)
+test.must_match('f6.out', "f6.in\n")
+test.must_match('f7.out', "f7.in\n")
+s = stat.S_IMODE(os.stat(test.workpath('Chmod-f7.in'))[stat.ST_MODE])
+test.fail_test(s != 0775)
+s = stat.S_IMODE(os.stat(test.workpath('f7.out-Chmod'))[stat.ST_MODE])
+test.fail_test(s != 0775)
+
+test.pass_test()