[systemd-devel] [PATCH] tests: add test for envfile with comments
Zbigniew Jędrzejewski-Szmek
zbyszek at in.waw.pl
Fri Feb 1 17:07:49 PST 2013
---
Hi,
can you check if it works with the following test case?
For me it doesn't, and I think there must be a bug.
Zbyszek
src/test/test-strv.c | 10 ++++-----
src/test/test-unit-file.c | 53 +++++++++++++++++++++++++++++++++--------------
2 files changed, 43 insertions(+), 20 deletions(-)
diff --git a/src/test/test-strv.c b/src/test/test-strv.c
index 7898ea7..8b09c97 100644
--- a/src/test/test-strv.c
+++ b/src/test/test-strv.c
@@ -71,27 +71,27 @@ static void test_strv_join(void) {
};
r = strv_join((char **)input_table_multiple, ", ");
- assert_se(streq(r, "one, two, three"));
+ assert(streq(r, "one, two, three"));
puts(r);
free(r);
r = strv_join((char **)input_table_multiple, ";");
- assert_se(streq(r, "one;two;three"));
+ assert(streq(r, "one;two;three"));
puts(r);
free(r);
r = strv_join((char **)input_table_multiple, NULL);
- assert_se(streq(r, "one two three"));
+ assert(streq(r, "one two three"));
puts(r);
free(r);
r = strv_join((char **)input_table_one, ", ");
- assert_se(streq(r, "one"));
+ assert(streq(r, "one"));
puts(r);
free(r);
r = strv_join((char **)input_table_none, ", ");
- assert_se(streq(r, ""));
+ assert(streq(r, ""));
puts(r);
free(r);
}
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
index 8519131..10e271e 100644
--- a/src/test/test-unit-file.c
+++ b/src/test/test-unit-file.c
@@ -193,17 +193,33 @@ static void test_config_parse_exec(void) {
#define env_file_2 \
"a\\\n"
-static void test_load_env_file_1(void) {
- char _cleanup_strv_free_ **data = NULL;
- int r;
+#define env_file_3 \
+ "#SPAMD_ARGS=\"-d --socketpath=/var/lib/bulwark/spamd \\\n" \
+ "#--nouser-config \\\n" \
+ "normal=line"
+static void write_read_env_file(char ***data, const char* text) {
char name[] = "/tmp/test-load-env-file.XXXXXX";
+ int r, i;
int _cleanup_close_ fd = mkstemp(name);
assert(fd >= 0);
- assert_se(write(fd, env_file_1, sizeof(env_file_1)) == sizeof(env_file_1));
- r = load_env_file(name, &data);
+ r = write(fd, text, strlen(text)+1);
+ assert_se(r == (int)strlen(text)+1);
+
+ r = load_env_file(name, data);
assert(r == 0);
+
+ for(i = 0; *data && (*data)[i]; i++)
+ puts((*data)[i]);
+
+ unlink(name);
+}
+
+static void test_load_env_file_1(void) {
+ char _cleanup_strv_free_ **data = NULL;
+ write_read_env_file(&data, env_file_1);
+
assert(streq(data[0], "a"));
assert(streq(data[1], "bc"));
assert(streq(data[2], "def"));
@@ -211,25 +227,31 @@ static void test_load_env_file_1(void) {
assert(streq(data[4], "h"));
assert(streq(data[5], "i\\"));
assert(data[6] == NULL);
- unlink(name);
}
static void test_load_env_file_2(void) {
char _cleanup_strv_free_ **data = NULL;
- int r;
-
- char name[] = "/tmp/test-load-env-file.XXXXXX";
- int _cleanup_close_ fd = mkstemp(name);
- assert(fd >= 0);
- assert_se(write(fd, env_file_2, sizeof(env_file_2)) == sizeof(env_file_2));
+ write_read_env_file(&data, env_file_2);
- r = load_env_file(name, &data);
- assert(r == 0);
assert(streq(data[0], "a"));
assert(data[1] == NULL);
- unlink(name);
}
+static void test_load_env_file_3(void) {
+ char _cleanup_strv_free_ **data = NULL;
+ write_read_env_file(&data, env_file_3);
+
+ assert(data);
+ assert(streq(data[0],
+ "#SPAMD_ARGS=\"-d --socketpath=/var/lib/bulwark/spamd \\"));
+ assert(streq(data[1],
+ "#--nouser-config \\"));
+ assert(streq(data[2],
+ "normal=line"));
+ assert(data[3] == NULL);
+}
+
+
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnonnull"
@@ -305,6 +327,7 @@ int main(int argc, char *argv[]) {
test_config_parse_exec();
test_load_env_file_1();
test_load_env_file_2();
+ test_load_env_file_3();
test_install_printf();
return 0;
--
1.8.1
More information about the systemd-devel
mailing list