diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2019-11-16 22:51:54 +0100 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2019-11-16 22:51:54 +0100 |
commit | 75520370b8f0c5afb8141b9808de69302d085d21 (patch) | |
tree | f851c4b4f62ad61c3c3aa2acad290b9941dc742d | |
parent | 95e2df8d14d36714cea2105673709166514cffd7 (diff) | |
download | ccache-75520370b8f0c5afb8141b9808de69302d085d21.tar.gz |
Ignore unknown sloppiness values in configuration files
Similar to 22db9ed893e9: This way legacy ccache versions can still work
with modern ccache configuration keys in the configuration files.
-rw-r--r-- | src/confitems.c | 7 | ||||
-rw-r--r-- | unittest/test_conf.c | 23 |
2 files changed, 20 insertions, 10 deletions
diff --git a/src/confitems.c b/src/confitems.c index d9d14bdd..4b70db4a 100644 --- a/src/confitems.c +++ b/src/confitems.c @@ -110,6 +110,8 @@ confitem_format_size(const void *value) bool confitem_parse_sloppiness(const char *str, void *result, char **errmsg) { + (void)errmsg; + unsigned *value = (unsigned *)result; if (!str) { return *value; @@ -141,11 +143,8 @@ confitem_parse_sloppiness(const char *str, void *result, char **errmsg) *value |= SLOPPY_CLANG_INDEX_STORE; } else if (str_eq(word, "locale")) { *value |= SLOPPY_LOCALE; - } else { - *errmsg = format("unknown sloppiness: \"%s\"", word); - free(p); - return false; } + // else: ignore unknown value for forward compatibility q = NULL; } free(p); diff --git a/unittest/test_conf.c b/unittest/test_conf.c index 7dba8571..da57bb4a 100644 --- a/unittest/test_conf.c +++ b/unittest/test_conf.c @@ -267,15 +267,13 @@ TEST(conf_read_invalid_size) conf_free(conf); } -TEST(conf_read_invalid_sloppiness) +TEST(conf_read_unknown_sloppiness) { struct conf *conf = conf_create(); char *errmsg; - create_file("ccache.conf", "sloppiness = file_macro, foo"); - CHECK(!conf_read(conf, "ccache.conf", &errmsg)); - CHECK_INT_EQ(errno, 0); - CHECK_STR_EQ_FREE2("ccache.conf:1: unknown sloppiness: \"foo\"", - errmsg); + create_file("ccache.conf", "sloppiness = time_macros, foo"); + CHECK(conf_read(conf, "ccache.conf", &errmsg)); + CHECK_INT_EQ(conf->sloppiness, SLOPPY_TIME_MACROS); conf_free(conf); } @@ -405,6 +403,19 @@ TEST(conf_set_unknown_option) CHECK_STR_EQ_FREE2("path = chocolate\nstats = chocolate\n", data); } +TEST(conf_set_unknown_sloppiness) +{ + char *errmsg; + char *data; + + create_file("ccache.conf", "path = vanilla\n"); + CHECK(conf_set_value_in_file("ccache.conf", "sloppiness", "foo", &errmsg)); + + data = read_text_file("ccache.conf", 0); + CHECK(data); + CHECK_STR_EQ_FREE2("path = vanilla\nsloppiness = foo\n", data); +} + TEST(conf_print_existing_value) { struct conf *conf = conf_create(); |