You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need an option to define exit code value. I am personally interest in setting it to zero, independent from test results, but would be happy to be able to set it for success and failure separately.
Background:
I am currently using this framework within emacs org-mode in an source code block, which can be executed within emacs, adding the result into the document. This, however, does not work if the exit code is not zero, because noting is added. But exactly that case would be of interest.
Example of what I need to do:
#+HEADER: :exports both :results output
#+HEADER: :includes <iostream> <unistd.h>
#+HEADER: :main no
#+HEADER: :flags -I. -std=c++03 -pedantic -Werror
#+BEGIN_SRC C++
#define DOCTEST_CONFIG_IMPLEMENT//_WITH_MAIN
#include "doctest.h"
static int factorial(int number)
{
return number <= 1 ? number : factorial(number - 1) * number;
}
TEST_CASE("testing the factorial function")
{
CHECK(factorial(0) == 1);
CHECK(factorial(1) == 1);
CHECK(factorial(2) == 2);
CHECK(factorial(3) == 6);
CHECK(factorial(10) == 3628800);
}
int main(int argc, char** argv) {
doctest::Context context; // initialize
// defaults
context.addFilter("test-case-exclude", "*math*"); // exclude test cases with "math" in their name
context.setOption("abort-after", 5); // stop test execution after 5 failed assertions
context.setOption("sort", "name"); // sort the test cases by their name
context.applyCommandLine(argc, argv);
// overrides
context.setOption("no-breaks", true); // don't break in the debugger when assertions fail
int res = context.run(); // run
if(context.shouldExit()) // important - query flags (and --exit) rely on the user doing this
return res; // propagate the result of the tests
int client_stuff_return_code = 0;
// your program - if the testing framework is integrated in your production code
return 0;//res + client_stuff_return_code; // the result from doctest is propagated here as well
}
#+END_SRC
#+RESULTS:
#+begin_example
[doctest] doctest version is "1.1.4"
[doctest] run with "--help" for options
===============================================================================
/tmp/babel-6771qy1/C-src-6771uQC.cpp(16)
testing the factorial function
/tmp/babel-6771qy1/C-src-6771uQC.cpp(18) FAILED!
CHECK( factorial(0) == 1 )
with expansion:
CHECK( 0 == 1 )
===============================================================================
[doctest] test cases: 1 | 0 passed | 1 failed | 0 skipped
[doctest] assertions: 5 | 4 passed | 1 failed |
#+end_example
The text was updated successfully, but these errors were encountered:
There is the --no-exitcodecommand line option which does exactly that - always returns 0.
You could set it as a default (before the command line parsing) or as an override (after the command line parsing) with context.setOption("no-exitcode", true);
Does this help?
Also note that the calls to setOption() I've put in the examples of a user-provided main() are not really needed.
I need an option to define exit code value. I am personally interest in setting it to zero, independent from test results, but would be happy to be able to set it for success and failure separately.
Background:
I am currently using this framework within emacs org-mode in an source code block, which can be executed within emacs, adding the result into the document. This, however, does not work if the exit code is not zero, because noting is added. But exactly that case would be of interest.
Example of what I need to do:
The text was updated successfully, but these errors were encountered: