32 """Tests Google Test's throw-on-failure mode with exceptions disabled.
34 This script invokes gtest_throw_on_failure_test_ (a program written with
35 Google Test) with different environments and command line flags.
38 __author__ =
'wan@google.com (Zhanyong Wan)'
41 import gtest_test_utils
47 THROW_ON_FAILURE =
'gtest_throw_on_failure'
52 'gtest_throw_on_failure_test_')
59 """Sets an environment variable to a given value; unsets it when the
63 env_var = env_var.upper()
65 os.environ[env_var] = value
66 elif env_var
in os.environ:
67 del os.environ[env_var]
71 """Runs a command; returns True/False if its exit code is/isn't 0."""
73 print(
'Running "%s". . .' %
' '.
join(command))
75 return p.exited
and p.exit_code == 0
81 """Tests the throw-on-failure mode."""
84 """Runs gtest_throw_on_failure_test_ and verifies that it does
85 (or does not) exit with a non-zero code.
88 env_var_value: value of the GTEST_BREAK_ON_FAILURE environment
89 variable; None if the variable should be unset.
90 flag_value: value of the --gtest_break_on_failure flag;
91 None if the flag should not be present.
92 should_fail: True iff the program is expected to fail.
95 SetEnvVar(THROW_ON_FAILURE, env_var_value)
97 if env_var_value
is None:
98 env_var_value_msg =
' is not set'
100 env_var_value_msg =
'=' + env_var_value
102 if flag_value
is None:
104 elif flag_value ==
'0':
105 flag =
'--%s=0' % THROW_ON_FAILURE
107 flag =
'--%s' % THROW_ON_FAILURE
114 should_or_not =
'should'
116 should_or_not =
'should not'
118 failed =
not Run(command)
122 msg = (
'when %s%s, an assertion failure in "%s" %s cause a non-zero '
124 (THROW_ON_FAILURE, env_var_value_msg,
' '.
join(command),
126 self.assert_(failed == should_fail, msg)
129 """Tests the behavior of the default mode."""
131 self.
RunAndVerify(env_var_value=
None, flag_value=
None, should_fail=
False)
134 """Tests using the GTEST_THROW_ON_FAILURE environment variable."""
144 """Tests using the --gtest_throw_on_failure flag."""
154 """Tests that --gtest_throw_on_failure overrides GTEST_THROW_ON_FAILURE."""
170 if __name__ ==
'__main__':