diff options
author | David Robillard <d@drobilla.net> | 2017-12-26 20:15:58 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2017-12-26 20:15:58 -0500 |
commit | 3d0606010358707ad9f3265e189417929d6b69b7 (patch) | |
tree | bd686a0ce77080779d36c96248f06ed93d08c282 /tests/test_utils.h | |
parent | 6a3d09d70bcad9844d8989640736b8b620b53642 (diff) | |
download | serd-3d0606010358707ad9f3265e189417929d6b69b7.tar.gz serd-3d0606010358707ad9f3265e189417929d6b69b7.tar.bz2 serd-3d0606010358707ad9f3265e189417929d6b69b7.zip |
Report source file and line on test failures
Diffstat (limited to 'tests/test_utils.h')
-rw-r--r-- | tests/test_utils.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/test_utils.h b/tests/test_utils.h new file mode 100644 index 00000000..815d55fd --- /dev/null +++ b/tests/test_utils.h @@ -0,0 +1,42 @@ +/* + Copyright 2011-2017 David Robillard <http://drobilla.net> + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef SERD_TEST_UTILS_H +#define SERD_TEST_UTILS_H + +#include <stdarg.h> +#include <stdio.h> + +static inline int +serd_test_failure(const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + fprintf(stderr, "error: "); + vfprintf(stderr, fmt, args); + va_end(args); + return 1; +} + +#define FAIL(fmt) \ + fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \ + return serd_test_failure(fmt); + +#define FAILF(fmt, ...) \ + fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \ + return serd_test_failure(fmt, __VA_ARGS__); + +#endif /* SERD_TEST_UTILS_H */ |