Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
95536ab5
Commit
95536ab5
authored
Nov 26, 2008
by
vladlosev
Browse files
Fixed gtest_break_on_failure_unittest on Ubuntu 8.04 and Windows
parent
c440a692
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
101 additions
and
45 deletions
+101
-45
test/gtest_break_on_failure_unittest.py
test/gtest_break_on_failure_unittest.py
+12
-6
test/gtest_break_on_failure_unittest_.cc
test/gtest_break_on_failure_unittest_.cc
+8
-0
test/gtest_test_utils.py
test/gtest_test_utils.py
+65
-22
test/gtest_xml_outfiles_test.py
test/gtest_xml_outfiles_test.py
+4
-5
test/gtest_xml_output_unittest.py
test/gtest_xml_output_unittest.py
+12
-12
No files found.
test/gtest_break_on_failure_unittest.py
View file @
95536ab5
...
@@ -77,8 +77,11 @@ def Run(command):
...
@@ -77,8 +77,11 @@ def Run(command):
"""Runs a command; returns 1 if it was killed by a signal, or 0 otherwise.
"""Runs a command; returns 1 if it was killed by a signal, or 0 otherwise.
"""
"""
exit_code
=
os
.
system
(
command
)
p
=
gtest_test_utils
.
Subprocess
(
command
)
return
os
.
WIFSIGNALED
(
exit_code
)
if
p
.
terminated_by_signal
:
return
1
else
:
return
0
# The unit test.
# The unit test.
...
@@ -112,11 +115,13 @@ class GTestBreakOnFailureUnitTest(unittest.TestCase):
...
@@ -112,11 +115,13 @@ class GTestBreakOnFailureUnitTest(unittest.TestCase):
if
flag_value
is
None
:
if
flag_value
is
None
:
flag
=
''
flag
=
''
elif
flag_value
==
'0'
:
elif
flag_value
==
'0'
:
flag
=
'
--%s=0'
%
BREAK_ON_FAILURE_FLAG
flag
=
'--%s=0'
%
BREAK_ON_FAILURE_FLAG
else
:
else
:
flag
=
'
--%s'
%
BREAK_ON_FAILURE_FLAG
flag
=
'--%s'
%
BREAK_ON_FAILURE_FLAG
command
=
EXE_PATH
+
flag
command
=
[
EXE_PATH
]
if
flag
:
command
.
append
(
flag
)
if
expect_seg_fault
:
if
expect_seg_fault
:
should_or_not
=
'should'
should_or_not
=
'should'
...
@@ -128,7 +133,8 @@ class GTestBreakOnFailureUnitTest(unittest.TestCase):
...
@@ -128,7 +133,8 @@ class GTestBreakOnFailureUnitTest(unittest.TestCase):
SetEnvVar
(
BREAK_ON_FAILURE_ENV_VAR
,
None
)
SetEnvVar
(
BREAK_ON_FAILURE_ENV_VAR
,
None
)
msg
=
(
'when %s%s, an assertion failure in "%s" %s cause a seg-fault.'
%
msg
=
(
'when %s%s, an assertion failure in "%s" %s cause a seg-fault.'
%
(
BREAK_ON_FAILURE_ENV_VAR
,
env_var_value_msg
,
command
,
should_or_not
))
(
BREAK_ON_FAILURE_ENV_VAR
,
env_var_value_msg
,
' '
.
join
(
command
),
should_or_not
))
self
.
assert_
(
has_seg_fault
==
expect_seg_fault
,
msg
)
self
.
assert_
(
has_seg_fault
==
expect_seg_fault
,
msg
)
def
testDefaultBehavior
(
self
):
def
testDefaultBehavior
(
self
):
...
...
test/gtest_break_on_failure_unittest_.cc
View file @
95536ab5
...
@@ -41,6 +41,9 @@
...
@@ -41,6 +41,9 @@
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#ifdef GTEST_OS_WINDOWS
#include <windows.h>
#endif
namespace
{
namespace
{
...
@@ -53,6 +56,11 @@ TEST(Foo, Bar) {
...
@@ -53,6 +56,11 @@ TEST(Foo, Bar) {
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
#ifdef GTEST_OS_WINDOWS
// Suppresses display of the Windows error dialog upon encountering
// a general protection fault (segment violation).
SetErrorMode
(
SEM_NOGPFAULTERRORBOX
|
SEM_FAILCRITICALERRORS
);
#endif
testing
::
InitGoogleTest
(
&
argc
,
argv
);
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
return
RUN_ALL_TESTS
();
...
...
test/gtest_test_utils.py
View file @
95536ab5
...
@@ -37,6 +37,13 @@ import os
...
@@ -37,6 +37,13 @@ import os
import
sys
import
sys
import
unittest
import
unittest
try
:
import
subprocess
_SUBPROCESS_MODULE_AVAILABLE
=
True
except
:
import
popen2
_SUBPROCESS_MODULE_AVAILABLE
=
False
# Initially maps a flag to its default value. After
# Initially maps a flag to its default value. After
# _ParseAndStripGTestFlags() is called, maps a flag to its actual
# _ParseAndStripGTestFlags() is called, maps a flag to its actual
...
@@ -116,29 +123,65 @@ def GetExitStatus(exit_code):
...
@@ -116,29 +123,65 @@ def GetExitStatus(exit_code):
return
-
1
return
-
1
def
RunCommandSuppressOutput
(
command
,
working_dir
=
None
):
class
Subprocess
:
"""Changes into a specified directory, if provided, and executes a command.
def
__init__
(
this
,
command
,
working_dir
=
None
):
Restores the old directory afterwards.
"""Changes into a specified directory, if provided, and executes a command.
Restores the old directory afterwards. Execution results are returned
Args:
via the following attributes:
command: A command to run.
terminated_by_sygnal True iff the child process has been terminated
working_dir: A directory to change into.
by a signal.
"""
signal Sygnal that terminated the child process.
exited True iff the child process exited normally.
old_dir
=
None
exit_code The code with which the child proces exited.
try
:
output Child process's stdout and stderr output
if
working_dir
is
not
None
:
combined in a string.
Args:
command: A command to run.
working_dir: A directory to change into.
"""
# The subprocess module is the preferrable way of running programs
# since it is available and behaves consistently on all platforms,
# including Windows. But it is only available starting in python 2.4.
# In earlier python versions, we revert to the popen2 module, which is
# available in python 2.0 and later but doesn't provide required
# functionality (Popen4) under Windows. This allows us to support Mac
# OS X 10.4 Tiger, which has python 2.3 installed.
if
_SUBPROCESS_MODULE_AVAILABLE
:
p
=
subprocess
.
Popen
(
command
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
,
cwd
=
working_dir
,
universal_newlines
=
True
)
# communicate returns a tuple with the file obect for the child's
# output.
this
.
output
=
p
.
communicate
()[
0
]
this
.
_return_code
=
p
.
returncode
else
:
old_dir
=
os
.
getcwd
()
old_dir
=
os
.
getcwd
()
os
.
chdir
(
working_dir
)
try
:
f
=
os
.
popen
(
command
,
'r'
)
if
working_dir
is
not
None
:
f
.
read
()
os
.
chdir
(
working_dir
)
ret_code
=
f
.
close
()
p
=
popen2
.
Popen4
(
command
)
finally
:
p
.
tochild
.
close
()
if
old_dir
is
not
None
:
this
.
output
=
p
.
fromchild
.
read
()
os
.
chdir
(
old_dir
)
ret_code
=
p
.
wait
()
if
ret_code
is
None
:
finally
:
ret_code
=
0
os
.
chdir
(
old_dir
)
return
ret_code
# Converts ret_code to match the semantics of
# subprocess.Popen.returncode.
if
os
.
WIFSIGNALED
(
ret_code
):
this
.
_return_code
=
-
os
.
WTERMSIG
(
ret_code
)
else
:
# os.WIFEXITED(ret_code) should return True here.
this
.
_return_code
=
os
.
WEXITSTATUS
(
ret_code
)
if
this
.
_return_code
<
0
:
this
.
terminated_by_signal
=
True
this
.
exited
=
False
this
.
signal
=
-
this
.
_return_code
else
:
this
.
terminated_by_signal
=
False
this
.
exited
=
True
this
.
exit_code
=
this
.
_return_code
def
Main
():
def
Main
():
...
...
test/gtest_xml_outfiles_test.py
View file @
95536ab5
...
@@ -100,11 +100,10 @@ class GTestXMLOutFilesTest(gtest_xml_test_utils.GTestXMLTestCase):
...
@@ -100,11 +100,10 @@ class GTestXMLOutFilesTest(gtest_xml_test_utils.GTestXMLTestCase):
def
_TestOutFile
(
self
,
test_name
,
expected_xml
):
def
_TestOutFile
(
self
,
test_name
,
expected_xml
):
gtest_prog_path
=
os
.
path
.
join
(
gtest_test_utils
.
GetBuildDir
(),
gtest_prog_path
=
os
.
path
.
join
(
gtest_test_utils
.
GetBuildDir
(),
test_name
)
test_name
)
command
=
"%s --gtest_output=xml:%s"
%
(
gtest_prog_path
,
self
.
output_dir_
)
command
=
[
gtest_prog_path
,
"--gtest_output=xml:%s"
%
self
.
output_dir_
]
status
=
gtest_test_utils
.
RunCommandSuppressOutput
(
p
=
gtest_test_utils
.
Subprocess
(
command
,
working_dir
=
tempfile
.
mkdtemp
())
command
,
self
.
assert_
(
p
.
exited
)
working_dir
=
tempfile
.
mkdtemp
())
self
.
assertEquals
(
0
,
p
.
exit_code
)
self
.
assertEquals
(
0
,
gtest_test_utils
.
GetExitStatus
(
status
))
# TODO(wan@google.com): libtool causes the built test binary to be
# TODO(wan@google.com): libtool causes the built test binary to be
# named lt-gtest_xml_outfiles_test_ instead of
# named lt-gtest_xml_outfiles_test_ instead of
...
...
test/gtest_xml_output_unittest.py
View file @
95536ab5
...
@@ -131,10 +131,11 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
...
@@ -131,10 +131,11 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
if
e
.
errno
!=
errno
.
ENOENT
:
if
e
.
errno
!=
errno
.
ENOENT
:
raise
raise
status
=
gtest_test_utils
.
RunCommandSuppressOutput
(
p
=
gtest_test_utils
.
Subprocess
(
"%s %s=xml"
%
(
gtest_prog_path
,
GTEST_OUTPUT_FLAG
),
[
gtest_prog_path
,
"%s=xml"
%
GTEST_OUTPUT_FLAG
],
working_dir
=
temp_dir
)
working_dir
=
temp_dir
)
self
.
assertEquals
(
0
,
gtest_test_utils
.
GetExitStatus
(
status
))
self
.
assert_
(
p
.
exited
)
self
.
assertEquals
(
0
,
p
.
exit_code
)
self
.
assert_
(
os
.
path
.
isfile
(
output_file
))
self
.
assert_
(
os
.
path
.
isfile
(
output_file
))
...
@@ -150,18 +151,17 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
...
@@ -150,18 +151,17 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
gtest_prog_path
=
os
.
path
.
join
(
gtest_test_utils
.
GetBuildDir
(),
gtest_prog_path
=
os
.
path
.
join
(
gtest_test_utils
.
GetBuildDir
(),
gtest_prog_name
)
gtest_prog_name
)
command
=
(
"%s %s=xml:%s"
%
(
gtest_prog_path
,
GTEST_OUTPUT_FLAG
,
xml_path
))
command
=
[
gtest_prog_path
,
"%s=xml:%s"
%
(
GTEST_OUTPUT_FLAG
,
xml_path
)]
status
=
gtest_test_utils
.
RunCommandSuppressOutput
(
command
)
p
=
gtest_test_utils
.
Subprocess
(
command
)
if
os
.
WIFSIGNALED
(
status
):
if
p
.
terminated_by_signal
:
signal
=
os
.
WTERMSIG
(
status
)
self
.
assert_
(
False
,
self
.
assert_
(
False
,
"%s was killed by signal %d"
%
(
gtest_prog_name
,
signal
))
"%s was killed by signal %d"
%
(
gtest_prog_name
,
p
.
signal
))
else
:
else
:
exit_code
=
gtest_test_utils
.
GetExitStatus
(
status
)
self
.
assert_
(
p
.
exited
)
self
.
assertEquals
(
expected_exit_code
,
exit_code
,
self
.
assertEquals
(
expected_exit_code
,
p
.
exit_code
,
"'%s' exited with code %s, which doesn't match "
"'%s' exited with code %s, which doesn't match "
"the expected exit code %s."
"the expected exit code %s."
%
(
command
,
exit_code
,
expected_exit_code
))
%
(
command
,
p
.
exit_code
,
expected_exit_code
))
expected
=
minidom
.
parseString
(
expected_xml
)
expected
=
minidom
.
parseString
(
expected_xml
)
actual
=
minidom
.
parse
(
xml_path
)
actual
=
minidom
.
parse
(
xml_path
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment