diff options
| -rw-r--r-- | meson.build | 28 | ||||
| -rw-r--r-- | meson_options.txt | 5 | ||||
| -rw-r--r-- | src/compfy.c | 1 | ||||
| -rw-r--r-- | src/config.c | 32 | ||||
| -rw-r--r-- | src/meson.build | 2 | ||||
| -rw-r--r-- | src/string_utils.c | 59 | ||||
| -rw-r--r-- | src/utils.h | 2 | ||||
| -rw-r--r-- | subprojects/test.h/meson.build | 2 | ||||
| -rw-r--r-- | subprojects/test.h/test.h | 211 |
9 files changed, 3 insertions, 339 deletions
diff --git a/meson.build b/meson.build index e74d184..d162424 100644 --- a/meson.build +++ b/meson.build @@ -12,32 +12,6 @@ if get_option('buildtype') == 'release' add_global_arguments('-DNDEBUG', language: 'c') endif -if get_option('sanitize') - sanitizers = ['address', 'undefined'] - if cc.has_argument('-fsanitize=integer') - sanitizers += ['integer'] - endif - if cc.has_argument('-fsanitize=nullability') - sanitizers += ['nullability'] - endif - add_global_arguments('-fsanitize='+','.join(sanitizers), language: 'c') - add_global_link_arguments('-fsanitize='+','.join(sanitizers), language: 'c') - if cc.has_argument('-fno-sanitize=unsigned-integer-overflow') - add_global_arguments('-fno-sanitize=unsigned-integer-overflow', language: 'c') - endif -endif - -if get_option('modularize') - if not cc.has_argument('-fmodules') - error('option \'modularize\' requires clang') - endif - add_global_arguments(['-fmodules', - '-fmodule-map-file='+ - meson.current_source_dir()+ - '/src/compfy.modulemap'], - language: 'c') -endif - add_global_arguments('-D_GNU_SOURCE', language: 'c') if cc.has_header('stdc-predef.h') @@ -61,8 +35,6 @@ if get_option('with_docs') install_data('./man/compfy.1', install_dir: join_paths(get_option('mandir'), 'man1')) endif -test_h_dep = subproject('test.h').get_variable('test_h_dep') - subdir('src') install_data('compfy.desktop', install_dir: 'share/applications') diff --git a/meson_options.txt b/meson_options.txt index e625bc0..8e1daba 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,10 +1,11 @@ -option('sanitize', type: 'boolean', value: false, description: 'Build with sanitizers enabled (deprecated)') option('config_file', type: 'boolean', value: true, description: 'Enable config file support') + option('regex', type: 'boolean', value: true, description: 'Enable regex support in window conditions') option('vsync_drm', type: 'boolean', value: false, description: 'Enable support for using drm for vsync') option('opengl', type: 'boolean', value: true, description: 'Enable features that require opengl (opengl backend, and opengl vsync methods)') + option('dbus', type: 'boolean', value: true, description: 'Enable support for D-Bus remote control') option('xrescheck', type: 'boolean', value: false, description: 'Enable X resource leak checker (for debug only)') @@ -13,6 +14,4 @@ option('with_docs', type: 'boolean', value: true, description: 'Build documentat option('update_checks', type: 'boolean', value: false, description: 'Gives access to --check-for-updates option') -option('modularize', type: 'boolean', value: false, description: 'Build with clang\'s module system') - option('unittest', type: 'boolean', value: false, description: 'Enable unittests in the code') diff --git a/src/compfy.c b/src/compfy.c index 29cbe08..975bfaf 100644 --- a/src/compfy.c +++ b/src/compfy.c @@ -21,7 +21,6 @@ #include <xcb/xinerama.h> #include <ev.h> -#include <test.h> #include "common.h" #include "compiler.h" diff --git a/src/config.c b/src/config.c index d23a69a..deca6ad 100644 --- a/src/config.c +++ b/src/config.c @@ -16,8 +16,6 @@ #include <unistd.h> #include <xcb/render.h> // for xcb_render_fixed_t, XXX -#include <test.h> - #include "c2.h" #include "common.h" #include "compiler.h" @@ -93,36 +91,6 @@ char **xdg_config_dirs(void) { return dir_list; } -TEST_CASE(xdg_config_dirs) { - auto old_var = getenv("XDG_CONFIG_DIRS"); - if (old_var) { - old_var = strdup(old_var); - } - unsetenv("XDG_CONFIG_DIRS"); - - auto result = xdg_config_dirs(); - TEST_STREQUAL(result[0], "/etc/xdg"); - TEST_EQUAL(result[1], NULL); - free(result); - - setenv("XDG_CONFIG_DIRS", ".:.:/etc/xdg:.:/:", 1); - result = xdg_config_dirs(); - TEST_STREQUAL(result[0], "/etc/xdg"); - TEST_STREQUAL(result[1], "/"); - TEST_EQUAL(result[2], NULL); - free(result); - - setenv("XDG_CONFIG_DIRS", ":", 1); - result = xdg_config_dirs(); - TEST_EQUAL(result[0], NULL); - free(result); - - if (old_var) { - setenv("XDG_CONFIG_DIRS", old_var, 1); - free(old_var); - } -} - /** * Parse a long number. */ diff --git a/src/meson.build b/src/meson.build index 60d1893..a1da5a6 100644 --- a/src/meson.build +++ b/src/meson.build @@ -91,7 +91,7 @@ endif subdir('backend') compfy = executable('compfy', srcs, c_args: cflags, - dependencies: [ base_deps, deps, test_h_dep ], + dependencies: [ base_deps, deps ], install: true, include_directories: compfy_inc) if get_option('unittest') diff --git a/src/string_utils.c b/src/string_utils.c index ee5bb2d..871f29a 100644 --- a/src/string_utils.c +++ b/src/string_utils.c @@ -3,8 +3,6 @@ #include <string.h> -#include <test.h> - #include "compiler.h" #include "string_utils.h" #include "utils.h" @@ -35,20 +33,6 @@ char *mstrjoin(const char *src1, const char *src2) { return str; } -TEST_CASE(mstrjoin) { - char *str = mstrjoin("asdf", "qwer"); - TEST_STREQUAL(str, "asdfqwer"); - free(str); - - str = mstrjoin("", "qwer"); - TEST_STREQUAL(str, "qwer"); - free(str); - - str = mstrjoin("asdf", ""); - TEST_STREQUAL(str, "asdf"); - free(str); -} - /** * Concatenate a string on heap with another string. */ @@ -67,19 +51,6 @@ void mstrextend(char **psrc1, const char *src2) { (*psrc1)[len - 1] = '\0'; } -TEST_CASE(mstrextend) { - char *str1 = NULL; - mstrextend(&str1, "asdf"); - TEST_STREQUAL(str1, "asdf"); - - mstrextend(&str1, "asd"); - TEST_STREQUAL(str1, "asdfasd"); - - mstrextend(&str1, ""); - TEST_STREQUAL(str1, "asdfasd"); - free(str1); -} - #pragma GCC diagnostic pop /// Parse a floating point number of form (+|-)?[0-9]*(\.[0-9]*) @@ -113,21 +84,6 @@ double strtod_simple(const char *src, const char **end) { return ret * neg; } -TEST_CASE(strtod_simple) { - const char *end; - double result = strtod_simple("1.0", &end); - TEST_EQUAL(result, 1); - TEST_EQUAL(*end, '\0'); - - result = strtod_simple("-1.0", &end); - TEST_EQUAL(result, -1); - TEST_EQUAL(*end, '\0'); - - result = strtod_simple("+.5", &end); - TEST_EQUAL(result, 0.5); - TEST_EQUAL(*end, '\0'); -} - const char *trim_both(const char *src, size_t *length) { size_t i = 0; while (isspace(src[i])) { @@ -140,18 +96,3 @@ const char *trim_both(const char *src, size_t *length) { *length = j - i + 1; return src + i; } - -TEST_CASE(trim_both) { - size_t length; - const char *str = trim_both(" \t\n\r\f", &length); - TEST_EQUAL(length, 0); - TEST_EQUAL(*str, '\0'); - - str = trim_both(" asdfas ", &length); - TEST_EQUAL(length, 6); - TEST_STRNEQUAL(str, "asdfas", length); - - str = trim_both(" asdf asdf ", &length); - TEST_EQUAL(length, 9); - TEST_STRNEQUAL(str, "asdf asdf", length); -} diff --git a/src/utils.h b/src/utils.h index a35bfa8..80dab92 100644 --- a/src/utils.h +++ b/src/utils.h @@ -12,8 +12,6 @@ #include <string.h> #include <unistd.h> -#include <test.h> - #include <time.h> #include "compiler.h" diff --git a/subprojects/test.h/meson.build b/subprojects/test.h/meson.build deleted file mode 100644 index 042e5d5..0000000 --- a/subprojects/test.h/meson.build +++ /dev/null @@ -1,2 +0,0 @@ -project('test.h', 'c') -test_h_dep = declare_dependency(include_directories: include_directories('.')) diff --git a/subprojects/test.h/test.h b/subprojects/test.h/test.h deleted file mode 100644 index 71522e1..0000000 --- a/subprojects/test.h/test.h +++ /dev/null @@ -1,211 +0,0 @@ -// SPDX-License-Identifier: MIT -#pragma once - -#ifdef UNIT_TEST - -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ - defined(__NetBSD__) || defined(__OpenBSD__) -#define USE_SYSCTL_FOR_ARGS 1 -// clang-format off -#include <sys/types.h> -#include <sys/sysctl.h> -// clang-format on -#include <unistd.h> // getpid -#endif - -struct test_file_metadata; - -struct test_failure { - bool present; - const char *message; - const char *file; - int line; - bool owned; -}; - -struct test_case_metadata { - void (*fn)(struct test_case_metadata *, struct test_file_metadata *); - struct test_failure failure; - const char *name; - struct test_case_metadata *next; -}; - -struct test_file_metadata { - bool registered; - const char *name; - struct test_file_metadata *next; - struct test_case_metadata *tests; -}; - -struct test_file_metadata __attribute__((weak)) * test_file_head; - -#define SET_FAILURE(_message, _owned) \ - metadata->failure = (struct test_failure) { \ - .message = _message, .file = __FILE__, .line = __LINE__, \ - .present = true, .owned = _owned, \ - } - -#define TEST_EQUAL(a, b) \ - do { \ - if ((a) != (b)) { \ - SET_FAILURE(#a " != " #b, false); \ - return; \ - } \ - } while (0) - -#define TEST_TRUE(a) \ - do { \ - if (!(a)) { \ - SET_FAILURE(#a " is not true", false); \ - return; \ - } \ - } while (0) - -#define TEST_STREQUAL(a, b) \ - do { \ - if (strcmp(a, b) != 0) { \ - const char *part2 = " != " #b; \ - size_t len = strlen(a) + strlen(part2) + 3; \ - char *buf = malloc(len); \ - snprintf(buf, len, "\"%s\"%s", a, part2); \ - SET_FAILURE(buf, true); \ - return; \ - } \ - } while (0) - -#define TEST_STRNEQUAL(a, b, len) \ - do { \ - if (strncmp(a, b, len) != 0) { \ - const char *part2 = " != " #b; \ - size_t len2 = len + strlen(part2) + 3; \ - char *buf = malloc(len2); \ - snprintf(buf, len2, "\"%.*s\"%s", (int)len, a, part2); \ - SET_FAILURE(buf, true); \ - return; \ - } \ - } while (0) - -#define TEST_CASE(_name) \ - static void __test_h_##_name(struct test_case_metadata *, \ - struct test_file_metadata *); \ - static struct test_file_metadata __test_h_file; \ - static struct test_case_metadata __test_h_meta_##_name = { \ - .name = #_name, \ - .fn = __test_h_##_name, \ - }; \ - static void __attribute__((constructor(101))) __test_h_##_name##_register(void) { \ - __test_h_meta_##_name.next = __test_h_file.tests; \ - __test_h_file.tests = &__test_h_meta_##_name; \ - if (!__test_h_file.registered) { \ - __test_h_file.name = __FILE__; \ - __test_h_file.next = test_file_head; \ - test_file_head = &__test_h_file; \ - __test_h_file.registered = true; \ - } \ - } \ - static void __test_h_##_name( \ - struct test_case_metadata *metadata __attribute__((unused)), \ - struct test_file_metadata *file_metadata __attribute__((unused))) - -extern void __attribute__((weak)) (*test_h_unittest_setup)(void); -/// Run defined tests, return true if all tests succeeds -/// @param[out] tests_run if not NULL, set to whether tests were run -static inline void __attribute__((constructor(102))) run_tests(void) { - bool should_run = false; -#ifdef USE_SYSCTL_FOR_ARGS - int mib[] = { - CTL_KERN, -#if defined(__NetBSD__) || defined(__OpenBSD__) - KERN_PROC_ARGS, - getpid(), - KERN_PROC_ARGV, -#else - KERN_PROC, - KERN_PROC_ARGS, - getpid(), -#endif - }; - char *arg = NULL; - size_t arglen; - sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &arglen, NULL, 0); - arg = malloc(arglen); - sysctl(mib, sizeof(mib) / sizeof(mib[0]), arg, &arglen, NULL, 0); -#else - FILE *cmdlinef = fopen("/proc/self/cmdline", "r"); - char *arg = NULL; - int arglen; - fscanf(cmdlinef, "%ms%n", &arg, &arglen); - fclose(cmdlinef); -#endif - for (char *pos = arg; pos < arg + arglen; pos += strlen(pos) + 1) { - if (strcmp(pos, "--unittest") == 0) { - should_run = true; - break; - } - } - free(arg); - - if (!should_run) { - return; - } - - if (&test_h_unittest_setup) { - test_h_unittest_setup(); - } - - struct test_file_metadata *i = test_file_head; - int failed = 0, success = 0; - while (i) { - fprintf(stderr, "Running tests from %s:\n", i->name); - struct test_case_metadata *j = i->tests; - while (j) { - fprintf(stderr, "\t%s ... ", j->name); - j->failure.present = false; - j->fn(j, i); - if (j->failure.present) { - fprintf(stderr, "failed (%s at %s:%d)\n", j->failure.message, - j->failure.file, j->failure.line); - if (j->failure.owned) { - free((char *)j->failure.message); - j->failure.message = NULL; - } - failed++; - } else { - fprintf(stderr, "passed\n"); - success++; - } - j = j->next; - } - fprintf(stderr, "\n"); - i = i->next; - } - int total = failed + success; - fprintf(stderr, "Test results: passed %d/%d, failed %d/%d\n", success, total, - failed, total); - exit(failed == 0 ? EXIT_SUCCESS : EXIT_FAILURE); -} - -#else - -#include <stdbool.h> - -#define TEST_CASE(name) static void __attribute__((unused)) __test_h_##name(void) - -#define TEST_EQUAL(a, b) \ - (void)(a); \ - (void)(b) -#define TEST_TRUE(a) (void)(a) -#define TEST_STREQUAL(a, b) \ - (void)(a); \ - (void)(b) -#define TEST_STRNEQUAL(a, b, len) \ - (void)(a); \ - (void)(b); \ - (void)(len) - -#endif |