From: Aran85 Date: Thu, 6 Aug 2015 09:45:43 +0000 (+0800) Subject: cleanup: fix the eol dumping in JSONFormatter flush & close_section X-Git-Tag: v10.0.3~128^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b34363ac0fd40e2d1a2b311e566f3db5e2f30da8;p=ceph.git cleanup: fix the eol dumping in JSONFormatter flush & close_section Signed-off-by: Aran85 zhangzengran@h3c.com --- diff --git a/src/common/Formatter.cc b/src/common/Formatter.cc index 7c166ef09865..32588750997e 100644 --- a/src/common/Formatter.cc +++ b/src/common/Formatter.cc @@ -126,8 +126,6 @@ void JSONFormatter::flush(std::ostream& os) { finish_pending_string(); os << m_ss.str(); - if (m_pretty) - os << "\n"; m_ss.clear(); m_ss.str(""); } @@ -238,6 +236,8 @@ void JSONFormatter::close_section() } m_ss << (entry.is_array ? ']' : '}'); m_stack.pop_back(); + if (m_pretty && m_stack.empty()) + m_ss << "\n"; } void JSONFormatter::finish_pending_string() diff --git a/src/test/crush/CrushWrapper.cc b/src/test/crush/CrushWrapper.cc index c690ada4f167..bbf40ec6d639 100644 --- a/src/test/crush/CrushWrapper.cc +++ b/src/test/crush/CrushWrapper.cc @@ -686,11 +686,13 @@ TEST(CrushWrapper, dump_rules) { // no ruleset by default { Formatter *f = Formatter::create("json-pretty"); + f->open_array_section("rules"); c->dump_rules(f); + f->close_section(); stringstream ss; f->flush(ss); delete f; - EXPECT_EQ("\n", ss.str()); + EXPECT_EQ("[]\n", ss.str()); } string name("NAME");