From: Matthew Owens Date: Wed, 22 Dec 2021 22:39:42 +0000 (+0000) Subject: Initial commit X-Git-Url: https://git.owens.tech///git?a=commitdiff_plain;h=821f081a23c3b2fdef9262d2382c2c939bfc668f;p=AbyssalThistle%2Fqueue-test.git Initial commit --- 821f081a23c3b2fdef9262d2382c2c939bfc668f diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3326609 --- /dev/null +++ b/.gitignore @@ -0,0 +1,63 @@ +# Compiled Object files +*.slo +*.lo +*.o +*.obj +*.sto + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app +check +template + +# Libraries +*.a +*.so +*.dylib +*.lib +*.dll + +# Depend files +*.d + +# Subdirectories +obj/ +build/ +CMakeFiles/ + +# Make stuff +CMakeCache.txt +cmake_install.cmake +CmakeLists.txtt +*.sh + +# swap files +*.sw* + +# krita +*.kra +*.kra~ +*.png~ + +# Valgrind log +log diff --git a/README.md b/README.md new file mode 100644 index 0000000..9414afc --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# test-template + +template repo for quickly creating testable modules + +## usage +* create a new repo with [generate](https://github.com/AbyssalThistle/test-template/generate) +* add the new repo as a git submodule into your codebase +* navigate to the submodule directory and run `./init_tests $module` where +`$module` is the name of your cecse module, this should match your include headers. diff --git a/check_template.c b/check_template.c new file mode 100644 index 0000000..ba53e23 --- /dev/null +++ b/check_template.c @@ -0,0 +1,31 @@ +#include "check_template.h" +#include "template.h" +#include + +static void setup() +{ +} + +static void teardown() +{ +} + +START_TEST(test_template) +{ +} +END_TEST + +Suite *template_suite(void) +{ + Suite *s; + TCase *tc; + + s = suite_create("template suite"); + tc = tcase_create("template"); + + tcase_add_unchecked_fixture(tc, setup, teardown); + tcase_add_test(tc, test_template); + + suite_add_tcase(s, tc); + return s; +} diff --git a/check_template.h b/check_template.h new file mode 100644 index 0000000..23ad748 --- /dev/null +++ b/check_template.h @@ -0,0 +1,3 @@ +#pragma once +#include +Suite * template_suite(void); diff --git a/init_tests.sh b/init_tests.sh new file mode 100755 index 0000000..b0a23bc --- /dev/null +++ b/init_tests.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +function error() +{ + echo "provide a name" + exit 1 +} + +function init() +{ + echo "renaming template file & lines to $1" + upper=$(echo $1 | tr '[:lower:]' '[:upper:]') + under=$(echo $1 | tr '-' '_') + dashes=$(echo $1 | tr '_' '-') + + mv check_template.h check_$under.h + mv check_template.c check_$under.c + find . -type f -name '*.[c|h]' -exec sed -i "s/template/$under/g" {} + + sed -i "s/template/$dashes/g" .gitignore + sed -i "s/TEMPLATE/$upper/g" module.mk + + # clearing README + echo "# test-$dashes" > README.md +} + +# do we have a name parameter? +[ $# -eq 1 ] && init $1 || error +rm -- "$0" + +# clearing up source control +git rm check_template.c check_template.h $0 +git add check_$under.c check_$under.h README.md .gitignore main.c + +git commit -m "initilised repo" +git push diff --git a/main.c b/main.c new file mode 100644 index 0000000..72cc307 --- /dev/null +++ b/main.c @@ -0,0 +1,9 @@ +#include "runner.h" +#include "check_template.h" +#include + +int main() +{ + int failed_count = run_suite_forkless(template_suite()); + return (failed_count == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/runner.c b/runner.c new file mode 100644 index 0000000..7937846 --- /dev/null +++ b/runner.c @@ -0,0 +1,23 @@ +#include "runner.h" +#include + +int run_suite(Suite *s) +{ + int failed_count = 0; + SRunner *sr = srunner_create(s); + srunner_run_all(sr, CK_NORMAL); + failed_count += srunner_ntests_failed(sr); + srunner_free(sr); + return failed_count; +} + +int run_suite_forkless(Suite *s) +{ + int failed_count = 0; + SRunner *sr = srunner_create(s); + srunner_set_fork_status(sr, CK_NOFORK); + srunner_run_all(sr, CK_NORMAL); + failed_count += srunner_ntests_failed(sr); + srunner_free(sr); + return failed_count; +} diff --git a/runner.h b/runner.h new file mode 100644 index 0000000..cc2ed2a --- /dev/null +++ b/runner.h @@ -0,0 +1,4 @@ +#pragma once +#include +int run_suite(Suite *s); +int run_suite_forkless(Suite *s);