Skip to content

Commit 861ee40

Browse files
authored
Merge pull request #1176 from grembo/develop
Fix unit tests that were silently skipped or crashed (depending on the compiler)
2 parents 3ce4325 + 05b27e8 commit 861ee40

3 files changed

Lines changed: 108 additions & 33 deletions

File tree

test/src/unit-cbor.cpp

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,21 @@ TEST_CASE("CBOR roundtrips", "[hide]")
16601660
{
16611661
SECTION("input from flynn")
16621662
{
1663+
// most of these are exluded due to differences in key order (not a real problem)
1664+
auto exclude_packed = std::set<std::string>{
1665+
"test/data/json.org/1.json",
1666+
"test/data/json.org/2.json",
1667+
"test/data/json.org/3.json",
1668+
"test/data/json.org/4.json",
1669+
"test/data/json.org/5.json",
1670+
"test/data/json_testsuite/sample.json", // kills AppVeyor
1671+
"test/data/json_tests/pass1.json",
1672+
"test/data/regression/working_file.json",
1673+
"test/data/nst_json_testsuite/test_parsing/y_object.json",
1674+
"test/data/nst_json_testsuite/test_parsing/y_object_duplicated_key.json",
1675+
"test/data/nst_json_testsuite/test_parsing/y_object_long_strings.json",
1676+
};
1677+
16631678
for (std::string filename :
16641679
{
16651680
"test/data/json_nlohmann_tests/all_unicode.json",
@@ -1811,12 +1826,12 @@ TEST_CASE("CBOR roundtrips", "[hide]")
18111826
{
18121827
CAPTURE(filename);
18131828

1814-
// parse JSON file
1815-
std::ifstream f_json(filename);
1816-
json j1 = json::parse(f_json);
1817-
1818-
SECTION("std::vector<uint8_t>")
1829+
SECTION(filename + ": std::vector<uint8_t>")
18191830
{
1831+
// parse JSON file
1832+
std::ifstream f_json(filename);
1833+
json j1 = json::parse(f_json);
1834+
18201835
// parse CBOR file
18211836
std::ifstream f_cbor(filename + ".cbor", std::ios::binary);
18221837
std::vector<uint8_t> packed(
@@ -1829,8 +1844,12 @@ TEST_CASE("CBOR roundtrips", "[hide]")
18291844
CHECK(j1 == j2);
18301845
}
18311846

1832-
SECTION("std::ifstream")
1847+
SECTION(filename + ": std::ifstream")
18331848
{
1849+
// parse JSON file
1850+
std::ifstream f_json(filename);
1851+
json j1 = json::parse(f_json);
1852+
18341853
// parse CBOR file
18351854
std::ifstream f_cbor(filename + ".cbor", std::ios::binary);
18361855
json j2;
@@ -1840,8 +1859,12 @@ TEST_CASE("CBOR roundtrips", "[hide]")
18401859
CHECK(j1 == j2);
18411860
}
18421861

1843-
SECTION("uint8_t* and size")
1862+
SECTION(filename + ": uint8_t* and size")
18441863
{
1864+
// parse JSON file
1865+
std::ifstream f_json(filename);
1866+
json j1 = json::parse(f_json);
1867+
18451868
// parse CBOR file
18461869
std::ifstream f_cbor(filename + ".cbor", std::ios::binary);
18471870
std::vector<uint8_t> packed(
@@ -1854,19 +1877,26 @@ TEST_CASE("CBOR roundtrips", "[hide]")
18541877
CHECK(j1 == j2);
18551878
}
18561879

1857-
SECTION("output to output adapters")
1880+
SECTION(filename + ": output to output adapters")
18581881
{
1882+
// parse JSON file
1883+
std::ifstream f_json(filename);
1884+
json j1 = json::parse(f_json);
1885+
18591886
// parse CBOR file
18601887
std::ifstream f_cbor(filename + ".cbor", std::ios::binary);
18611888
std::vector<uint8_t> packed(
18621889
(std::istreambuf_iterator<char>(f_cbor)),
18631890
std::istreambuf_iterator<char>());
18641891

1865-
SECTION("std::vector<uint8_t>")
1892+
if (!exclude_packed.count(filename))
18661893
{
1867-
std::vector<uint8_t> vec;
1868-
json::to_cbor(j1, vec);
1869-
CHECK(vec == packed);
1894+
SECTION(filename + ": output adapters: std::vector<uint8_t>")
1895+
{
1896+
std::vector<uint8_t> vec;
1897+
json::to_cbor(j1, vec);
1898+
CHECK(vec == packed);
1899+
}
18701900
}
18711901
}
18721902
}

test/src/unit-msgpack.cpp

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,24 @@ TEST_CASE("MessagePack roundtrips", "[hide]")
13491349
{
13501350
SECTION("input from msgpack-python")
13511351
{
1352+
// most of these are exluded due to differences in key order (not a real problem)
1353+
auto exclude_packed = std::set<std::string>{
1354+
"test/data/json.org/1.json",
1355+
"test/data/json.org/2.json",
1356+
"test/data/json.org/3.json",
1357+
"test/data/json.org/4.json",
1358+
"test/data/json.org/5.json",
1359+
"test/data/json_testsuite/sample.json", // kills AppVeyor
1360+
"test/data/json_tests/pass1.json",
1361+
"test/data/regression/working_file.json",
1362+
"test/data/nst_json_testsuite/test_parsing/y_object.json",
1363+
"test/data/nst_json_testsuite/test_parsing/y_object_basic.json",
1364+
"test/data/nst_json_testsuite/test_parsing/y_object_duplicated_key.json",
1365+
"test/data/nst_json_testsuite/test_parsing/y_object_long_strings.json",
1366+
"test/data/nst_json_testsuite/test_parsing/y_object_simple.json",
1367+
"test/data/nst_json_testsuite/test_parsing/y_object_string_unicode.json",
1368+
};
1369+
13521370
for (std::string filename :
13531371
{
13541372
"test/data/json_nlohmann_tests/all_unicode.json",
@@ -1500,12 +1518,12 @@ TEST_CASE("MessagePack roundtrips", "[hide]")
15001518
{
15011519
CAPTURE(filename);
15021520

1503-
// parse JSON file
1504-
std::ifstream f_json(filename);
1505-
json j1 = json::parse(f_json);
1506-
1507-
SECTION("std::vector<uint8_t>")
1521+
SECTION(filename + ": std::vector<uint8_t>")
15081522
{
1523+
// parse JSON file
1524+
std::ifstream f_json(filename);
1525+
json j1 = json::parse(f_json);
1526+
15091527
// parse MessagePack file
15101528
std::ifstream f_msgpack(filename + ".msgpack", std::ios::binary);
15111529
std::vector<uint8_t> packed(
@@ -1518,8 +1536,12 @@ TEST_CASE("MessagePack roundtrips", "[hide]")
15181536
CHECK(j1 == j2);
15191537
}
15201538

1521-
SECTION("std::ifstream")
1539+
SECTION(filename + ": std::ifstream")
15221540
{
1541+
// parse JSON file
1542+
std::ifstream f_json(filename);
1543+
json j1 = json::parse(f_json);
1544+
15231545
// parse MessagePack file
15241546
std::ifstream f_msgpack(filename + ".msgpack", std::ios::binary);
15251547
json j2;
@@ -1529,8 +1551,12 @@ TEST_CASE("MessagePack roundtrips", "[hide]")
15291551
CHECK(j1 == j2);
15301552
}
15311553

1532-
SECTION("uint8_t* and size")
1554+
SECTION(filename + ": uint8_t* and size")
15331555
{
1556+
// parse JSON file
1557+
std::ifstream f_json(filename);
1558+
json j1 = json::parse(f_json);
1559+
15341560
// parse MessagePack file
15351561
std::ifstream f_msgpack(filename + ".msgpack", std::ios::binary);
15361562
std::vector<uint8_t> packed(
@@ -1543,19 +1569,26 @@ TEST_CASE("MessagePack roundtrips", "[hide]")
15431569
CHECK(j1 == j2);
15441570
}
15451571

1546-
SECTION("output to output adapters")
1572+
SECTION(filename + ": output to output adapters")
15471573
{
1574+
// parse JSON file
1575+
std::ifstream f_json(filename);
1576+
json j1 = json::parse(f_json);
1577+
15481578
// parse MessagePack file
15491579
std::ifstream f_msgpack(filename + ".msgpack", std::ios::binary);
15501580
std::vector<uint8_t> packed(
15511581
(std::istreambuf_iterator<char>(f_msgpack)),
15521582
std::istreambuf_iterator<char>());
15531583

1554-
SECTION("std::vector<uint8_t>")
1584+
if (!exclude_packed.count(filename))
15551585
{
1556-
std::vector<uint8_t> vec;
1557-
json::to_msgpack(j1, vec);
1558-
CHECK(vec == packed);
1586+
SECTION(filename + ": output adapters: std::vector<uint8_t>")
1587+
{
1588+
std::vector<uint8_t> vec;
1589+
json::to_msgpack(j1, vec);
1590+
CHECK(vec == packed);
1591+
}
15591592
}
15601593
}
15611594
}

test/src/unit-ubjson.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,12 +2199,12 @@ TEST_CASE("UBJSON roundtrips", "[hide]")
21992199
{
22002200
CAPTURE(filename);
22012201

2202-
// parse JSON file
2203-
std::ifstream f_json(filename);
2204-
json j1 = json::parse(f_json);
2205-
2206-
SECTION("std::vector<uint8_t>")
2202+
SECTION(filename + ": std::vector<uint8_t>")
22072203
{
2204+
// parse JSON file
2205+
std::ifstream f_json(filename);
2206+
json j1 = json::parse(f_json);
2207+
22082208
// parse MessagePack file
22092209
std::ifstream f_ubjson(filename + ".ubjson", std::ios::binary);
22102210
std::vector<uint8_t> packed(
@@ -2217,8 +2217,12 @@ TEST_CASE("UBJSON roundtrips", "[hide]")
22172217
CHECK(j1 == j2);
22182218
}
22192219

2220-
SECTION("std::ifstream")
2220+
SECTION(filename + ": std::ifstream")
22212221
{
2222+
// parse JSON file
2223+
std::ifstream f_json(filename);
2224+
json j1 = json::parse(f_json);
2225+
22222226
// parse MessagePack file
22232227
std::ifstream f_ubjson(filename + ".ubjson", std::ios::binary);
22242228
json j2;
@@ -2228,8 +2232,12 @@ TEST_CASE("UBJSON roundtrips", "[hide]")
22282232
CHECK(j1 == j2);
22292233
}
22302234

2231-
SECTION("uint8_t* and size")
2235+
SECTION(filename + ": uint8_t* and size")
22322236
{
2237+
// parse JSON file
2238+
std::ifstream f_json(filename);
2239+
json j1 = json::parse(f_json);
2240+
22332241
// parse MessagePack file
22342242
std::ifstream f_ubjson(filename + ".ubjson", std::ios::binary);
22352243
std::vector<uint8_t> packed(
@@ -2242,15 +2250,19 @@ TEST_CASE("UBJSON roundtrips", "[hide]")
22422250
CHECK(j1 == j2);
22432251
}
22442252

2245-
SECTION("output to output adapters")
2253+
SECTION(filename + ": output to output adapters")
22462254
{
2255+
// parse JSON file
2256+
std::ifstream f_json(filename);
2257+
json j1 = json::parse(f_json);
2258+
22472259
// parse MessagePack file
22482260
std::ifstream f_ubjson(filename + ".ubjson", std::ios::binary);
22492261
std::vector<uint8_t> packed(
22502262
(std::istreambuf_iterator<char>(f_ubjson)),
22512263
std::istreambuf_iterator<char>());
22522264

2253-
SECTION("std::vector<uint8_t>")
2265+
SECTION(filename + ": output adapters: std::vector<uint8_t>")
22542266
{
22552267
std::vector<uint8_t> vec;
22562268
json::to_ubjson(j1, vec);

0 commit comments

Comments
 (0)