Skip to content

Commit

Permalink
tests: Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
andy5995 committed Feb 28, 2024
1 parent 484103b commit 8a4bcc6
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 30 deletions.
11 changes: 10 additions & 1 deletion example.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <stdio.h>

#include "test.h" // Used for canfigger test, not normally needed
#include "canfigger.h"

int
main(int argc, char *argv[])
{
char *default_filename = "../examplerc";
char *default_filename = SOURCE_DIR "/examplerc";
char *filename_ptr = default_filename;

if (argc == 2)
Expand All @@ -31,6 +32,9 @@ main(int argc, char *argv[])
if (!config)
return -1;

// i is only used for testing
int i = 0;

while (config != NULL)
{
//
Expand Down Expand Up @@ -60,7 +64,12 @@ main(int argc, char *argv[])
// Move to the next node and automatically free the current node
canfigger_free_current_key_node_advance(&config);
putchar('\n');

i++;
}

// This should be the number of keys in the example config
assert(i == 6);

return 0;
}
4 changes: 3 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ if get_option('build_examples')
example = executable(
'example',
'example.c',
dependencies: canfigger_dep
dependencies: canfigger_dep,
include_directories: 'tests',
c_args: '-DSOURCE_DIR="@0@"'.format(meson.current_source_dir())
)
endif

Expand Down
4 changes: 1 addition & 3 deletions tests/colons.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ main(void)
{"statement", "hello world", "obvious"},
};

char test_config_file[PATH_MAX];
sprintf(test_config_file, "%s/test_canfigger_colons.conf", SOURCE_DIR);
struct Canfigger *list = canfigger_parse_file(test_config_file, ':');
struct Canfigger *list = canfigger_parse_file(SOURCE_DIR "/test_canfigger_colons.conf", ':');
assert (list);

int i = 0;
Expand Down
8 changes: 1 addition & 7 deletions tests/file_open_err.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
int
main(void)
{
char test_config_file[PATH_MAX];
assert((size_t)
snprintf(test_config_file, sizeof test_config_file,
"%s/no_exist_test_canfigger.conf",
SOURCE_DIR) < sizeof test_config_file);

struct Canfigger *list = canfigger_parse_file(test_config_file, ',');
struct Canfigger *list = canfigger_parse_file("foo", ',');
assert(list == NULL);
assert(errno);
perror(__func__);
Expand Down
5 changes: 1 addition & 4 deletions tests/german.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ int main(void) {
const char *data3[] = {"zweite", "nach eins"};
const char *data4[] = {"ßchar", "Füße", "Gänsefüßchen", "über", "Änderung"};

char test_config_file[PATH_MAX];
assert((size_t)snprintf(test_config_file, sizeof test_config_file, "%s/german.conf", SOURCE_DIR) < sizeof test_config_file);

struct Canfigger *list = canfigger_parse_file(test_config_file, ',');
struct Canfigger *list = canfigger_parse_file(SOURCE_DIR "/german.conf", ',');
assert (list);

int i = 0;
Expand Down
8 changes: 1 addition & 7 deletions tests/multiple_attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@ main(void)
"after one",
};

char test_config_file[PATH_MAX];
assert((size_t)
snprintf(test_config_file, sizeof test_config_file,
"%s/multiple_attributes.conf",
SOURCE_DIR) < sizeof test_config_file);

// call the primary library function to read your config file
struct Canfigger *list = canfigger_parse_file(test_config_file, ',');
struct Canfigger *list = canfigger_parse_file(SOURCE_DIR "/multiple_attributes.conf", ',');
assert (list);

int i = 0;
Expand Down
8 changes: 1 addition & 7 deletions tests/unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@ main(void)
"Some cartoon characters will be very unhappy."},
};

char test_config_file[PATH_MAX];
assert((size_t)
snprintf(test_config_file, sizeof test_config_file,
"%s/test_unicode.conf",
SOURCE_DIR) < sizeof test_config_file);

// call the primary library function to read your config file
struct Canfigger *list = canfigger_parse_file(test_config_file, ';');
struct Canfigger *list = canfigger_parse_file(SOURCE_DIR "/test_unicode.conf", ';');
assert (list);

int i = 0;
Expand Down

0 comments on commit 8a4bcc6

Please sign in to comment.