{"action":"created","issue":{"url":"https://api.github.com/repos/onqtam/doctest/issues/59","repository_url":"https://api.github.com/repos/onqtam/doctest","labels_url":"https://api.github.com/repos/onqtam/doctest/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/onqtam/doctest/issues/59/comments","events_url":"https://api.github.com/repos/onqtam/doctest/issues/59/events","html_url":"https://github.com/onqtam/doctest/issues/59","id":216606823,"number":59,"title":"Provide exit code option","user":{"login":"theldoria","id":1366671,"avatar_url":"https://avatars0.githubusercontent.com/u/1366671?v=3","gravatar_id":"","url":"https://api.github.com/users/theldoria","html_url":"https://github.com/theldoria","followers_url":"https://api.github.com/users/theldoria/followers","following_url":"https://api.github.com/users/theldoria/following{/other_user}","gists_url":"https://api.github.com/users/theldoria/gists{/gist_id}","starred_url":"https://api.github.com/users/theldoria/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theldoria/subscriptions","organizations_url":"https://api.github.com/users/theldoria/orgs","repos_url":"https://api.github.com/users/theldoria/repos","events_url":"https://api.github.com/users/theldoria/events{/privacy}","received_events_url":"https://api.github.com/users/theldoria/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-03-23T23:57:32Z","updated_at":"2017-03-24T14:42:56Z","closed_at":"2017-03-24T14:42:56Z","body":"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.\r\n\r\n\r\nBackground:\r\nI 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.\r\n\r\nExample of what I need to do:\r\n```\r\n#+HEADER: :exports both :results output\r\n#+HEADER: :includes <iostream> <unistd.h>\r\n#+HEADER: :main no\r\n#+HEADER: :flags -I. -std=c++03 -pedantic -Werror\r\n#+BEGIN_SRC C++\r\n#define DOCTEST_CONFIG_IMPLEMENT//_WITH_MAIN\r\n#include \"doctest.h\"\r\n\r\nstatic int factorial(int number)\r\n{\r\n   return number <= 1 ? number : factorial(number - 1) * number;\r\n}\r\n\r\nTEST_CASE(\"testing the factorial function\")\r\n{\r\n   CHECK(factorial(0) == 1);\r\n   CHECK(factorial(1) == 1);\r\n   CHECK(factorial(2) == 2);\r\n   CHECK(factorial(3) == 6);\r\n   CHECK(factorial(10) == 3628800);\r\n}\r\n\r\nint main(int argc, char** argv) {\r\n    doctest::Context context; // initialize\r\n\r\n    // defaults\r\n    context.addFilter(\"test-case-exclude\", \"*math*\"); // exclude test cases with \"math\" in their name\r\n    context.setOption(\"abort-after\", 5);              // stop test execution after 5 failed assertions\r\n    context.setOption(\"sort\", \"name\");                // sort the test cases by their name\r\n\r\n    context.applyCommandLine(argc, argv);\r\n\r\n    // overrides\r\n    context.setOption(\"no-breaks\", true);             // don't break in the debugger when assertions fail\r\n\r\n    int res = context.run(); // run\r\n\r\n    if(context.shouldExit()) // important - query flags (and --exit) rely on the user doing this\r\n        return res;          // propagate the result of the tests\r\n    \r\n    int client_stuff_return_code = 0;\r\n    // your program - if the testing framework is integrated in your production code\r\n    \r\n    return 0;//res + client_stuff_return_code; // the result from doctest is propagated here as well\r\n}\r\n#+END_SRC\r\n\r\n#+RESULTS:\r\n#+begin_example\r\n[doctest] doctest version is \"1.1.4\"\r\n[doctest] run with \"--help\" for options\r\n===============================================================================\r\n/tmp/babel-6771qy1/C-src-6771uQC.cpp(16)\r\ntesting the factorial function\r\n\r\n/tmp/babel-6771qy1/C-src-6771uQC.cpp(18) FAILED! \r\n  CHECK( factorial(0) == 1 )\r\nwith expansion:\r\n  CHECK( 0 == 1 )\r\n\r\n===============================================================================\r\n[doctest] test cases:    1 |    0 passed |    1 failed |    0 skipped\r\n[doctest] assertions:    5 |    4 passed |    1 failed |\r\n#+end_example\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/onqtam/doctest/issues/comments/289041903","html_url":"https://github.com/onqtam/doctest/issues/59#issuecomment-289041903","issue_url":"https://api.github.com/repos/onqtam/doctest/issues/59","id":289041903,"user":{"login":"theldoria","id":1366671,"avatar_url":"https://avatars0.githubusercontent.com/u/1366671?v=3","gravatar_id":"","url":"https://api.github.com/users/theldoria","html_url":"https://github.com/theldoria","followers_url":"https://api.github.com/users/theldoria/followers","following_url":"https://api.github.com/users/theldoria/following{/other_user}","gists_url":"https://api.github.com/users/theldoria/gists{/gist_id}","starred_url":"https://api.github.com/users/theldoria/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theldoria/subscriptions","organizations_url":"https://api.github.com/users/theldoria/orgs","repos_url":"https://api.github.com/users/theldoria/repos","events_url":"https://api.github.com/users/theldoria/events{/privacy}","received_events_url":"https://api.github.com/users/theldoria/received_events","type":"User","site_admin":false},"created_at":"2017-03-24T14:42:56Z","updated_at":"2017-03-24T14:42:56Z","body":"Hey, thanks. Yes that indeed did the trick.\r\n\r\nIn case someone else also cares, I now have this:\r\n```\r\n#+HEADER: :exports both :results output\r\n#+HEADER: :includes <iostream> <unistd.h>\r\n#+HEADER: :main no\r\n#+HEADER: :flags -I. -std=c++03 -pedantic -Werror\r\n#+HEADER: :cmdline --no-exitcode\r\n#+BEGIN_SRC C++\r\n#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN\r\n#define DOCTEST_CONFIG_COLORS_ANSI\r\n#include \"doctest.h\"\r\n\r\nstatic int factorial(int number)\r\n{\r\n   return number <= 1 ? number : factorial(number - 1) * number;\r\n}\r\n\r\nTEST_CASE(\"testing the factorial function\")\r\n{\r\n   CHECK(factorial(0) == 1);\r\n   CHECK(factorial(1) == 1);\r\n   CHECK(factorial(2) == 2);\r\n   CHECK(factorial(3) == 6);\r\n   CHECK(factorial(10) == 3628800);\r\n}\r\n#+END_SRC\r\n\r\n#+RESULTS:\r\n#+begin_example\r\n[doctest] doctest version is \"1.1.4\"\r\n[doctest] run with \"--help\" for options\r\n===============================================================================\r\nc:/Windows/TEMP/babel-12648gy4/C-src-126486SN.cpp(17)\r\ntesting the factorial function\r\n\r\nc:/Windows/TEMP/babel-12648gy4/C-src-126486SN.cpp(19) FAILED! \r\n  CHECK( factorial(0) == 1 )\r\nwith expansion:\r\n  CHECK( 0 == 1 )\r\n\r\n===============================================================================\r\n[doctest] test cases:    1 |    0 passed |    1 failed |    0 skipped\r\n[doctest] assertions:    5 |    4 passed |    1 failed |\r\n#+end_example\r\n```"}}
{"actor":{"display_login":"theldoria"}}