From cacbd43422f8761394a3d40c304a2b7aab5ae2a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano-Tarumi?= Date: Tue, 18 Dec 2018 20:25:28 -0500 Subject: [PATCH] t: modernize system.t --- t/system.cc | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/t/system.cc b/t/system.cc index 204b93e..2e8fc68 100644 --- a/t/system.cc +++ b/t/system.cc @@ -10,56 +10,52 @@ void check_partial_files() std::string name; { ot::partial_file bad_tmp; - if (bad_tmp.open("/dev/null") != ot::st::standard_error) - throw failure("cannot open a device as a partial file"); - if (bad_tmp.open(result) != ot::st::ok) - throw failure("could not open a simple result file"); + is(bad_tmp.open("/dev/null"), ot::st::standard_error, + "opening a device as a partial file fails"); + is(bad_tmp.open(result), ot::st::ok, + "opening a regular partial file works"); name = bad_tmp.name(); if (name.size() != strlen(result) + 12 || name.compare(0, strlen(result), result) != 0) throw failure("the temporary name is surprising: " + name); } - if (access(name.c_str(), F_OK) != -1) - throw failure("the bad temporary file was not deleted"); + is(access(name.c_str(), F_OK), -1, "expect the temporary file is deleted"); ot::partial_file good_tmp; - if (good_tmp.open(result) != ot::st::ok) - throw failure("could not open the result file"); + is(good_tmp.open(result), ot::st::ok, "open the partial file"); name = good_tmp.name(); - if (good_tmp.commit() != ot::st::ok) - throw failure("could not commit the result file"); - if (access(name.c_str(), F_OK) != -1) - throw failure("the good temporary file was not deleted"); - if (access(result, F_OK) != 0) - throw failure("the final result file is not there"); - if (remove(result) != 0) - throw failure("could not remove the result file"); + is(good_tmp.commit(), ot::st::ok, "commit the result file"); + is(access(name.c_str(), F_OK), -1, "expect the temporary file is deleted"); + is(access(result, F_OK), 0, "expect the final result file"); + is(remove(result), 0, "remove the result file"); } void check_converter() { const char* ephemere_iso = "\xc9\x70\x68\xe9\x6d\xe8\x72\x65"; ot::encoding_converter to_utf8("ISO-8859-1", "UTF-8"); - std::string out; - ot::status rc = to_utf8(ephemere_iso, out); - if (rc != ot::st::ok || out != "Éphémère") - throw failure("conversion to UTF-8 should have worked"); - ot::encoding_converter from_utf8("UTF-8", "ISO-8859-1//TRANSLIT"); + std::string out; + + ot::status rc = to_utf8(ephemere_iso, out); + is(rc, ot::st::ok, "conversion to UTF-8 is successful"); + is(out, "Éphémère", "conversion to UTF-8 is correct"); + rc = from_utf8("Éphémère", out); - if (rc != ot::st::ok || out != ephemere_iso) - throw failure("conversion from UTF-8 should have worked"); + is(rc, ot::st::ok, "conversion from UTF-8 is successful"); + is(out, ephemere_iso, "conversion from UTF-8 is correct"); + rc = from_utf8("\xFF\xFF", out); - if (rc != ot::st::badly_encoded) - throw failure("conversion from bad UTF-8 should have failed"); + is(rc, ot::st::badly_encoded, "conversion from bad UTF-8 fails"); + rc = from_utf8("cat 猫 chat", out); - if (rc != ot::st::information_lost || out != "cat ? chat") - throw failure("lossy conversion from UTF-8 should have worked"); + is(rc, ot::st::information_lost, "lossy conversion from UTF-8 is detected"); + is(out, "cat ? chat", "check result of lossy conversion"); } int main(int argc, char **argv) { - std::cout << "1..2\n"; + plan(2); run(check_partial_files, "test partial files"); run(check_converter, "test encoding converter"); return 0;