summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2016-03-09 17:01:01 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2016-03-09 17:13:41 -0800
commitf56939c16c36ee946f40571bdc330b432af93cce (patch)
tree52428e6c101efff5f2d6ac104fffd24796b0ab64 /lib
parentca102295657adef7100f638be0dabc0e6d7cf37f (diff)
downloadspack-f56939c16c36ee946f40571bdc330b432af93cce.tar.gz
spack-f56939c16c36ee946f40571bdc330b432af93cce.tar.bz2
spack-f56939c16c36ee946f40571bdc330b432af93cce.tar.xz
spack-f56939c16c36ee946f40571bdc330b432af93cce.zip
Add unit test for sbang patching.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/__init__.py13
-rw-r--r--lib/spack/spack/test/sbang.py93
2 files changed, 100 insertions, 6 deletions
diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py
index 4b9a361d4b..d5d8b64765 100644
--- a/lib/spack/spack/test/__init__.py
+++ b/lib/spack/spack/test/__init__.py
@@ -65,7 +65,8 @@ test_names = ['versions',
'lock',
'database',
'namespace_trie',
- 'yaml']
+ 'yaml',
+ 'sbang']
def list_tests():
@@ -87,20 +88,20 @@ def run(names, outputDir, verbose=False):
"Valid names are:")
colify(sorted(test_names), indent=4)
sys.exit(1)
-
+
tally = Tally()
for test in names:
module = 'spack.test.' + test
print module
-
+
tty.msg("Running test: %s" % test)
-
+
runOpts = ["--with-%s" % spack.test.tally_plugin.Tally.name]
-
+
if outputDir:
xmlOutputFname = "unittests-{0}.xml".format(test)
xmlOutputPath = join_path(outputDir, xmlOutputFname)
- runOpts += ["--with-xunit",
+ runOpts += ["--with-xunit",
"--xunit-file={0}".format(xmlOutputPath)]
argv = [""] + runOpts + [module]
result = nose.run(argv=argv, addplugins=[tally])
diff --git a/lib/spack/spack/test/sbang.py b/lib/spack/spack/test/sbang.py
new file mode 100644
index 0000000000..825bc4be98
--- /dev/null
+++ b/lib/spack/spack/test/sbang.py
@@ -0,0 +1,93 @@
+##############################################################################
+# Copyright (c) 2013-2015, Lawrence Livermore National Security, LLC.
+# Produced at the Lawrence Livermore National Laboratory.
+#
+# This file is part of Spack.
+# Written by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
+# LLNL-CODE-647188
+#
+# For details, see https://github.com/llnl/spack
+# Please also see the LICENSE file for our notice and the LGPL.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License (as published by
+# the Free Software Foundation) version 2.1 dated February 1999.
+#
+# This program 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 terms and
+# conditions of the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##############################################################################
+"""\
+Test that Spack's shebang filtering works correctly.
+"""
+import os
+import unittest
+import tempfile
+import shutil
+
+from llnl.util.filesystem import *
+from spack.hooks.sbang import filter_shebangs_in_directory
+import spack
+
+short_line = "#!/this/is/short/bin/bash\n"
+long_line = "#!/this/" + ('x' * 200) + "/is/long\n"
+sbang_line = '#!/bin/bash %s/bin/sbang\n' % spack.spack_root
+last_line = "last!\n"
+
+class SbangTest(unittest.TestCase):
+ def setUp(self):
+ self.tempdir = tempfile.mkdtemp()
+
+ # make sure we can ignore non-files
+ directory = os.path.join(self.tempdir, 'dir')
+ mkdirp(directory)
+
+ # Script with short shebang
+ self.short_shebang = os.path.join(self.tempdir, 'short')
+ with open(self.short_shebang, 'w') as f:
+ f.write(short_line)
+ f.write(last_line)
+
+ # Script with long shebang
+ self.long_shebang = os.path.join(self.tempdir, 'long')
+ with open(self.long_shebang, 'w') as f:
+ f.write(long_line)
+ f.write(last_line)
+
+ # Script already using sbang.
+ self.has_shebang = os.path.join(self.tempdir, 'shebang')
+ with open(self.has_shebang, 'w') as f:
+ f.write(sbang_line)
+ f.write(long_line)
+ f.write(last_line)
+
+
+ def tearDown(self):
+ shutil.rmtree(self.tempdir, ignore_errors=True)
+
+
+
+ def test_shebang_handling(self):
+ filter_shebangs_in_directory(self.tempdir)
+
+ # Make sure this is untouched
+ with open(self.short_shebang, 'r') as f:
+ self.assertEqual(f.readline(), short_line)
+ self.assertEqual(f.readline(), last_line)
+
+ # Make sure this got patched.
+ with open(self.long_shebang, 'r') as f:
+ self.assertEqual(f.readline(), sbang_line)
+ self.assertEqual(f.readline(), long_line)
+ self.assertEqual(f.readline(), last_line)
+
+ # Make sure this is untouched
+ with open(self.has_shebang, 'r') as f:
+ self.assertEqual(f.readline(), sbang_line)
+ self.assertEqual(f.readline(), long_line)
+ self.assertEqual(f.readline(), last_line)