2020-11-05 15:34:58 +01:00
|
|
|
* QMCkl test :noexport:
|
2020-10-21 19:50:18 +02:00
|
|
|
|
2020-11-05 15:34:58 +01:00
|
|
|
This file is the main program of the unit tests. The tests rely on the
|
|
|
|
$\mu$unit framework, which is provided as a git submodule.
|
2020-10-22 01:24:14 +02:00
|
|
|
|
2020-11-05 15:34:58 +01:00
|
|
|
First, we use a script to find the list of all the produced test files:
|
|
|
|
#+NAME: test-files
|
|
|
|
#+BEGIN_SRC sh :exports none :results value
|
2020-10-21 19:50:18 +02:00
|
|
|
grep BEGIN_SRC *.org | \
|
|
|
|
grep test_qmckl_ | \
|
|
|
|
rev | \
|
|
|
|
cut -d ' ' -f 1 | \
|
|
|
|
rev | \
|
|
|
|
sort | \
|
|
|
|
uniq
|
2020-11-05 15:34:58 +01:00
|
|
|
#+END_SRC
|
2020-10-21 19:50:18 +02:00
|
|
|
|
2020-11-05 15:34:58 +01:00
|
|
|
#+RESULTS: test-files
|
|
|
|
| test_qmckl_ao.c |
|
|
|
|
| test_qmckl_context.c |
|
|
|
|
| test_qmckl_distance.c |
|
|
|
|
| test_qmckl_memory.c |
|
2020-10-21 19:50:18 +02:00
|
|
|
|
2020-11-05 15:34:58 +01:00
|
|
|
We generate the function headers
|
|
|
|
#+BEGIN_SRC sh :var files=test-files :exports output :results raw
|
2020-10-21 19:50:18 +02:00
|
|
|
echo "#+NAME: headers"
|
|
|
|
echo "#+BEGIN_SRC C :tangle no"
|
|
|
|
for file in $files
|
|
|
|
do
|
2020-11-05 15:34:58 +01:00
|
|
|
routine=${file%.c}
|
|
|
|
echo "MunitResult ${routine}();"
|
2020-10-21 19:50:18 +02:00
|
|
|
done
|
|
|
|
echo "#+END_SRC"
|
2020-11-05 15:34:58 +01:00
|
|
|
#+END_SRC
|
2020-10-21 19:50:18 +02:00
|
|
|
|
2020-11-05 15:34:58 +01:00
|
|
|
#+RESULTS:
|
|
|
|
#+NAME: headers
|
|
|
|
#+BEGIN_SRC C :tangle no
|
2020-10-25 15:02:37 +01:00
|
|
|
MunitResult test_qmckl_ao();
|
2020-10-21 19:50:18 +02:00
|
|
|
MunitResult test_qmckl_context();
|
2020-10-22 00:50:07 +02:00
|
|
|
MunitResult test_qmckl_distance();
|
2020-10-21 19:50:18 +02:00
|
|
|
MunitResult test_qmckl_memory();
|
2020-11-05 15:34:58 +01:00
|
|
|
#+END_SRC
|
2020-10-21 19:50:18 +02:00
|
|
|
|
2020-11-05 15:34:58 +01:00
|
|
|
and the required function calls:
|
|
|
|
#+BEGIN_SRC sh :var files=test-files :exports output :results raw
|
2020-10-21 19:50:18 +02:00
|
|
|
echo "#+NAME: calls"
|
|
|
|
echo "#+BEGIN_SRC C :tangle no"
|
|
|
|
for file in $files
|
|
|
|
do
|
2020-11-05 15:34:58 +01:00
|
|
|
routine=${file%.c}
|
|
|
|
echo " { (char*) \"${routine}\", ${routine}, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},"
|
2020-10-21 19:50:18 +02:00
|
|
|
done
|
|
|
|
echo "#+END_SRC"
|
2020-11-05 15:34:58 +01:00
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
#+NAME: calls
|
|
|
|
#+BEGIN_SRC C :tangle no
|
2020-10-25 15:02:37 +01:00
|
|
|
{ (char*) "test_qmckl_ao", test_qmckl_ao, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},
|
2020-10-21 19:50:18 +02:00
|
|
|
{ (char*) "test_qmckl_context", test_qmckl_context, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},
|
2020-10-22 00:50:07 +02:00
|
|
|
{ (char*) "test_qmckl_distance", test_qmckl_distance, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},
|
2020-10-21 19:50:18 +02:00
|
|
|
{ (char*) "test_qmckl_memory", test_qmckl_memory, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},
|
2020-11-05 15:34:58 +01:00
|
|
|
#+END_SRC
|
2020-10-21 19:50:18 +02:00
|
|
|
|
2020-11-05 15:34:58 +01:00
|
|
|
#+BEGIN_SRC C :comments link :noweb yes :tangle test_qmckl.c
|
2020-10-21 19:50:18 +02:00
|
|
|
#include "qmckl.h"
|
|
|
|
#include "munit.h"
|
|
|
|
<<headers>>
|
|
|
|
|
|
|
|
int main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)]) {
|
|
|
|
static MunitTest test_suite_tests[] =
|
|
|
|
{
|
2020-11-05 15:34:58 +01:00
|
|
|
<<calls>>
|
2020-10-21 19:50:18 +02:00
|
|
|
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
|
|
|
|
};
|
|
|
|
|
2020-11-05 15:34:58 +01:00
|
|
|
static const MunitSuite test_suite =
|
2020-10-21 19:50:18 +02:00
|
|
|
{
|
|
|
|
(char*) "", test_suite_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE
|
|
|
|
};
|
|
|
|
|
2020-11-05 15:34:58 +01:00
|
|
|
return munit_suite_main(&test_suite, (void*) "µnit", argc, argv);
|
|
|
|
}
|
|
|
|
#+END_SRC
|