|
8 | 8 |
|
9 | 9 | sys.dont_write_bytecode = True
|
10 | 10 |
|
| 11 | +import contextlib |
| 12 | +import io |
11 | 13 | import os
|
12 | 14 |
|
13 | 15 |
|
@@ -628,6 +630,84 @@ def test_SetProgramOptionsCMake_FORCE_only_for_bash(self):
|
628 | 630 | print("OK")
|
629 | 631 | return 0
|
630 | 632 |
|
| 633 | + def test_SetProgramOptionsCMake_gen_option_list_bash_unresolved_cmake_var_01(self): |
| 634 | + """ |
| 635 | + Tests what we do with an unresolved cmake variable encountered in the |
| 636 | + bash generator. The hitch is that if we replace the unresolved cmake |
| 637 | + var with an empty string we may be allowing a ``cmake-fragment`` and a |
| 638 | + ``bash command`` to diverge sicne the cmake fragment would have additional |
| 639 | + context of pre-existing variables that *might exist* versus the bash command |
| 640 | + where a cmake variable *definitely will not exist*. |
| 641 | + """ |
| 642 | + parser = self._create_standard_parser() |
| 643 | + section = "TEST_CMAKE_VAR_IN_BASH_GENERATOR" |
| 644 | + print("Section : {}".format(section)) |
| 645 | + |
| 646 | + print("-----[ TEST BEGIN ]----------------------------------------") |
| 647 | + # Test 1: Validate exception is raised when `exception_control_level` |
| 648 | + # is the default (4). |
| 649 | + with self.assertRaises(ValueError): |
| 650 | + option_list_actual = parser.gen_option_list(section, generator='bash') |
| 651 | + print("-----[ TEST END ]------------------------------------------") |
| 652 | + |
| 653 | + print("-----[ TEST BEGIN ]----------------------------------------") |
| 654 | + # Test 2: Reduce the `exception_control_level` so that the exception is |
| 655 | + # not generated. |
| 656 | + # - Sets `exception_control_level` to 3 |
| 657 | + # - Sets `exception_control_compact_warnings` to False |
| 658 | + # Note: This test is sensitive to formatting changes to `ExceptionControl` |
| 659 | + # if this is a big problem we may need to change this in the future |
| 660 | + # to be less sensitive to stdout. |
| 661 | + option_list_expect = [ |
| 662 | + '-DFOO_VAR:STRING="FOO"', |
| 663 | + '-DFOO_VAR:STRING="BAR "' |
| 664 | + ] |
| 665 | + parser.exception_control_level = 3 |
| 666 | + parser.exception_control_compact_warnings = False |
| 667 | + with io.StringIO() as m_stdout: |
| 668 | + with contextlib.redirect_stdout(m_stdout): |
| 669 | + option_list_actual = parser.gen_option_list(section, generator='bash') |
| 670 | + |
| 671 | + # Check that the output matches |
| 672 | + self.assertListEqual(option_list_expect, option_list_actual) |
| 673 | + |
| 674 | + # Check that the exception-control warning message gets printed |
| 675 | + self.assertIn("EXCEPTION SKIPPED", m_stdout.getvalue()) |
| 676 | + self.assertIn("Event Type : MINOR", m_stdout.getvalue()) |
| 677 | + self.assertIn("Exception : ValueError", m_stdout.getvalue()) |
| 678 | + print("-----[ TEST END ]------------------------------------------") |
| 679 | + |
| 680 | + print("-----[ TEST BEGIN ]----------------------------------------") |
| 681 | + # Test 2: Repeat the previous test but with *compact* warnings from |
| 682 | + # `exception_control_compact_warnings` set to True to enable |
| 683 | + # compact warnings. |
| 684 | + # - Sets `exception_control_level` to 3 |
| 685 | + # - Sets `exception_control_compact_warnings` to True |
| 686 | + # Note: This test is sensitive to formatting changes to `ExceptionControl` |
| 687 | + # if this is a big problem we may need to change this in the future |
| 688 | + # to be less sensitive to stdout. |
| 689 | + option_list_expect = [ |
| 690 | + '-DFOO_VAR:STRING="FOO"', |
| 691 | + '-DFOO_VAR:STRING="BAR "' |
| 692 | + ] |
| 693 | + parser.exception_control_level = 3 |
| 694 | + parser.exception_control_compact_warnings = True |
| 695 | + with io.StringIO() as m_stdout: |
| 696 | + with contextlib.redirect_stdout(m_stdout): |
| 697 | + option_list_actual = parser.gen_option_list(section, generator='bash') |
| 698 | + |
| 699 | + # Check that the output matches |
| 700 | + self.assertListEqual(option_list_expect, option_list_actual) |
| 701 | + |
| 702 | + # Check that the exception-control warning message gets printed |
| 703 | + self.assertIn("EXCEPTION SKIPPED", m_stdout.getvalue()) |
| 704 | + self.assertIn("(MINOR : ValueError)", m_stdout.getvalue()) |
| 705 | + print("-----[ TEST END ]------------------------------------------") |
| 706 | + |
| 707 | + print("OK") |
| 708 | + return 0 |
| 709 | + |
| 710 | + |
631 | 711 | def _create_standard_parser(
|
632 | 712 | self, filename=DEFAULT_VALUE(), debug_level=5, ece_level=4, ece_compact=False
|
633 | 713 | ):
|
|
0 commit comments