I have started writing tests for the config functions. This has resulted in a few changes to the config code (tests working I guess) I have also added a special "all" config file which (as the name suggests) runs all test suites In the makefile I have added the compiled test files to the clean target and added targets for building and running testsmaster
parent
c046ac37a9
commit
e42705280c
4 changed files with 159 additions and 8 deletions
@ -0,0 +1,28 @@ |
||||
// This stops the main definintion in the sub suites
|
||||
#define MAINTEST |
||||
|
||||
#include "munit/munit.h" |
||||
#include "config.test.c" |
||||
#include <string.h> |
||||
#include <stdio.h> |
||||
|
||||
|
||||
|
||||
|
||||
int main (int argc, char* argv[]) { |
||||
|
||||
MunitSuite all_suites[] = { |
||||
config_test_suite, |
||||
{ NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE } |
||||
}; |
||||
|
||||
MunitSuite all_test_suite = { |
||||
"", /* name */ |
||||
NULL, /* tests */ |
||||
all_suites, /* suites */ |
||||
1, /* iterations */ |
||||
MUNIT_SUITE_OPTION_NONE /* options */ |
||||
}; |
||||
|
||||
return munit_suite_main(&all_test_suite, NULL, argc, argv); |
||||
} |
@ -0,0 +1,113 @@ |
||||
#include "munit/munit.h" |
||||
#include "../src/config.c" |
||||
#include <unistd.h> //This has getcwd |
||||
#include <stdlib.h> //This has getenv |
||||
|
||||
/*
|
||||
* Ensures that path_exists returns true on current working dir (should to exist) |
||||
*/ |
||||
MunitResult path_that_exists(const MunitParameter params[], |
||||
void* user_data_or_fixture){ |
||||
char cwd[500] = {'\0'}; |
||||
getcwd(cwd,500); |
||||
munit_assert_true( path_exists( cwd ) ); |
||||
return MUNIT_OK; |
||||
} |
||||
|
||||
MunitResult path_that_doesnt_exist(const MunitParameter params[], |
||||
void* user_data_or_fixture){ |
||||
char cwd[500] = {'\0'}; |
||||
getcwd(cwd,500); |
||||
strcat( cwd, "thisshoudldnotexist" ); |
||||
munit_assert_false( path_exists( cwd ) ); |
||||
return MUNIT_OK; |
||||
} |
||||
|
||||
MunitResult tilde_resolves_correctly(const MunitParameter params[], |
||||
void* user_data_or_fixture){ |
||||
munit_assert_string_equal( getenv("HOME"), resolveTilde("~") ); |
||||
return MUNIT_OK; |
||||
} |
||||
|
||||
|
||||
MunitResult check_config_dir_with_xdg(const MunitParameter params[], |
||||
void* user_data_or_fixture){ |
||||
char directory[] = "/testing/xdg/directory"; |
||||
setenv( "XDG_CONFIG_HOME",directory, 1 ); |
||||
munit_assert_string_equal( directory, getConfigDir() ); |
||||
return MUNIT_OK; |
||||
} |
||||
|
||||
MunitResult check_config_dir_without_xdg(const MunitParameter params[], |
||||
void* user_data_or_fixture){ |
||||
unsetenv( "XDG_CONFIG_HOME" ); |
||||
char dir[500] = {'\0'}; |
||||
strcpy( dir, getenv("HOME") ); |
||||
strcat( dir, "/.config" ); |
||||
munit_assert_string_equal( dir, getConfigDir() ); |
||||
return MUNIT_OK; |
||||
} |
||||
|
||||
|
||||
MunitTest tests[] = { |
||||
{ |
||||
"/path_exists/yes", /* name */ |
||||
path_that_exists, /* test */ |
||||
NULL, /* setup */ |
||||
NULL, /* tear_down */ |
||||
MUNIT_TEST_OPTION_NONE, /* options */ |
||||
NULL /* parameters */ |
||||
}, |
||||
{ |
||||
"/path_exists/no", /* name */ |
||||
path_that_doesnt_exist, /* test */ |
||||
NULL, /* setup */ |
||||
NULL, /* tear_down */ |
||||
MUNIT_TEST_OPTION_NONE, /* options */ |
||||
NULL /* parameters */ |
||||
}, |
||||
{ |
||||
"/TildeResolves", /* name */ |
||||
tilde_resolves_correctly, /* test */ |
||||
NULL, /* setup */ |
||||
NULL, /* tear_down */ |
||||
MUNIT_TEST_OPTION_NONE, /* options */ |
||||
NULL /* parameters */ |
||||
}, |
||||
{ |
||||
"/ConfigDir/WithXDG", /* name */ |
||||
check_config_dir_with_xdg, /* test */ |
||||
NULL, /* setup */ |
||||
NULL, /* tear_down */ |
||||
MUNIT_TEST_OPTION_NONE, /* options */ |
||||
NULL /* parameters */ |
||||
}, |
||||
{ |
||||
"/ConfigDir/WithoutXDG", /* name */ |
||||
check_config_dir_without_xdg, /* test */ |
||||
NULL, /* setup */ |
||||
NULL, /* tear_down */ |
||||
MUNIT_TEST_OPTION_NONE, /* options */ |
||||
NULL /* parameters */ |
||||
}, |
||||
/* Mark the end of the array with an entry where the test
|
||||
* function is NULL */ |
||||
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } |
||||
}; |
||||
|
||||
MunitSuite config_test_suite = { |
||||
"/config", /* name */ |
||||
tests, /* tests */ |
||||
NULL, /* suites */ |
||||
1, /* iterations */ |
||||
MUNIT_SUITE_OPTION_NONE /* options */ |
||||
}; |
||||
|
||||
#ifndef MAINTEST |
||||
#define MAINTEST |
||||
|
||||
int main (int argc, char* argv[]) { |
||||
return munit_suite_main(&config_test_suite, NULL, argc, argv); |
||||
} |
||||
|
||||
#endif /* ifndef MAINTEST */ |
Loading…
Reference in new issue