Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 911bc6d

Browse files
author
William McLendon
committed
TRILFRAME-120+ Add bash test for unresolved cmake var
1 parent e7a4ada commit 911bc6d

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

src/setprogramoptions/unittests/files_ini/config_test_setprogramoptions.ini

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,18 @@ opt-remove FOO_TEST
199199

200200
[TEST_CMAKE_VAR_FORCE_ONLY]
201201
opt-set-cmake-var FOO FORCE : "BAR"
202+
203+
204+
[TEST_CMAKE_VAR_IN_BASH_GENERATOR]
205+
# The purpose of this section is to see what we do if someone
206+
# has an _update_ operation (i.e., append/prepend to an existing var)
207+
# and that cmake var does not exist already. In this case we emulate
208+
# this by simulating a typo but it could occur in other cases where
209+
# a cmake generator would expect a fragment to update something that was
210+
# defined elsewhere. Should the bash generator throw an error or replace
211+
# "FOO_VAE" with an empty string?
212+
#
213+
# Set FOO_VAR to something concrete
214+
opt-set-cmake-var FOO_VAR STRING : "FOO"
215+
# Simulated typo in FOO_VAR update
216+
opt-set-cmake-var FOO_VAR FORCE : "BAR ${FOO_VAE|CMAKE}"

src/setprogramoptions/unittests/test_SetProgramOptionsCMake.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
sys.dont_write_bytecode = True
1010

11+
import contextlib
12+
import io
1113
import os
1214

1315

@@ -628,6 +630,84 @@ def test_SetProgramOptionsCMake_FORCE_only_for_bash(self):
628630
print("OK")
629631
return 0
630632

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+
631711
def _create_standard_parser(
632712
self, filename=DEFAULT_VALUE(), debug_level=5, ece_level=4, ece_compact=False
633713
):

0 commit comments

Comments
 (0)