Re: doctest rtems example

2023-06-27 Thread Sam Price
I was testing the out of box version of gtest.
It does not support parsing arguments more than once.
I think you have to load / unload the library between runs.

I would really prefer to use google test.  Its what most of our tests
are already in, and has support for utbot.org

Sam

On Sun, Jun 18, 2023 at 7:25 PM Chris Johns  wrote:
>
> Hi Sam,
>
> Thanks for the post. The website for the code is:
>
> https://github.com/doctest/doctest
>
> I have been using this and I can port tests between Linux and RTEMS. I like it
> because it works and it is a single header. There is no need to build and link
> libraries.
>
> Chris
>
> On 16/6/2023 11:07 pm, Sam Price wrote:
> > /* Tell doctest to not use its own main */
> > #define DOCTEST_CONFIG_IMPLEMENT
> > /* tell doctest to not use sigint that rtems does not have */
> > #define DOCTEST_CONFIG_NO_POSIX_SIGNALS
> > #include "doctest.h"
> >
> > /* Setup command line part */
> > const char rtems_test_name[] = "DOCTEST UNIT TESTS";
> >
> > static int run_doctest_tests(int argc, char **argv) {
> >
> > // Initialize doctest context
> > doctest::Context context(argc, argv);
> >
> > int test_result = context.run(); // run queries, or run tests unless 
> > --no-run
> >
> > if(context.shouldExit()) // honor query flags and --exit
> > return test_result;
> > return 0;
> > }
> >
> > rtems_shell_cmd_t Shell_DOCTEST_Command = {
> > "doctest", /* name */
> > "doctest [doctest options]", /* usage */
> > "tests", /* topic */
> > run_doctest_tests, /* command */
> > NULL, /* alias */
> > NULL /* next */
> > };
> >
> > /* Inside of your Init add the following prior to starting shell */
> > rtems_task Init(rtems_task_argument ignored)
> > {
> > 
> >
> > rtems_shell_add_cmd_struct(_DOCTEST_Command);
> > /* Note i made this high priority, some of my tests require priority 
> > access. */
> > /* It may be better to use 100, and use the following in your test
> > rtems_task_priority old_priority;
> > rtems_task_set_priority(RTEMS_SELF, 0, _priority);
> > ...
> > rtems_task_set_priority(RTEMS_SELF, old_priority, 0x0);
> > */
> >
> > rtems_shell_init("shell0", 20 * 1024, 2, "/dev/console", 0, 1, NULL);
> > ...
> > }
> >
> > TEST_CASE("testing the addition function") {
> > CHECK((2 + 2) == 4);
> > CHECK((2 + 2) == 4.0);
> > }
> > ___
> > devel mailing list
> > devel@rtems.org
> > http://lists.rtems.org/mailman/listinfo/devel
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel



-- 
Sincerely,

Sam Price
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: doctest rtems example

2023-06-18 Thread Chris Johns
Hi Sam,

Thanks for the post. The website for the code is:

https://github.com/doctest/doctest

I have been using this and I can port tests between Linux and RTEMS. I like it
because it works and it is a single header. There is no need to build and link
libraries.

Chris

On 16/6/2023 11:07 pm, Sam Price wrote:
> /* Tell doctest to not use its own main */
> #define DOCTEST_CONFIG_IMPLEMENT
> /* tell doctest to not use sigint that rtems does not have */
> #define DOCTEST_CONFIG_NO_POSIX_SIGNALS
> #include "doctest.h"
> 
> /* Setup command line part */
> const char rtems_test_name[] = "DOCTEST UNIT TESTS";
> 
> static int run_doctest_tests(int argc, char **argv) {
> 
> // Initialize doctest context
> doctest::Context context(argc, argv);
> 
> int test_result = context.run(); // run queries, or run tests unless --no-run
> 
> if(context.shouldExit()) // honor query flags and --exit
> return test_result;
> return 0;
> }
> 
> rtems_shell_cmd_t Shell_DOCTEST_Command = {
> "doctest", /* name */
> "doctest [doctest options]", /* usage */
> "tests", /* topic */
> run_doctest_tests, /* command */
> NULL, /* alias */
> NULL /* next */
> };
> 
> /* Inside of your Init add the following prior to starting shell */
> rtems_task Init(rtems_task_argument ignored)
> {
> 
> 
> rtems_shell_add_cmd_struct(_DOCTEST_Command);
> /* Note i made this high priority, some of my tests require priority access. 
> */
> /* It may be better to use 100, and use the following in your test
> rtems_task_priority old_priority;
> rtems_task_set_priority(RTEMS_SELF, 0, _priority);
> ...
> rtems_task_set_priority(RTEMS_SELF, old_priority, 0x0);
> */
> 
> rtems_shell_init("shell0", 20 * 1024, 2, "/dev/console", 0, 1, NULL);
> ...
> }
> 
> TEST_CASE("testing the addition function") {
> CHECK((2 + 2) == 4);
> CHECK((2 + 2) == 4.0);
> }
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


doctest rtems example

2023-06-16 Thread Sam Price
/* Tell doctest to not use its own main */
#define DOCTEST_CONFIG_IMPLEMENT
/* tell doctest to not use sigint that rtems does not have */
#define DOCTEST_CONFIG_NO_POSIX_SIGNALS
#include "doctest.h"

/* Setup command line part */
const char rtems_test_name[] = "DOCTEST UNIT TESTS";

static int run_doctest_tests(int argc, char **argv) {

// Initialize doctest context
doctest::Context context(argc, argv);

int test_result = context.run(); // run queries, or run tests unless --no-run

if(context.shouldExit()) // honor query flags and --exit
return test_result;
return 0;
}

rtems_shell_cmd_t Shell_DOCTEST_Command = {
"doctest", /* name */
"doctest [doctest options]", /* usage */
"tests", /* topic */
run_doctest_tests, /* command */
NULL, /* alias */
NULL /* next */
};

/* Inside of your Init add the following prior to starting shell */
rtems_task Init(rtems_task_argument ignored)
{


rtems_shell_add_cmd_struct(_DOCTEST_Command);
/* Note i made this high priority, some of my tests require priority access. */
/* It may be better to use 100, and use the following in your test
rtems_task_priority old_priority;
rtems_task_set_priority(RTEMS_SELF, 0, _priority);
...
rtems_task_set_priority(RTEMS_SELF, old_priority, 0x0);
*/

rtems_shell_init("shell0", 20 * 1024, 2, "/dev/console", 0, 1, NULL);
...
}

TEST_CASE("testing the addition function") {
CHECK((2 + 2) == 4);
CHECK((2 + 2) == 4.0);
}
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel