From 0bf8ca8820489ff7e154964771688c74eaf1933d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 4 Apr 2011 16:44:23 +0200 Subject: [PATCH] config: add tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These tests are basic, but they should tell us when we've broken something. Signed-off-by: Carlos Martín Nieto --- tests/resources/config/config0 | Bin 0 -> 295 bytes tests/resources/config/config1 | Bin 0 -> 98 bytes tests/resources/config/config2 | Bin 0 -> 96 bytes tests/resources/config/config3 | Bin 0 -> 87 bytes tests/t14-config.c | 121 +++++++++++++++++++++++++++++++++ tests/test_main.c | 2 + 6 files changed, 123 insertions(+) create mode 100644 tests/resources/config/config0 create mode 100644 tests/resources/config/config1 create mode 100644 tests/resources/config/config2 create mode 100644 tests/resources/config/config3 create mode 100644 tests/t14-config.c diff --git a/tests/resources/config/config0 b/tests/resources/config/config0 new file mode 100644 index 0000000000000000000000000000000000000000..85235c5012392fb8578a6d86e1207fa87b04a448 GIT binary patch literal 295 zcmd6jK?(vv3{}Mr R_yV;Dt2$&|Dvv^b#~-9dLT&&6 literal 0 HcmV?d00001 diff --git a/tests/resources/config/config1 b/tests/resources/config/config1 new file mode 100644 index 0000000000000000000000000000000000000000..211dc9e7d4c0692f767736df89e45954cf74ec47 GIT binary patch literal 98 zcmZX~F$#b%5Cp*5ykd#(@E7UCB7~DW0tw_+A-@+3E9;pRNzKulps1AUIQu}!E^ujX cwA(nt&UZy>W<0_IbgB$&;JD<|^wTLG9%Zs0+5i9m literal 0 HcmV?d00001 diff --git a/tests/resources/config/config2 b/tests/resources/config/config2 new file mode 100644 index 0000000000000000000000000000000000000000..60a389827c2c3c549fb77a489e8461a93b8836c3 GIT binary patch literal 96 zcmcCk2+7DSR>;pwRVYa%P&&MEzK#(%*h0bl_lnsrWSKWmw*&0g=8d_D8+Jd hDkvo8r6|~fb%At(a12*TdA5OESw+x!~%9 WOPyfqxi~q?5{ndUf% + +#define CONFIG_BASE TEST_RESOURCES "/config" + +/* + * This one is so we know the code isn't completely broken + */ +BEGIN_TEST(config0, "read a simple configuration") + git_config *cfg; + int i; + + must_pass(git_config_open(&cfg, CONFIG_BASE "/config0")); + must_pass(git_config_get_int(cfg, "core.repositoryformatversion", &i)); + must_be_true(i == 0); + must_pass(git_config_get_bool(cfg, "core.filemode", &i)); + must_be_true(i == 1); + must_pass(git_config_get_bool(cfg, "core.bare", &i)); + must_be_true(i == 0); + must_pass(git_config_get_bool(cfg, "core.logallrefupdates", &i)); + must_be_true(i == 1); + + git_config_free(cfg); +END_TEST + +/* + * [this "that"] and [this "That] are different namespaces. Make sure + * each returns the correct one. + */ +BEGIN_TEST(config1, "case sensitivity") + git_config *cfg; + int i; + const char *str; + + must_pass(git_config_open(&cfg, CONFIG_BASE "/config1")); + + must_pass(git_config_get_string(cfg, "this.that.other", &str)); + must_be_true(!strcmp(str, "true")); + must_pass(git_config_get_string(cfg, "this.That.other", &str)); + must_be_true(!strcmp(str, "yes")); + + must_pass(git_config_get_bool(cfg, "this.that.other", &i)); + must_be_true(i == 1); + must_pass(git_config_get_bool(cfg, "this.That.other", &i)); + must_be_true(i == 1); + + /* This one doesn't exist */ + must_fail(git_config_get_bool(cfg, "this.thaT.other", &i)); + + git_config_free(cfg); +END_TEST + +/* + * If \ is the last non-space character on the line, we read the next + * one, separating each line with SP. + */ +BEGIN_TEST(config2, "parse a multiline value") + git_config *cfg; + const char *str; + + must_pass(git_config_open(&cfg, CONFIG_BASE "/config2")); + + must_pass(git_config_get_string(cfg, "this.That.and", &str)); + must_be_true(!strcmp(str, "one one one two two three three")); + + git_config_free(cfg); +END_TEST + +/* + * This kind of subsection declaration is case-insensitive + */ +BEGIN_TEST(config3, "parse a [section.subsection] header") + git_config *cfg; + const char *str; + + must_pass(git_config_open(&cfg, CONFIG_BASE "/config3")); + + must_pass(git_config_get_string(cfg, "section.subsection.var", &str)); + must_be_true(!strcmp(str, "hello")); + + /* Avoid a false positive */ + str = "nohello"; + must_pass(git_config_get_string(cfg, "section.subSectIon.var", &str)); + must_be_true(!strcmp(str, "hello")); + + git_config_free(cfg); +END_TEST + + +BEGIN_SUITE(config) + ADD_TEST(config0); + ADD_TEST(config1); + ADD_TEST(config2); + ADD_TEST(config3); +END_SUITE diff --git a/tests/test_main.c b/tests/test_main.c index f2a623a48..c99722e80 100644 --- a/tests/test_main.c +++ b/tests/test_main.c @@ -43,6 +43,7 @@ DECLARE_SUITE(refs); DECLARE_SUITE(sqlite); DECLARE_SUITE(repository); DECLARE_SUITE(threads); +DECLARE_SUITE(config); static libgit2_suite suite_methods[]= { SUITE_NAME(core), @@ -59,6 +60,7 @@ static libgit2_suite suite_methods[]= { SUITE_NAME(sqlite), SUITE_NAME(repository), SUITE_NAME(threads), + SUITE_NAME(config), }; #define GIT_SUITE_COUNT (ARRAY_SIZE(suite_methods))