[llvm] 6d5845c - [support] Attempt to fix PrintNumber test for Solaris

Paul Kirth via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 24 09:48:27 PDT 2023


Author: Paul Kirth
Date: 2023-03-24T16:48:18Z
New Revision: 6d5845c5c335f7146c9d3c8b2b4946609aaea2c2

URL: https://github.com/llvm/llvm-project/commit/6d5845c5c335f7146c9d3c8b2b4946609aaea2c2
DIFF: https://github.com/llvm/llvm-project/commit/6d5845c5c335f7146c9d3c8b2b4946609aaea2c2.diff

LOG: [support] Attempt to fix PrintNumber test for Solaris

NaN and Inf are still causing some problems in a formatting test.
This patch makes the checked format string exactly match the internal
JSON format string. If there are still problems, we should disable
testing Inf and NaN values until we can come to a portable solution.

Reviewed By: abhina.sreeskantharajan

Differential Revision: https://reviews.llvm.org/D146818

Added: 
    

Modified: 
    llvm/unittests/Support/ScopedPrinterTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/Support/ScopedPrinterTest.cpp b/llvm/unittests/Support/ScopedPrinterTest.cpp
index 9ebcb0b14bd43..dde43cb103aea 100644
--- a/llvm/unittests/Support/ScopedPrinterTest.cpp
+++ b/llvm/unittests/Support/ScopedPrinterTest.cpp
@@ -572,7 +572,7 @@ TEST_F(ScopedPrinterTest, PrintNumber) {
     W.printNumber("float-42.0", 42.0f);
     W.printNumber("float-42.5625", 42.5625f);
 
-        W.printNumber("double-max", MaxDouble);
+    W.printNumber("double-max", MaxDouble);
     W.printNumber("double-min", MinDouble);
     W.printNumber("double-inf", InfDouble);
     W.printNumber("double-nan", NaNDouble);
@@ -610,6 +610,19 @@ TEST_F(ScopedPrinterTest, PrintNumber) {
   format("%5.1f", NaNDouble).snprint(Buf, sizeof(Buf));
   std::string NaNDoubleStr(Buf);
 
+  format("%.*g", InfFloat).snprint(Buf, sizeof(Buf));
+  std::string JsonInfFloatStr(Buf);
+
+  format("%.*g", InfDouble).snprint(Buf, sizeof(Buf));
+  std::string JsonInfDoubleStr(Buf);
+
+  format("%.*g", NaNFloat).snprint(Buf, sizeof(Buf));
+  std::string JsonNaNFloatStr(Buf);
+
+  format("%.*g", NaNDouble).snprint(Buf, sizeof(Buf));
+  std::string JsonNaNDoubleStr(Buf);
+
+
   std::string ExpectedOut = Twine(
                                 R"(uint64_t-max: 18446744073709551615
 uint64_t-min: 0
@@ -669,14 +682,14 @@ double-42.5625:  42.6
   },
   "float-max": 3.4028234663852886e+38,
   "float-min": 1.1754943508222875e-38,
-  "float-inf": )" + std::to_string(InfFloat) + R"(,
-  "float-nan": )" + std::to_string(NaNFloat) + R"(,
+  "float-inf": )" + JsonInfFloatStr + R"(,
+  "float-nan": )" + JsonNaNFloatStr + R"(,
   "float-42.0": 42,
   "float-42.5625": 42.5625,
   "double-max": 1.7976931348623157e+308,
   "double-min": 2.2250738585072014e-308,
-  "double-inf": )" + std::to_string(InfDouble) + R"(,
-  "double-nan": )" + std::to_string(NaNDouble) + R"(,
+  "double-inf": )" + JsonInfDoubleStr + R"(,
+  "double-nan": )" + JsonNaNDoubleStr + R"(,
   "double-42.0": 42,
   "double-42.5625": 42.5625
 })").str();


        


More information about the llvm-commits mailing list