[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Tests for config_find_option_name()



commit cb5f8ace79813fd835d4bb396dd693b39b1063e4
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Tue Aug 27 09:08:51 2019 -0400

    Tests for config_find_option_name()
    
    Fix a bug in config_find_option_name() where it did not consider
    the abbreviations table.
---
 src/app/config/confparse.c |  1 +
 src/test/test_confparse.c  | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/src/app/config/confparse.c b/src/app/config/confparse.c
index 8b2b53003..5c994c0a6 100644
--- a/src/app/config/confparse.c
+++ b/src/app/config/confparse.c
@@ -493,6 +493,7 @@ config_mgr_find_var(const config_mgr_t *mgr,
 const char *
 config_find_option_name(const config_mgr_t *mgr, const char *key)
 {
+  key = config_expand_abbrev(mgr, key, 0, 0);
   const managed_var_t *mv = config_mgr_find_var(mgr, key, true, NULL);
   if (mv)
     return mv->cvar->member.name;
diff --git a/src/test/test_confparse.c b/src/test/test_confparse.c
index 1d2e31ab9..f04c412c0 100644
--- a/src/test/test_confparse.c
+++ b/src/test/test_confparse.c
@@ -1000,6 +1000,29 @@ test_confparse_list_deprecated(void *arg)
   config_mgr_free(mgr);
 }
 
+static void
+test_confparse_find_option_name(void *arg)
+{
+  (void)arg;
+  config_mgr_t *mgr = config_mgr_new(&test_fmt);
+
+  // exact match
+  tt_str_op(config_find_option_name(mgr, "u64"), OP_EQ, "u64");
+  // case-insensitive match
+  tt_str_op(config_find_option_name(mgr, "S"), OP_EQ, "s");
+  tt_str_op(config_find_option_name(mgr, "linetypea"), OP_EQ, "LineTypeA");
+  // prefix match
+  tt_str_op(config_find_option_name(mgr, "deprec"), OP_EQ, "deprecated_int");
+  // explicit abbreviation
+  tt_str_op(config_find_option_name(mgr, "uint"), OP_EQ, "pos");
+  tt_str_op(config_find_option_name(mgr, "UINT"), OP_EQ, "pos");
+  // no match
+  tt_ptr_op(config_find_option_name(mgr, "absent"), OP_EQ, NULL);
+
+ done:
+  config_mgr_free(mgr);
+}
+
 #define CONFPARSE_TEST(name, flags)                          \
   { #name, test_confparse_ ## name, flags, NULL, NULL }
 
@@ -1038,5 +1061,6 @@ struct testcase_t confparse_tests[] = {
   CONFPARSE_TEST(check_ok_fail, 0),
   CONFPARSE_TEST(list_vars, 0),
   CONFPARSE_TEST(list_deprecated, 0),
+  CONFPARSE_TEST(find_option_name, 0),
   END_OF_TESTCASES
 };



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits