summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdam J. Stewart <ajstewart426@gmail.com>2017-12-31 01:55:49 -0500
committerTodd Gamblin <tgamblin@llnl.gov>2017-12-30 22:55:49 -0800
commit05ce8407af2075ebcc002583b4224659d19dc9db (patch)
tree7b7d0d3a701cba5d70fec7ffe57d57b237426e51 /lib
parent088c193a785ec5199195f32b99d4adc4028b54c1 (diff)
downloadspack-05ce8407af2075ebcc002583b4224659d19dc9db.tar.gz
spack-05ce8407af2075ebcc002583b4224659d19dc9db.tar.bz2
spack-05ce8407af2075ebcc002583b4224659d19dc9db.tar.xz
spack-05ce8407af2075ebcc002583b4224659d19dc9db.zip
Add unit tests for spack help command (#6779)
* Add unit tests for spack help command * Work around issue with using `spack help` twice in tests
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/cmd/help.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/lib/spack/spack/test/cmd/help.py b/lib/spack/spack/test/cmd/help.py
new file mode 100644
index 0000000000..d4f914fcde
--- /dev/null
+++ b/lib/spack/spack/test/cmd/help.py
@@ -0,0 +1,75 @@
+##############################################################################
+# Copyright (c) 2013-2017, Lawrence Livermore National Security, LLC.
+# Produced at the Lawrence Livermore National Laboratory.
+#
+# This file is part of Spack.
+# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
+# LLNL-CODE-647188
+#
+# For details, see https://github.com/spack/spack
+# Please also see the NOTICE and LICENSE files 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 Lesser General Public License (as
+# published by the Free Software Foundation) version 2.1, 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 Lesser 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
+##############################################################################
+import pytest
+
+from spack.main import SpackCommand
+
+
+@pytest.mark.xfail
+def test_reuse_after_help():
+ """Test `spack help` can be called twice with the same SpackCommand."""
+ help_cmd = SpackCommand('help')
+ help_cmd()
+
+ # This second invocation will somehow fail because the parser no
+ # longer works after add_all_commands() is called in
+ # SpackArgumentParser.format_help_sections().
+ #
+ # TODO: figure out why this doesn't work properly and change this
+ # test to use a single SpackCommand.
+ #
+ # It seems that parse_known_args() finds "too few arguments" the
+ # second time through b/c add_all_commands() ends up leaving extra
+ # positionals in the parser. But this used to work before we loaded
+ # commands lazily.
+ help_cmd()
+
+
+def test_help():
+ """Sanity check the help command to make sure it works."""
+ help_cmd = SpackCommand('help')
+ out = help_cmd()
+ assert 'These are common spack commands:' in out
+
+
+def test_help_all():
+ """Test the spack help --all flag"""
+ help_cmd = SpackCommand('help')
+ out = help_cmd('--all')
+ assert 'Complete list of spack commands:' in out
+
+
+def test_help_spec():
+ """Test the spack help --spec flag"""
+ help_cmd = SpackCommand('help')
+ out = help_cmd('--spec')
+ assert 'spec expression syntax:' in out
+
+
+def test_help_subcommand():
+ """Test the spack help subcommand argument"""
+ help_cmd = SpackCommand('help')
+ out = help_cmd('help')
+ assert 'get help on spack and its commands' in out