Skip to content

Instantly share code, notes, and snippets.

@logc
Created November 28, 2017 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logc/dfc7778e4770fc191b0c408023e01b70 to your computer and use it in GitHub Desktop.
Save logc/dfc7778e4770fc191b0c408023e01b70 to your computer and use it in GitHub Desktop.
Create a basic SCons project as Fish function
function mkscons --argument proj
mkdir -p $proj/include/core
mkdir -p $proj/src/core
mkdir -p $proj/tests/core
###############################################################################
# BUILD SCONSCRIPT
printf "\
env = Environment(CPPPATH=['include'])
env.Library(target='$proj', source=Glob('src/core/*.c'))
env.Program(target='$proj', source=Glob('src/*.c'),
LIBS=['$proj'], LIBPATH=['.'])
env.Program(target='test_$proj',
source=Glob('tests/*.c') + Glob('tests/**/*.c'),
LIBS=['$proj', 'check'], LIBPATH=['.'])
" > $proj/sconstruct
###############################################################################
# IMPLEMENTATION
printf "\
int $proj() {
return 0;
}
" > $proj/src/core/$proj.c
printf "\
#include \"core/$proj.h\"
int main() {
return $proj();
}
" > $proj/src/main.c
printf "\
int $proj();
" > $proj/include/core/$proj.h
###############################################################################
# TESTS
printf "\
#include <check.h>
START_TEST(test_fails)
{
ck_assert_int_eq(1, 2);
}
END_TEST
Suite * core_suite(void)
{
Suite *s;
TCase *tc_core;
s = suite_create(\"Core/$proj\");
/* Core test case */
tc_core = tcase_create(\"Core\");
tcase_add_test(tc_core, test_fails);
suite_add_tcase(s, tc_core);
return s;
}
" > $proj/tests/core/test_proj.c
printf "\
Suite * core_suite(void);
" > $proj/tests/core/test_$proj.h
printf "\
#include \"test_$proj.h\"
" > $proj/tests/core/tests.h
printf "\
#include <stdlib.h>
#include <check.h>
#include \"core/tests.h\"
int main(void)
{
int number_failed;
Suite *s;
SRunner *sr;
s = core_suite();
sr = srunner_create(s);
srunner_run_all(sr, CK_NORMAL);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
" > $proj/tests/main.c
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment