Compare commits

...

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
738e4c4280
!23 Update TODO
From: @linker99 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
2023-12-27 06:47:56 +00:00
fandehui
12d175f073 Update TODO
This TODO was addressed here:

https://github.com/libcheck/check/pull/158
3987c1d906ee68e0a6a5fd7888d88e0873f914d9

Signed-off-by: fandehui <fandehui@xfusion.com>
2023-12-27 12:51:52 +08:00
openeuler-ci-bot
a78fdc11f6
!20 Fix START_TEST to look like valid C code
From: @linker99 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
2023-12-11 06:30:56 +00:00
openeuler-ci-bot
5dc7b8a094
!15 Fix title of web/install.html
From: @linker99 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
2023-11-24 06:30:10 +00:00
openeuler-ci-bot
c59e0b5681
!14 Fixed typo in ck_assert_str_eq doc
From: @linker99 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
2023-11-15 02:23:00 +00:00
openeuler-ci-bot
9a2ba6ccbc
!11 Add warning on floating point eq and ne assertions
From: @linker99 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
2023-11-10 01:46:28 +00:00
linker99
ac357b3ad6 Fix START_TEST to look like valid C code
Signed-off-by: linker99 <fandehui@xfusion.com>
2023-11-01 05:45:42 +08:00
linker99
eca98a2fc0 Fix title of web/install.html. 2023-10-31 21:51:56 +08:00
linker99
1301b0b081 Fixed typo in ck_assert_str_eq doc 2023-10-31 10:12:44 +08:00
linker99
e1116104ff Add warning on floating point eq and ne assertions
The usefulness of the float/double/ldouble eq and ne macros is very limited. Comparing
    the results of a floating point computation should be done with some tolerance, instead
    of expecting an exact answer. There may be differences on different platforms, etc.

    To this end, some warnings are added to the eq and ne functions, instead directing users
    to use the _tol functions instead.
2023-10-31 06:52:50 +08:00
6 changed files with 451 additions and 1 deletions

View File

