Note that there are some explanatory texts on larger screens.

plurals
  1. POcppunit to use command line arguments
    primarykey
    data
    text
    <p>I have a CPP unit test which tests a class which is designed to read configuration: we can call this class </p> <pre><code>Config </code></pre> <p>The config class has the capacity of doing</p> <pre><code>Config c; c.read("/tmp/random-tmp-directory/test.conf"); </code></pre> <p>The <code>random-temp-directory</code> is created by a bash script and should be passed into the test binary.</p> <pre><code>#!/bin/bash TEMPDIR=$(mktemp) cp files/config/test.conf $TEMPDIR/. ./testConfig $(mktemp)/test.conf </code></pre> <p>The above creates a temp directory, copies our temporary file and passes the path to the test, so it can load the correct file.</p> <p>Is there a way to tell CPPUNIT to send the commandline arguments, or any arguments to the test registry?</p> <p>Here is my <code>testConfig.cpp</code></p> <pre><code>#include &lt;all the required.h&gt; CPPUNIT_TEST_SUITE_REGISTRATION(testConfig); int main(int argc, char ** argv) { CPPUNIT_NS::TestResult testresult; CPPUNIT_NS::TestRunner runner; CPPUNIT_NS::TestFactoryRegistry &amp;registry = CPPUNIT_NS::TestFactoryRegistry::getRegistry(); // register listener for collecting the test-results CPPUNIT_NS::TestResultCollector collectedresults; testresult.addListener(&amp;collectedresults); runner.addTest(registry.makeTest()); runner.run(testresult); // Print test in a compiler compatible format. CppUnit::CompilerOutputter outputter( &amp;collectedresults, std::cerr ); outputter.write(); return collectedresults.wasSuccessful() ? 0 : 1; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload