Blame googletest/test/gtest_env_var_test_.cc

Packit bd1cd8
// Copyright 2008, Google Inc.
Packit bd1cd8
// All rights reserved.
Packit bd1cd8
//
Packit bd1cd8
// Redistribution and use in source and binary forms, with or without
Packit bd1cd8
// modification, are permitted provided that the following conditions are
Packit bd1cd8
// met:
Packit bd1cd8
//
Packit bd1cd8
//     * Redistributions of source code must retain the above copyright
Packit bd1cd8
// notice, this list of conditions and the following disclaimer.
Packit bd1cd8
//     * Redistributions in binary form must reproduce the above
Packit bd1cd8
// copyright notice, this list of conditions and the following disclaimer
Packit bd1cd8
// in the documentation and/or other materials provided with the
Packit bd1cd8
// distribution.
Packit bd1cd8
//     * Neither the name of Google Inc. nor the names of its
Packit bd1cd8
// contributors may be used to endorse or promote products derived from
Packit bd1cd8
// this software without specific prior written permission.
Packit bd1cd8
//
Packit bd1cd8
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit bd1cd8
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit bd1cd8
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit bd1cd8
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit bd1cd8
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit bd1cd8
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit bd1cd8
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit bd1cd8
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit bd1cd8
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit bd1cd8
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit bd1cd8
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit bd1cd8
//
Packit bd1cd8
// Author: wan@google.com (Zhanyong Wan)
Packit bd1cd8
Packit bd1cd8
// A helper program for testing that Google Test parses the environment
Packit bd1cd8
// variables correctly.
Packit bd1cd8
Packit bd1cd8
#include "gtest/gtest.h"
Packit bd1cd8
Packit bd1cd8
#include <iostream>
Packit bd1cd8
Packit bd1cd8
#define GTEST_IMPLEMENTATION_ 1
Packit bd1cd8
#include "src/gtest-internal-inl.h"
Packit bd1cd8
#undef GTEST_IMPLEMENTATION_
Packit bd1cd8
Packit bd1cd8
using ::std::cout;
Packit bd1cd8
Packit bd1cd8
namespace testing {
Packit bd1cd8
Packit bd1cd8
// The purpose of this is to make the test more realistic by ensuring
Packit bd1cd8
// that the UnitTest singleton is created before main() is entered.
Packit bd1cd8
// We don't actual run the TEST itself.
Packit bd1cd8
TEST(GTestEnvVarTest, Dummy) {
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
void PrintFlag(const char* flag) {
Packit bd1cd8
  if (strcmp(flag, "break_on_failure") == 0) {
Packit bd1cd8
    cout << GTEST_FLAG(break_on_failure);
Packit bd1cd8
    return;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  if (strcmp(flag, "catch_exceptions") == 0) {
Packit bd1cd8
    cout << GTEST_FLAG(catch_exceptions);
Packit bd1cd8
    return;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  if (strcmp(flag, "color") == 0) {
Packit bd1cd8
    cout << GTEST_FLAG(color);
Packit bd1cd8
    return;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  if (strcmp(flag, "death_test_style") == 0) {
Packit bd1cd8
    cout << GTEST_FLAG(death_test_style);
Packit bd1cd8
    return;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  if (strcmp(flag, "death_test_use_fork") == 0) {
Packit bd1cd8
    cout << GTEST_FLAG(death_test_use_fork);
Packit bd1cd8
    return;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  if (strcmp(flag, "filter") == 0) {
Packit bd1cd8
    cout << GTEST_FLAG(filter);
Packit bd1cd8
    return;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  if (strcmp(flag, "output") == 0) {
Packit bd1cd8
    cout << GTEST_FLAG(output);
Packit bd1cd8
    return;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  if (strcmp(flag, "print_time") == 0) {
Packit bd1cd8
    cout << GTEST_FLAG(print_time);
Packit bd1cd8
    return;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  if (strcmp(flag, "repeat") == 0) {
Packit bd1cd8
    cout << GTEST_FLAG(repeat);
Packit bd1cd8
    return;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  if (strcmp(flag, "stack_trace_depth") == 0) {
Packit bd1cd8
    cout << GTEST_FLAG(stack_trace_depth);
Packit bd1cd8
    return;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  if (strcmp(flag, "throw_on_failure") == 0) {
Packit bd1cd8
    cout << GTEST_FLAG(throw_on_failure);
Packit bd1cd8
    return;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  cout << "Invalid flag name " << flag
Packit bd1cd8
       << ".  Valid names are break_on_failure, color, filter, etc.\n";
Packit bd1cd8
  exit(1);
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
}  // namespace testing
Packit bd1cd8
Packit bd1cd8
int main(int argc, char** argv) {
Packit bd1cd8
  testing::InitGoogleTest(&argc, argv);
Packit bd1cd8
Packit bd1cd8
  if (argc != 2) {
Packit bd1cd8
    cout << "Usage: gtest_env_var_test_ NAME_OF_FLAG\n";
Packit bd1cd8
    return 1;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  testing::PrintFlag(argv[1]);
Packit bd1cd8
  return 0;
Packit bd1cd8
}