@ -0,0 +1,100 @@
From bf671bfc8d86630e84892219196bf2dd5173306a Mon Sep 17 00:00:00 2001
From: Branden Archer <b.m.archer4@gmail.com>
Date: Sun, 22 Oct 2017 12:35:49 -0400
Subject: [PATCH] Add warning on floating point eq and ne assertions
The usefulness of the float/double/ldouble eq and ne macros is very limited. Comparing
the results of a floating point computation should be done with some tolerance, instead
of expecting an exact answer. There may be differences on different platforms, etc.
To this end, some warnings are added to the eq and ne functions, instead directing users
to use the _tol functions instead.
---
src/check.h.in | 36 ++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/src/check.h.in b/src/check.h.in
index 712caef..7966126 100644
--- a/src/check.h.in
+++ b/src/check.h.in
@@ -770,7 +770,11 @@ do { \
} while (0)
/**
- * Check two single precision floating point numbers to determine if X == Y
+ * Check two single precision floating point numbers to determine if X == Y.
+ *
+ * Note that the usefulness of this assertion is very limited. If you
+ * want to compare two floating point numbers for equality, you probably
+ * want to use ck_assert_float_eq_tol instead.
*
* If not X == Y, the test fails.
*
@@ -783,7 +787,11 @@ do { \
*/
#define ck_assert_float_eq(X, Y) _ck_assert_floating(X, ==, Y, float, "")
/**
- * Check two single precision floating point numbers to determine if X != Y
+ * Check two single precision floating point numbers to determine if X != Y.
+ *
+ * Note that the usefulness of this assertion is very limited. If you
+ * want to compare two floating point numbers for equality, you probably
+ * want to use ck_assert_float_ne_tol instead.
*
* If not X != Y, the test fails.
*
@@ -969,7 +977,11 @@ do { \
#define ck_assert_float_nonnan(X) _ck_assert_floating_nonnan(X, float, "")
/**
- * Check two double precision floating point numbers to determine if X == Y
+ * Check two double precision floating point numbers to determine if X == Y.
+ *
+ * Note that the usefulness of this assertion is very limited. If you
+ * want to compare two floating point numbers for equality, you probably
+ * want to use ck_assert_double_eq_tol instead.
*
* If not X == Y, the test fails.
*
@@ -982,7 +994,11 @@ do { \
*/
#define ck_assert_double_eq(X, Y) _ck_assert_floating(X, ==, Y, double, "")
/**
- * Check two double precision floating point numbers to determine if X != Y
+ * Check two double precision floating point numbers to determine if X != Y.
+ *
+ * Note that the usefulness of this assertion is very limited. If you
+ * want to compare two floating point numbers for equality, you probably
+ * want to use ck_assert_double_ne_tol instead.
*
* If not X != Y, the test fails.
*
@@ -1168,7 +1184,11 @@ do { \
#define ck_assert_double_nonnan(X) _ck_assert_floating_nonnan(X, double, "")
/**
- * Check two double precision floating point numbers to determine if X == Y
+ * Check two double precision floating point numbers to determine if X == Y.
+ *
+ * Note that the usefulness of this assertion is very limited. If you
+ * want to compare two floating point numbers for equality, you probably
+ * want to use ck_assert_ldouble_eq_tol instead.
*
* If not X == Y, the test fails.
*
@@ -1181,7 +1201,11 @@ do { \
*/
#define ck_assert_ldouble_eq(X, Y) _ck_assert_floating(X, ==, Y, long double, "L")
/**
- * Check two double precision floating point numbers to determine if X != Y
+ * Check two double precision floating point numbers to determine if X != Y.
+ *
+ * Note that the usefulness of this assertion is very limited. If you
+ * want to compare two floating point numbers for equality, you probably
+ * want to use ck_assert_ldouble_ne_tol instead.
*
* If not X != Y, the test fails.
*
--
2.27.0

View File

@ -0,0 +1,251 @@
From 3987c1d906ee68e0a6a5fd7888d88e0873f914d9 Mon Sep 17 00:00:00 2001
From: Filipe Brandenburger <filbranden@google.com>
Date: Tue, 12 Jun 2018 10:08:07 -0700
Subject: [PATCH] Fix START_TEST to look like valid C code.
Instead of exporting the defined name as a bare function, export a
struct that has a pointer to the function, but also its name, file and
line number where it is defined.
Store that information into a new `struct TTest`.
After this commit, START_TEST(<testname>) will create three definitions:
- <testname>_fn: The actual function;
- <testname>_ttest: A `struct TTest` with the information about it;
- <testname>: A pointer to <testname>_ttest.
Functions `tcase_add_test()` and friends are updated to take a `TTest *`
argument rather than a `TFun` and separate name. The runners are updated
to find that information inside the linked `tc->ttest`. The call to
`tcase_fn_start()` is moved from the defined functions to the runners
(both the "fork" and the "nofork" one) which call it just before
invoking the test function.
A nice side-effect is that END_TEST is now optional, though the empty
`#define` is kept for backwards compability.
v2: Initialize the struct TTest by position to be compatible with older
compilers that do not recognize named fields (e.g. VS 2010, VS 2012.)
Tested:
- `make check` still passes.
- Removing END_TEST from test cases still produces valid code that
builds and passes tests.
---
src/check.c | 10 +++++-----
src/check.h.in | 46 ++++++++++++++++++++++++++++------------------
src/check_impl.h | 3 +--
src/check_log.c | 2 +-
src/check_run.c | 10 ++++++----
5 files changed, 41 insertions(+), 30 deletions(-)
diff --git a/src/check.c b/src/check.c
index e42636e..9f9b251 100644
--- a/src/check.c
+++ b/src/check.c
@@ -247,21 +247,21 @@ void suite_add_tcase(Suite * s, TCase * tc)
check_list_add_end(s->tclst, tc);
}
-void _tcase_add_test(TCase * tc, TFun fn, const char *name, int _signal,
- int allowed_exit_value, int start, int end)
+void _tcase_add_test(TCase * tc, const TTest * ttest,
+ int _signal, int allowed_exit_value,
+ int start, int end)
{
TF *tf;
- if(tc == NULL || fn == NULL || name == NULL)
+ if(tc == NULL || ttest == NULL)
return;
tf = (TF *)emalloc(sizeof(TF)); /* freed in tcase_free */
- tf->fn = fn;
+ tf->ttest = ttest;
tf->loop_start = start;
tf->loop_end = end;
tf->signal = _signal; /* 0 means no signal expected */
tf->allowed_exit_value =
(WEXITSTATUS_MASK & allowed_exit_value); /* 0 is default successful exit */
- tf->name = name;
check_list_add_end(tc->tflst, tf);
}
diff --git a/src/check.h.in b/src/check.h.in
index 9e03d20..d546727 100644
--- a/src/check.h.in
+++ b/src/check.h.in
@@ -121,6 +121,16 @@ typedef void (*SFun) (void);
*/
typedef struct Suite Suite;
+/**
+ * Type for a test, which wraps a test function
+ */
+typedef struct TTest {
+ const char *name;
+ TFun fn;
+ const char *file;
+ int line;
+} TTest;
+
/**
* Creates a test suite with the given name.
*
@@ -214,8 +224,8 @@ CK_DLL_EXP void CK_EXPORT tcase_set_tags(TCase * tc,
*
* @since 0.9.2
* */
-#define tcase_add_test_raise_signal(tc,tf,signal) \
- _tcase_add_test((tc),(tf),"" # tf "",(signal), 0, 0, 1)
+#define tcase_add_test_raise_signal(tc,ttest,signal) \
+ _tcase_add_test((tc),(ttest),(signal), 0, 0, 1)
/**
* Add a test function with an expected exit value to a test case
@@ -229,8 +239,8 @@ CK_DLL_EXP void CK_EXPORT tcase_set_tags(TCase * tc,
*
* @since 0.9.7
*/
-#define tcase_add_exit_test(tc, tf, expected_exit_value) \
- _tcase_add_test((tc),(tf),"" # tf "",0,(expected_exit_value),0,1)
+#define tcase_add_exit_test(tc, ttest, expected_exit_value) \
+ _tcase_add_test((tc),(ttest),0,(expected_exit_value),0,1)
/**
* Add a looping test function to a test case
@@ -246,8 +256,8 @@ CK_DLL_EXP void CK_EXPORT tcase_set_tags(TCase * tc,
*
* @since 0.9.4
*/
-#define tcase_add_loop_test(tc,tf,s,e) \
- _tcase_add_test((tc),(tf),"" # tf "",0,0,(s),(e))
+#define tcase_add_loop_test(tc,ttest,s,e) \
+ _tcase_add_test((tc),(ttest),0,0,(s),(e))
/**
* Add a looping test function with signal handling to a test case
@@ -267,8 +277,8 @@ CK_DLL_EXP void CK_EXPORT tcase_set_tags(TCase * tc,
*
* @since 0.9.5
*/
-#define tcase_add_loop_test_raise_signal(tc,tf,signal,s,e) \
- _tcase_add_test((tc),(tf),"" # tf "",(signal),0,(s),(e))
+#define tcase_add_loop_test_raise_signal(tc,ttest,signal,s,e) \
+ _tcase_add_test((tc),(ttest),(signal),0,(s),(e))
/**
* Add a looping test function with an expected exit value to a test case
@@ -288,16 +298,15 @@ CK_DLL_EXP void CK_EXPORT tcase_set_tags(TCase * tc,
*
* @since 0.9.7
*/
-#define tcase_add_loop_exit_test(tc,tf,expected_exit_value,s,e) \
- _tcase_add_test((tc),(tf),"" # tf "",0,(expected_exit_value),(s),(e))
+#define tcase_add_loop_exit_test(tc,ttest,expected_exit_value,s,e) \
+ _tcase_add_test((tc),(ttest),0,(expected_exit_value),(s),(e))
/* Add a test function to a test case
(function version -- use this when the macro won't work
*/
-CK_DLL_EXP void CK_EXPORT _tcase_add_test(TCase * tc, TFun tf,
- const char *fname, int _signal,
- int allowed_exit_value, int start,
- int end);
+CK_DLL_EXP void CK_EXPORT _tcase_add_test(TCase * tc, const TTest * ttest,
+ int _signal, int allowed_exit_value,
+ int start, int end);
/**
* Add unchecked fixture setup/teardown functions to a test case
@@ -400,16 +409,17 @@ CK_DLL_EXP const char* CK_EXPORT tcase_name(void);
* @since 0.6.0
*/
#define START_TEST(__testname)\
-static void __testname (int _i CK_ATTRIBUTE_UNUSED)\
-{\
- tcase_fn_start (""# __testname, __FILE__, __LINE__);
+static void __testname ## _fn (int _i CK_ATTRIBUTE_UNUSED);\
+static const TTest __testname ## _ttest = {""# __testname, __testname ## _fn, __FILE__, __LINE__};\
+static const TTest * __testname = & __testname ## _ttest;\
+static void __testname ## _fn (int _i CK_ATTRIBUTE_UNUSED)
/**
* End a unit test
*
* @since 0.6.0
*/
-#define END_TEST }
+#define END_TEST
/*
* Fail the test case unless expr is false
diff --git a/src/check_impl.h b/src/check_impl.h
index bddd186..f4e8c59 100644
--- a/src/check_impl.h
+++ b/src/check_impl.h
@@ -36,10 +36,9 @@
typedef struct TF
{
- TFun fn;
+ const TTest * ttest;
int loop_start;
int loop_end;
- const char *name;
int signal;
signed char allowed_exit_value;
} TF;
diff --git a/src/check_log.c b/src/check_log.c
index 2af8321..c785b33 100644
--- a/src/check_log.c
+++ b/src/check_log.c
@@ -152,7 +152,7 @@ void log_test_start(SRunner * sr, TCase * tc, TF * tfun)
{
char buffer[100];
- snprintf(buffer, 99, "%s:%s", tc->name, tfun->name);
+ snprintf(buffer, 99, "%s:%s", tc->name, tfun->ttest->name);
srunner_send_evt(sr, buffer, CLSTART_T);
}
diff --git a/src/check_run.c b/src/check_run.c
index da1f40f..7e212e0 100644
--- a/src/check_run.c
+++ b/src/check_run.c
@@ -415,11 +415,12 @@ static TestResult *tcase_run_tfun_nofork(SRunner * sr, TCase * tc, TF * tfun,
clock_gettime(check_get_clockid(), &ts_start);
if(0 == setjmp(error_jmp_buffer))
{
- tfun->fn(i);
+ tcase_fn_start(tfun->ttest->name, tfun->ttest->file, tfun->ttest->line);
+ tfun->ttest->fn(i);
}
clock_gettime(check_get_clockid(), &ts_end);
tcase_run_checked_teardown(tc);
- return receive_result_info_nofork(tc->name, tfun->name, i,
+ return receive_result_info_nofork(tc->name, tfun->ttest->name, i,
DIFF_IN_USEC(ts_start, ts_end));
}
@@ -491,7 +492,8 @@ static TestResult *tcase_run_tfun_fork(SRunner * sr, TCase * tc, TF * tfun,
tr = tcase_run_checked_setup(sr, tc);
free(tr);
clock_gettime(check_get_clockid(), &ts_start);
- tfun->fn(i);
+ tcase_fn_start(tfun->ttest->name, tfun->ttest->file, tfun->ttest->line);
+ tfun->ttest->fn(i);
clock_gettime(check_get_clockid(), &ts_end);
tcase_run_checked_teardown(tc);
send_duration_info(DIFF_IN_USEC(ts_start, ts_end));
@@ -535,7 +537,7 @@ static TestResult *tcase_run_tfun_fork(SRunner * sr, TCase * tc, TF * tfun,
killpg(pid, SIGKILL); /* Kill remaining processes. */
- return receive_result_info_fork(tc->name, tfun->name, i, status,
+ return receive_result_info_fork(tc->name, tfun->ttest->name, i, status,
tfun->signal, tfun->allowed_exit_value);
}
--
2.27.0

View File

@ -0,0 +1,25 @@
From dd6fa23814a1e552652a407dff210e6606944b4f Mon Sep 17 00:00:00 2001
From: foviedoITBA <foviedo@itba.edu.ar>
Date: Thu, 16 Nov 2017 16:55:30 -0300
Subject: [PATCH] Fixed typo in ck_assert_str_eq doc
---
src/check.h.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/check.h.in b/src/check.h.in
index 7966126..9e03d20 100644
--- a/src/check.h.in
+++ b/src/check.h.in
@@ -1430,7 +1430,7 @@ do { \
* Check two strings to determine if 0==strcmp(X,Y)
*
* If X or Y is NULL the test failes.
- * If (0==strcmp(X,Y)), the test fails.
+ * If not 0==strcmp(X,Y), the test fails.
*
* @param X string
* @param Y string to compare against X
--
2.27.0

View File

@ -0,0 +1,29 @@
From 6e93935189d0fc0b958d087f007d2b90eeba2f87 Mon Sep 17 00:00:00 2001
From: Branden Archer <b.m.archer4@gmail.com>
Date: Wed, 20 Jun 2018 17:19:10 -0400
Subject: [PATCH] Update TODO
This TODO was addressed here:
https://github.com/libcheck/check/pull/158
3987c1d906ee68e0a6a5fd7888d88e0873f914d9
---
TODO | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/TODO b/TODO
index 7236c69..818f813 100644
--- a/TODO
+++ b/TODO
@@ -61,7 +61,7 @@ Check source code:
[ ] * Eliminate abbreviations like nf for number_failed
[0.9.13] * Run indent on everything, make sure it works well.
-[ ] * Fix START_TEST/END_TEST to look like valid C code.
+[0.13.0] * Fix START_TEST/END_TEST to look like valid C code.
[ ] * Document things way more.
[ ] * Create check.h automatically using makeheaders.c (not sure)
[ ] * Eliminate check_ prefix from files in src/ ... not needed
--
2.42.0.windows.2

View File

@ -0,0 +1,25 @@
From bc4f626be601556652a16d5e359362d7c7aedc0b Mon Sep 17 00:00:00 2001
From: James Prior <jep200404@columbus.rr.com>
Date: Sat, 25 Nov 2017 17:07:02 -0500
Subject: [PATCH] Fix title of web/install.html.
---
web/install.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/web/install.html b/web/install.html
index e017e5d..5977183 100644
--- a/web/install.html
+++ b/web/install.html
@@ -15,7 +15,7 @@ http://creativecommons.org/licenses/by-nc/2.5/
<meta name="keywords" content="check, unit test, c" />
<!-- Site Title -->
-<title>Check | Users of Check</title>
+<title>Check | Installing Check</title>
<!-- Link to Style External Sheet -->
<link href="css/style.css" type="text/css" rel="stylesheet" />
--
2.27.0

View File

@ -1,12 +1,17 @@
Name: check
Version: 0.12.0
Release: 4
Release: 9
Summary: A unit testing framework for C
Source0: https://github.com/libcheck/%{name}/archive/%{version}/%{name}-%{version}.tar.gz
License: LGPLv2+
URL: http://libcheck.github.io/check/
Patch0: %{name}-0.11.0-info-in-builddir.patch
Patch1: %{name}-0.11.0-fp.patch
Patch2: %{name}-0.12.0-Add-warning-on-floating-point-eq-and-ne-assertions.patch
Patch3: %{name}-0.12.0-Fixed-typo-in-ck_assert_str_eq-doc.patch
Patch4: %{name}-0.12.0-fix-title-of-web-install.html.patch
Patch5: %{name}-0.12.0-Fix-START_TEST-to-look-like-valid-C-code.patch
Patch6: %{name}-0.12.0-Update-TODO.patch
BuildRequires: gcc libtool patchutils pkgconfig
BuildRequires: subunit-devel texinfo
@ -93,5 +98,20 @@ make check
%{_mandir}/man1/checkmk.1*
%changelog
* Wed Dec 27 2023 fandehui <fandehui@xfusion.com> - 0.12.0-9
- Update TODO
* Mon Dec 11 2023 fandehui <fandehui@xfusion.com> - 0.12.0-8
- Fix START_TEST to look like valid C code.
* Fri Nov 24 2023 fandehui <fandehui@xfusion.com> - 0.12.0-7
- Fix title of web/install.html
* Tue Nov 14 2023 fandehui <fandehui@xfusion.com> - 0.12.0-6
- Fixed typo in ck_assert_str_eq doc
* Thu Nov 9 2023 fandehui <fandehui@xfusion.com> - 0.12.0-5
- Add warning on floating point eq and ne assertions
* Mon Dec 9 2019 mengxian <mengxian@huawei.com> - 0.12.0-4
- Package init