]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cleanup: fix the eol dumping in JSONFormatter flush & close_section 5351/head
authorAran85 <zhangzengran@h3c.com>
Thu, 6 Aug 2015 09:45:43 +0000 (17:45 +0800)
committerAran85 <zhangzengran@h3c.com>
Thu, 6 Aug 2015 09:49:58 +0000 (17:49 +0800)
Signed-off-by: Aran85 zhangzengran@h3c.com
src/common/Formatter.cc
src/test/crush/CrushWrapper.cc

index 7c166ef09865f06b97205ebeed8e1803c0be790a..32588750997e1d6e1ed6d89ad3f6bda495936cdd 100644 (file)
@@ -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()
index c690ada4f16768511e5910ad67c5ab02f0162aed..bbf40ec6d639dc5901f821bc1924759fb474b680 100644 (file)
@@ -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");