Skip to main content
Post Reopened by Daniel Goldfarb, Toby Speight, alecxe, Josh Lee, Rabbid76
deleted 1 character in body
Source Link
alecxe
  • 476.2k
  • 127
  • 1.1k
  • 1.2k

This is NOT a duplicate of How are unnamed namespaces superior to the static keyword? Please read the question carefully before marking it as duplicate. I am not asking why use an unnamed namespace versus static!
I am asking, why are WHY ARE GOOGLE TESTS PLACED INSIDE AN UNNAMED NAMESPACE? Is this some convention that google tests follow, and if so, why? The tests work fine whether they are in an unnamed namespace or not, so obviously it is not required.google tests placed inside an unnamed namespace? Is this some convention that google tests follow, and if so, why? The tests work fine whether they are in an unnamed namespace or not, so obviously it is not required.**

I cloned google test from github and built it for my mac. It works fine, but I noticed in the sample test code they give they place the tests in an unnamed namespace. Does anyone know why?

For example, see following file: googletest/googletest/samples/sample1_unittest.cc (https://github.com/google/googletest/blob/master/googletest/samples/sample1_unittest.cc#L41)

Part of the file looks like this:

// Step 1. Include necessary header files such that the stuff your
// test logic needs is declared.
//
// Don't forget gtest.h, which declares the testing framework.

#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"
namespace {

// Step 2. Use the TEST macro to define your tests.
...
TEST(FactorialTest, Negative) {
// This test is named "Negative", and belongs to the "FactorialTest"
// test case.
EXPECT_EQ(1, Factorial(-5));
EXPECT_EQ(1, Factorial(-1));
EXPECT_GT(Factorial(-10), 0);
}
...
}  // namespace

Does anyone know why all the tests are in an unnamed namespace? I tried removing the unnamed namespace and the sample still worked fine, so clearly it is not necessary for this particular sample.

This is NOT a duplicate of How are unnamed namespaces superior to the static keyword? Please read the question carefully before marking it as duplicate. I am not asking why use an unnamed namespace versus static!
I am asking WHY ARE GOOGLE TESTS PLACED INSIDE AN UNNAMED NAMESPACE? Is this some convention that google tests follow, and if so, why? The tests work fine whether they are in an unnamed namespace or not, so obviously it is not required.

I cloned google test from github and built it for my mac. It works fine, but I noticed in the sample test code they give they place the tests in an unnamed namespace. Does anyone know why?

For example, see following file: googletest/googletest/samples/sample1_unittest.cc (https://github.com/google/googletest/blob/master/googletest/samples/sample1_unittest.cc#L41)

Part of the file looks like this:

// Step 1. Include necessary header files such that the stuff your
// test logic needs is declared.
//
// Don't forget gtest.h, which declares the testing framework.

#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"
namespace {

// Step 2. Use the TEST macro to define your tests.
...
TEST(FactorialTest, Negative) {
// This test is named "Negative", and belongs to the "FactorialTest"
// test case.
EXPECT_EQ(1, Factorial(-5));
EXPECT_EQ(1, Factorial(-1));
EXPECT_GT(Factorial(-10), 0);
}
...
}  // namespace

Does anyone know why all the tests are in an unnamed namespace? I tried removing the unnamed namespace and the sample still worked fine, so clearly it is not necessary for this particular sample.

This is NOT a duplicate of How are unnamed namespaces superior to the static keyword? Please read the question carefully before marking it as duplicate. I am not asking why use an unnamed namespace versus static!
I am asking, why are google tests placed inside an unnamed namespace? Is this some convention that google tests follow, and if so, why? The tests work fine whether they are in an unnamed namespace or not, so obviously it is not required.**

I cloned google test from github and built it for my mac. It works fine, but I noticed in the sample test code they give they place the tests in an unnamed namespace. Does anyone know why?

For example, see following file: googletest/googletest/samples/sample1_unittest.cc (https://github.com/google/googletest/blob/master/googletest/samples/sample1_unittest.cc#L41)

Part of the file looks like this:

// Step 1. Include necessary header files such that the stuff your
// test logic needs is declared.
//
// Don't forget gtest.h, which declares the testing framework.

#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"
namespace {

// Step 2. Use the TEST macro to define your tests.
...
TEST(FactorialTest, Negative) {
// This test is named "Negative", and belongs to the "FactorialTest"
// test case.
EXPECT_EQ(1, Factorial(-5));
EXPECT_EQ(1, Factorial(-1));
EXPECT_GT(Factorial(-10), 0);
}
...
}  // namespace

Does anyone know why all the tests are in an unnamed namespace? I tried removing the unnamed namespace and the sample still worked fine, so clearly it is not necessary for this particular sample.

deleted 432 characters in body
Source Link
Daniel Goldfarb
  • 7.9k
  • 6
  • 40
  • 72

This is NOT a duplicate of How are unnamed namespaces superior to the static keyword? Please read the question carefully before marking it as duplicate. I am not asking why use an unnamed namespace versus static!
I am asking WHY ARE GOOGLE TESTS PLACED INSIDE AN UNNAMED NAMESPACE? Is this some convention that google tests follow, and if so, why? The tests work fine whether they are in an unnamed namespace or not, so obviously it is not required.

I cloned google test from github and built it for my mac. It works fine, but I noticed in the sample test code they give they place the tests in an unnamed namespace. Does anyone know why?

For example, see following file: googletest/googletest/samples/sample1_unittest.cc (https://github.com/google/googletest/blob/master/googletest/samples/sample1_unittest.cc#L41)

Part of the file looks like this:

// Step 1. Include necessary header files such that the stuff your
// test logic needs is declared.
//
// Don't forget gtest.h, which declares the testing framework.

#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"
namespace {

// Step 2. Use the TEST macro to define your tests.
...
TEST(FactorialTest, Negative) {
// This test is named "Negative", and belongs to the "FactorialTest"
// test case.
EXPECT_EQ(1, Factorial(-5));
EXPECT_EQ(1, Factorial(-1));
EXPECT_GT(Factorial(-10), 0);
}
...
}  // namespace

Does anyone know why all the tests are in an unnamed namespace? I tried removing the unnamed namespace and the sample still worked fine, so clearly it is not necessary for this particular sample.

This is NOT a duplicate of How are unnamed namespaces superior to the static keyword? I am not asking why use an unnamed namespace versus static! I am asking WHY ARE THESE GOOGLE TESTS PLACED INSIDE AN UNNAMED NAMESPACE? Is this some convention that google tests follow, and if so, why? The tests work fine whether they are in an unnamed namespace or not, so obviously it is not required.

This is NOT a duplicate of How are unnamed namespaces superior to the static keyword? Please read the question carefully before marking it as duplicate. I am not asking why use an unnamed namespace versus static!
I am asking WHY ARE GOOGLE TESTS PLACED INSIDE AN UNNAMED NAMESPACE? Is this some convention that google tests follow, and if so, why? The tests work fine whether they are in an unnamed namespace or not, so obviously it is not required.

I cloned google test from github and built it for my mac. It works fine, but I noticed in the sample test code they give they place the tests in an unnamed namespace. Does anyone know why?

For example, see following file: googletest/googletest/samples/sample1_unittest.cc (https://github.com/google/googletest/blob/master/googletest/samples/sample1_unittest.cc#L41)

Part of the file looks like this:

// Step 1. Include necessary header files such that the stuff your
// test logic needs is declared.
//
// Don't forget gtest.h, which declares the testing framework.

#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"
namespace {

// Step 2. Use the TEST macro to define your tests.
...
TEST(FactorialTest, Negative) {
// This test is named "Negative", and belongs to the "FactorialTest"
// test case.
EXPECT_EQ(1, Factorial(-5));
EXPECT_EQ(1, Factorial(-1));
EXPECT_GT(Factorial(-10), 0);
}
...
}  // namespace

Does anyone know why all the tests are in an unnamed namespace? I tried removing the unnamed namespace and the sample still worked fine, so clearly it is not necessary for this particular sample.

This is NOT a duplicate of How are unnamed namespaces superior to the static keyword? I am not asking why use an unnamed namespace versus static! I am asking WHY ARE THESE GOOGLE TESTS PLACED INSIDE AN UNNAMED NAMESPACE? Is this some convention that google tests follow, and if so, why? The tests work fine whether they are in an unnamed namespace or not, so obviously it is not required.

This is NOT a duplicate of How are unnamed namespaces superior to the static keyword? Please read the question carefully before marking it as duplicate. I am not asking why use an unnamed namespace versus static!
I am asking WHY ARE GOOGLE TESTS PLACED INSIDE AN UNNAMED NAMESPACE? Is this some convention that google tests follow, and if so, why? The tests work fine whether they are in an unnamed namespace or not, so obviously it is not required.

I cloned google test from github and built it for my mac. It works fine, but I noticed in the sample test code they give they place the tests in an unnamed namespace. Does anyone know why?

For example, see following file: googletest/googletest/samples/sample1_unittest.cc (https://github.com/google/googletest/blob/master/googletest/samples/sample1_unittest.cc#L41)

Part of the file looks like this:

// Step 1. Include necessary header files such that the stuff your
// test logic needs is declared.
//
// Don't forget gtest.h, which declares the testing framework.

#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"
namespace {

// Step 2. Use the TEST macro to define your tests.
...
TEST(FactorialTest, Negative) {
// This test is named "Negative", and belongs to the "FactorialTest"
// test case.
EXPECT_EQ(1, Factorial(-5));
EXPECT_EQ(1, Factorial(-1));
EXPECT_GT(Factorial(-10), 0);
}
...
}  // namespace

Does anyone know why all the tests are in an unnamed namespace? I tried removing the unnamed namespace and the sample still worked fine, so clearly it is not necessary for this particular sample.

added 428 characters in body
Source Link
Daniel Goldfarb
  • 7.9k
  • 6
  • 40
  • 72

This is NOT a duplicate of How are unnamed namespaces superior to the static keyword? Please read the question carefully before marking it as duplicate. I am not asking why use an unnamed namespace versus static!
I am asking WHY ARE GOOGLE TESTS PLACED INSIDE AN UNNAMED NAMESPACE? Is this some convention that google tests follow, and if so, why? The tests work fine whether they are in an unnamed namespace or not, so obviously it is not required.

I cloned google test from github and built it for my mac. It works fine, but I noticed in the sample test code they give they place the tests in an unnamed namespace. Does anyone know why?

For example, see following file: googletest/googletest/samples/sample1_unittest.cc (https://github.com/google/googletest/blob/master/googletest/samples/sample1_unittest.cc#L41)

Part of the file looks like this:

// Step 1. Include necessary header files such that the stuff your
// test logic needs is declared.
//
// Don't forget gtest.h, which declares the testing framework.

#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"
namespace {

// Step 2. Use the TEST macro to define your tests.
...
TEST(FactorialTest, Negative) {
// This test is named "Negative", and belongs to the "FactorialTest"
// test case.
EXPECT_EQ(1, Factorial(-5));
EXPECT_EQ(1, Factorial(-1));
EXPECT_GT(Factorial(-10), 0);
}
...
}  // namespace

Does anyone know why all the tests are in an unnamed namespace? I tried removing the unnamed namespace and the sample still worked fine, so clearly it is not necessary for this particular sample.

This is NOT a duplicate of How are unnamed namespaces superior to the static keyword? I am not asking why use an unnamed namespace versus static! I am asking WHY ARE THESE GOOGLE TESTS PLACED INSIDE AN UNNAMED NAMESPACE? Is this some convention that google tests follow, and if so, why? The tests work fine whether they are in an unnamed namespace or not, so obviously it is not required.

I cloned google test from github and built it for my mac. It works fine, but I noticed in the sample test code they give they place the tests in an unnamed namespace. Does anyone know why?

For example, see following file: googletest/googletest/samples/sample1_unittest.cc (https://github.com/google/googletest/blob/master/googletest/samples/sample1_unittest.cc#L41)

Part of the file looks like this:

// Step 1. Include necessary header files such that the stuff your
// test logic needs is declared.
//
// Don't forget gtest.h, which declares the testing framework.

#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"
namespace {

// Step 2. Use the TEST macro to define your tests.
...
TEST(FactorialTest, Negative) {
// This test is named "Negative", and belongs to the "FactorialTest"
// test case.
EXPECT_EQ(1, Factorial(-5));
EXPECT_EQ(1, Factorial(-1));
EXPECT_GT(Factorial(-10), 0);
}
...
}  // namespace

Does anyone know why all the tests are in an unnamed namespace? I tried removing the unnamed namespace and the sample still worked fine, so clearly it is not necessary for this particular sample.

This is NOT a duplicate of How are unnamed namespaces superior to the static keyword? Please read the question carefully before marking it as duplicate. I am not asking why use an unnamed namespace versus static!
I am asking WHY ARE GOOGLE TESTS PLACED INSIDE AN UNNAMED NAMESPACE? Is this some convention that google tests follow, and if so, why? The tests work fine whether they are in an unnamed namespace or not, so obviously it is not required.

I cloned google test from github and built it for my mac. It works fine, but I noticed in the sample test code they give they place the tests in an unnamed namespace. Does anyone know why?

For example, see following file: googletest/googletest/samples/sample1_unittest.cc (https://github.com/google/googletest/blob/master/googletest/samples/sample1_unittest.cc#L41)

Part of the file looks like this:

// Step 1. Include necessary header files such that the stuff your
// test logic needs is declared.
//
// Don't forget gtest.h, which declares the testing framework.

#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"
namespace {

// Step 2. Use the TEST macro to define your tests.
...
TEST(FactorialTest, Negative) {
// This test is named "Negative", and belongs to the "FactorialTest"
// test case.
EXPECT_EQ(1, Factorial(-5));
EXPECT_EQ(1, Factorial(-1));
EXPECT_GT(Factorial(-10), 0);
}
...
}  // namespace

Does anyone know why all the tests are in an unnamed namespace? I tried removing the unnamed namespace and the sample still worked fine, so clearly it is not necessary for this particular sample.

This is NOT a duplicate of How are unnamed namespaces superior to the static keyword? I am not asking why use an unnamed namespace versus static! I am asking WHY ARE THESE GOOGLE TESTS PLACED INSIDE AN UNNAMED NAMESPACE? Is this some convention that google tests follow, and if so, why? The tests work fine whether they are in an unnamed namespace or not, so obviously it is not required.

Post Closed as "Duplicate" by Bo Persson c++
Source Link
Daniel Goldfarb
  • 7.9k
  • 6
  • 40
  • 72
Loading