title: Redefined Catch unit tests
body: <p>I'm testing a huge piece of software and would like to use Catch for this task.
  I'm using the "single include" version 1.9, integrating it in Visual Studio 2012 update 4 and using C++04 standard.</p>
  
  <p>As you will see below, I use three ".cpp" files. Each of them reference:</p>
  
  <ul>
  <li>a include file providing "abstraction" macros (eg. <code>#define Assert(x) REQUIRE(x)</code>);</li>
  <li>a utility file providing... utilities for the test;</li>
  <li>the specific test target include files;</li>
  <li>some "using namespace" statement, all cpp files "using" the same namespace;</li>
  <li>the actual tests, written with the macros (eg. <code>Assert(2 == getNumber())</code>).</li>
  </ul>
  
  <p>More details on the files content below.</p>
  
  <p>This configuration works, but one of the test file is growing bigger by the day and I would like to split it in 3, or more. Now, say that I do the following:</p>
  
  <ul>
  <li>take part of the content of a test <code>test.cpp</code> and move it in a new file <code>test2.cpp</code>;</li>
  <li>add the same includes and defines to make it compile;</li>
  <li>include the new file in my main</li>
  </ul>
  
  <p>this error pops up when I run the tests:</p>
  
  <pre><code>=============================
  No tests ran
  error: TEST_CASE( "test 2" ) already defined.
      First seen at c:\tests\catchtest2\catchtest2\test2.cpp(3)
      Redefined at c:\tests\catchtest2\catchtest2\test2.cpp(3)
  </code></pre>
  
  <p>where <code>test2.cpp</code> is the new file.
  If I move the content back to <code>test.cpp</code> it all works, but working with tests thousands of lines long is almost harder than working on the project itself, and the dimension could grow 3, 4 times bigger still.
  Is there a way to split the tests in multiple files?</p>
  
  <p>-- NOTES --</p>
  
  <p>I reckon including Catch in a header and using the including header instead of <code>catch.cpp</code> directly is not a good idea, but I successfully used this configuration with 3 (exactly 3) included <code>.cpp</code> test files, and am unable to use this with 4 files.</p>
  
  <p>I remember reading that it was somehow related to the <em>line</em> at which the components were defined, but I can also move the code so that the test cases are defined at different lines and the behaviour doesn't change.</p>
  
  <p>I also tried to "clean and rebuild", because it may well be that dirty data is kept in the compiler / linker's caches, but to no avail.</p>
  
  <p>I couldn't create an actual MWE right now, so I gave you a sketch of the test setup as accurate as I thought it could be needed. I'm more than willing to provide additional details or try and build an actual MWE and share it.</p>
  
  <p>Any idea is appreciated!</p>
  
  <hr>
  
  <p>My "working" code looks like this:</p>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#define CATCH_CONFIG_RUNNER
  #include "catch.hpp"
  #include "test1.cpp"
  #include "test2.cpp"
  #include "test3.cpp"
  
  int main( int argc, char* argv[] )
  {
      cleanDir("c:\\temp");
      init (argv);
      int result = Catch::Session().run( argc, argv );
      return ( result &lt; 0xff ? result : 0xff );
  }
  </code></pre>
  
  <p><strong>test1.cpp</strong></p>
  
  <pre><code>#include "unitTestSuite.h"
  #include "utils.h"
  #include "systemundertest.h"
  
  using namespace system::under::test;
  
  my_test_case("test 1") {
      my_section("does X") {
          // tests...
      }
  }
  
  my_test_case("test 2") {
      my_section("does Y") {
          // tests...
      }
  }
  </code></pre>
  
  <p><strong>unitTestSuite.h</strong></p>
  
  <pre><code>#ifndef UNIT_TEST_SUITE
  #define UNIT_TEST_SUITE 1
  
  #include "catch.hpp"
  #define my_test_case(x) TEST_CASE("Testing: " x)
  ... // here is also a namespace with some unit test specific utils
  #endif
  </code></pre>
  
  <p><strong>utils.h</strong></p>
  
  <pre><code>#ifndef _UTILS_
  #define _UTILS_
  // some global variables declared here and defined in utils.cpp
  // template functions defined in the header
  // non-template functions defined in utils.cpp
  // a test generation namespace with some template functions and some non-template functions defined in utils.cpp
  #endif
  </code></pre>
  
  <hr>
  
  <p>After the "split":</p>
  
  <p><strong>test1.cpp</strong></p>
  
  <pre><code>#include "unitTestSuite.h"
  #include "utils.h"
  #include "systemundertest.h"
  
  using namespace system::under::test;
  
  my_test_case("test 1") {
      my_section("does X") {
          // tests...
      }
  }
  </code></pre>
  
  <p><strong>test1.2.cpp</strong></p>
  
  <pre><code>#include "unitTestSuite.h"
  #include "utils.h"
  #include "systemundertest.h"
  
  using namespace system::under::test;
  
  my_test_case("test 2") {
      my_section("does Y") {
          // tests...
      }
  }
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#define CATCH_CONFIG_RUNNER
  #include "catch.hpp"
  #include "test1.cpp"
  #include "test1.2.cpp"
  #include "test2.cpp"
  #include "test3.cpp"
  
  int main( int argc, char* argv[] )
  {
      cleanDir("c:\\temp");
      init (argv);
      int result = Catch::Session().run( argc, argv );
      return ( result &lt; 0xff ? result : 0xff );
  }
  </code></pre>
  
  <p><strong>program output:</strong></p>
  
  <pre><code>=============================
  No tests ran
  error: TEST_CASE( "test 2" ) already defined.
      First seen at c:\tests\catchtest2\catchtest2\test1.2.cpp(3)
      Redefined at c:\tests\catchtest2\catchtest2\test1.2.cpp(3)
  </code></pre>