11be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#!/usr/bin/env python 21be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# 31be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# Copyright 2008, Google Inc. 41be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# All rights reserved. 51be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# 61be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# Redistribution and use in source and binary forms, with or without 71be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# modification, are permitted provided that the following conditions are 81be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# met: 91be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# 101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# * Redistributions of source code must retain the above copyright 111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# notice, this list of conditions and the following disclaimer. 121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# * Redistributions in binary form must reproduce the above 131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# copyright notice, this list of conditions and the following disclaimer 141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# in the documentation and/or other materials provided with the 151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# distribution. 161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# * Neither the name of Google Inc. nor the names of its 171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# contributors may be used to endorse or promote products derived from 181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# this software without specific prior written permission. 191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# 201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania"""Verifies that Google Test warns the user when not initialized properly.""" 331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania__author__ = 'wan@google.com (Zhanyong Wan)' 351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaimport gtest_test_utils 371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3941d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotCOMMAND = gtest_test_utils.GetTestExecutablePath('gtest_uninitialized_test_') 401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniadef Assert(condition): 431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if not condition: 441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania raise AssertionError 451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniadef AssertEq(expected, actual): 481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if expected != actual: 491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania print 'Expected: %s' % (expected,) 501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania print ' Actual: %s' % (actual,) 511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania raise AssertionError 521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniadef TestExitCodeAndOutput(command): 551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania """Runs the given command and verifies its exit code and output.""" 561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania # Verifies that 'command' exits with code 1. 581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania p = gtest_test_utils.Subprocess(command) 591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Assert(p.exited) 601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania AssertEq(1, p.exit_code) 611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Assert('InitGoogleTest' in p.output) 621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass GTestUninitializedTest(gtest_test_utils.TestCase): 6541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot def testExitCodeAndOutput(self): 6641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot TestExitCodeAndOutput(COMMAND) 671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotif __name__ == '__main__': 7041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot gtest_test_utils.Main() 71