From e03b440e1c059c18fa1d4fc9bbad1bafde2b3d31 Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Tue, 11 Jun 2019 12:59:03 -0700 Subject: [PATCH] make ConfigSetting::getStringValue() return true/false Summary: The `FieldConverter` code previously relied on `folly::to()` for all arithmetic types, including `bool`. Unfortunately `folly::to()` returns `"1"` and `"0"` for booleans, which isn't terribly human-friendly. This updates the code to explicitly return `"true"` and `"false"` as the output for converting boolean values to strings. Reviewed By: strager Differential Revision: D15550014 fbshipit-source-id: 69a3385e529e2940a8be20dbcbeda92e5836d969 --- eden/fs/config/FieldConverter.h | 7 ++++--- eden/fs/config/test/ConfigSettingTest.cpp | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/eden/fs/config/FieldConverter.h b/eden/fs/config/FieldConverter.h index 08a4cb84cf..b04a96efbf 100644 --- a/eden/fs/config/FieldConverter.h +++ b/eden/fs/config/FieldConverter.h @@ -61,13 +61,11 @@ class FieldConverter { /* * FieldConverter implementation for integers, floating point, and bool types - * using folly::to(string) */ template class FieldConverter< T, - typename std::enable_if< - std::is_arithmetic::value || std::is_same::value>::type> { + typename std::enable_if::value>::type> { public: /** * Convert the passed string piece to a boolean. @@ -87,6 +85,9 @@ class FieldConverter< } std::string toDebugString(T value) const { + if constexpr (std::is_same::value) { + return value ? "true" : "false"; + } return folly::to(value); } }; diff --git a/eden/fs/config/test/ConfigSettingTest.cpp b/eden/fs/config/test/ConfigSettingTest.cpp index eb7c3e033f..93c314cb68 100644 --- a/eden/fs/config/test/ConfigSettingTest.cpp +++ b/eden/fs/config/test/ConfigSettingTest.cpp @@ -321,12 +321,12 @@ TEST(ConfigSettingTest, setBool) { checkSet(setting, true, "yes"); checkSet(setting, true, "Y"); checkSet(setting, true, "on"); - EXPECT_EQ("1", setting.getStringValue()); + EXPECT_EQ("true", setting.getStringValue()); checkSet(setting, false, "n"); checkSet(setting, false, "0"); checkSet(setting, false, "false"); checkSet(setting, false, "off"); - EXPECT_EQ("0", setting.getStringValue()); + EXPECT_EQ("false", setting.getStringValue()); checkSetError(setting, "Empty input string", ""); checkSetError(setting, "Invalid value for bool: \"bogus\"", "bogus");