LMMP 4.3.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
test.c
浏览该文件的文档.
1/**
2 * Copyright (C) 2026 HJimmyK (Jericho Knox)
3 *
4 * This file is part of LMMP.
5 *
6 * LMMP is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 3 of
9 * the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <https://www.gnu.org/licenses/>.
19 *
20 * SPDX-License-Identifier: LGPL-3.0-or-later
21 */
22
23#include "test.h"
24
25static unsigned tests;
26static unsigned failed_tests;
27static unsigned checks;
28static unsigned failures;
29
30void lmmp_test_check(bool ok, const char *file, int line, const char *expr, const char *message) {
31 ++checks;
32 if (ok)
33 return;
34 ++failures;
35 fprintf(stderr, "%s:%d: %s", file, line, expr);
36 if (message)
37 fprintf(stderr, " (%s)", message);
38 fputc('\n', stderr);
39}
40
41void lmmp_test_run(const char *name, void (*test)(void)) {
42 unsigned before = failures;
43 ++tests;
44 printf("[ RUN ] %s\n", name);
45 test();
46 if (failures != before)
48 printf("[ %s ] %s\n", failures == before ? "PASSED" : "FAILED", name);
49}
50
52 printf("TOTAL: %u tests, %u failed, %u checks\n", tests, failed_tests, checks);
53 return failed_tests != 0;
54}
static unsigned checks
定义 test.c:27
int lmmp_test_finish(void)
定义 test.c:51
void lmmp_test_check(bool ok, const char *file, int line, const char *expr, const char *message)
定义 test.c:30
static unsigned failed_tests
定义 test.c:26
static unsigned tests
Copyright (C) 2026 HJimmyK (Jericho Knox)
定义 test.c:25
static unsigned failures
定义 test.c:28
void lmmp_test_run(const char *name, void(*test)(void))
定义 test.c:41