From aa7cb7ce52a6f2dec9a45abec60f1a18eb701639 Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Wed, 5 Jun 2024 19:18:47 +0200 Subject: [PATCH] extend test_run_shell_cmd_with_hooks to check that run_shell_cmd pre hook is triggered sufficiently early --- test/framework/run.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/framework/run.py b/test/framework/run.py index 23fdb562d3..4e8c3816c3 100644 --- a/test/framework/run.py +++ b/test/framework/run.py @@ -1854,6 +1854,32 @@ def post_run_shell_cmd_hook(cmd, *args, **kwargs): ]) self.assertEqual(stdout, expected_stdout) + # also check in dry run mode, to verify that pre-run_shell_cmd hook is triggered sufficiently early + update_build_option('extended_dry_run', True) + + with self.mocked_stdout_stderr(): + run_shell_cmd("make") + stdout = self.get_stdout() + + expected_stdout = '\n'.join([ + "pre-run hook 'make' in %s" % cwd, + ' running shell command "echo make"', + ' (in %s)' % cwd, + '', + ]) + self.assertEqual(stdout, expected_stdout) + + # also check with trace output enabled + update_build_option('extended_dry_run', False) + update_build_option('trace', True) + + with self.mocked_stdout_stderr(): + run_shell_cmd("make") + stdout = self.get_stdout() + + regex = re.compile('>> running shell command:\n\techo make', re.M) + self.assertTrue(regex.search(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout)) + def suite(): """ returns all the testcases in this module """