88from __future__ import print_function
99
1010from rez .system import system
11- from rez .shells import create_shell
11+ from rez .shells import create_shell , get_shell_types , get_shell_class
1212from rez .resolved_context import ResolvedContext
1313from rez .rex import literal , expandable
14+ from rez .plugin_managers import plugin_manager
1415from rez .utils .execution import ExecutableScriptMode , _get_python_script_files
1516from rez .tests .util import TestBase , TempdirMixin , per_available_shell , \
1617 install_dependent
2627
2728def _stdout (proc ):
2829 out_ , _ = proc .communicate ()
30+ if proc .returncode :
31+ raise RuntimeError (
32+ "The subprocess failed with exitcode %d" % proc .returncode
33+ )
2934 return out_ .strip ()
3035
3136
@@ -52,6 +57,46 @@ def tearDownClass(cls):
5257 def _create_context (cls , pkgs ):
5358 return ResolvedContext (pkgs , caching = False )
5459
60+ def test_aaa_shell_presence (self ):
61+ """Ensure specific shell types are present as loaded plugins.
62+
63+ The env var _REZ_ENSURE_TEST_SHELLS should be set by a CI system (such
64+ as github actions) to make sure the shells we expect to be installed,
65+ are installed, and are getting tested.
66+
67+ Note 'aaa' forces unittest to run this test first.
68+ """
69+ shells = os .getenv ("_REZ_ENSURE_TEST_SHELLS" , "" ).split (',' )
70+ shells = set (x for x in shells if x )
71+
72+ if not shells :
73+ self .skipTest ("Not ensuring presence of shells from explicit list" )
74+ return
75+
76+ # check for missing shells
77+ missing_shells = shells - set (get_shell_types ())
78+ if missing_shells :
79+ raise RuntimeError (
80+ "The following shells should be available for testing but are "
81+ "not present: %r" % list (missing_shells )
82+ )
83+
84+ # check for unavailable shells
85+ for shell in shells :
86+ if not get_shell_class (shell ).is_available ():
87+ raise RuntimeError (
88+ "The shell %r is not available (executable not found)"
89+ % shell
90+ )
91+
92+ # check for shell plugins that failed to load
93+ for (name , reason ) in plugin_manager .get_failed_plugins ("shell" ):
94+ if name in shells :
95+ raise RuntimeError (
96+ "The shell plugin %r failed to load: %s"
97+ % (name , reason )
98+ )
99+
55100 @per_available_shell ()
56101 def test_no_output (self , shell ):
57102 sh = create_shell (shell )
@@ -208,7 +253,7 @@ def _test(txt):
208253 # how it's been configured
209254 #
210255 if sh_out [1 ]:
211- raise Exception ("Command %r failed:\n %s" % (txt , sh_out [1 ]))
256+ raise RuntimeError ("Command %r failed:\n %s" % (txt , sh_out [1 ]))
212257
213258 self .assertEqual (sh_out [0 ].strip (), txt )
214259
@@ -351,6 +396,7 @@ def _print(value):
351396
352397 # Assertions for other environment variable types
353398 from rez .shells import create_shell
399+
354400 sh = create_shell ()
355401 for token in sh .get_all_key_tokens ("WHO" ):
356402 expected_output += [
0 commit comments