From bb99639d480e4edf655e00ff13474158f84a4294 Mon Sep 17 00:00:00 2001 From: Craig Ferguson Date: Tue, 14 Jul 2020 18:32:25 +0200 Subject: [PATCH] Quote pretty-printed diffs to indicate trailing whitespace --- CHANGES.md | 5 + src/alcotest-engine/test.ml | 7 +- .../e2e/alcotest/failing/check_basic.expected | 52 +++--- test/e2e/alcotest/failing/check_long.expected | 156 +++++++++--------- 4 files changed, 113 insertions(+), 107 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b0ef6816..4085724e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +### Unreleased + +- Surround pretty-printed diffs with quotes to make trailing whitespace more + obvious. (#261, @CraigFe) + ### 1.2.0 (2020-07-13) - Add an `alcotest-mirage` package, allowing the construction of MirageOS diff --git a/src/alcotest-engine/test.ml b/src/alcotest-engine/test.ml index aadda5ab..12333eb3 100644 --- a/src/alcotest-engine/test.ml +++ b/src/alcotest-engine/test.ml @@ -149,12 +149,13 @@ let check (type a) (t : a testable) msg (expected : a) (actual : a) = let s = const string in let pp_error = const Pp.tag `Fail ++ s (" " ^ msg) and pp_expected ppf () = - Fmt.string ppf " Expected: "; - (styled `Green (pp t)) ppf expected; + Fmt.pf ppf " Expected: `%a'" (styled `Green (pp t)) expected; Format.pp_print_if_newline ppf (); Fmt.cut ppf (); () - and pp_actual = s " Received: " ++ const (styled `Red (pp t)) actual in + and pp_actual ppf () = + Fmt.pf ppf " Received: `%a'" (styled `Red (pp t)) actual + in raise (Core.Check_error Fmt.(vbox (pp_error ++ cut ++ cut ++ pp_expected ++ cut ++ pp_actual))) diff --git a/test/e2e/alcotest/failing/check_basic.expected b/test/e2e/alcotest/failing/check_basic.expected index 638bd854..1fbc9171 100644 --- a/test/e2e/alcotest/failing/check_basic.expected +++ b/test/e2e/alcotest/failing/check_basic.expected @@ -33,8 +33,8 @@ This run has ID `'. └──────────────────────────────────────────────────────────────────────────────┘ FAIL bool - Expected: true - Received: false + Expected: `true' + Received: `false' ────────────────────────────────────────────────────────────────────────────── @@ -43,8 +43,8 @@ FAIL bool └──────────────────────────────────────────────────────────────────────────────┘ FAIL int - Expected: 1 - Received: 2 + Expected: `1' + Received: `2' ────────────────────────────────────────────────────────────────────────────── @@ -53,8 +53,8 @@ FAIL int └──────────────────────────────────────────────────────────────────────────────┘ FAIL int32 - Expected: 2147483647 - Received: -2147483648 + Expected: `2147483647' + Received: `-2147483648' ────────────────────────────────────────────────────────────────────────────── @@ -63,8 +63,8 @@ FAIL int32 └──────────────────────────────────────────────────────────────────────────────┘ FAIL int64 - Expected: 9223372036854775807 - Received: -9223372036854775808 + Expected: `9223372036854775807' + Received: `-9223372036854775808' ────────────────────────────────────────────────────────────────────────────── @@ -73,8 +73,8 @@ FAIL int64 └──────────────────────────────────────────────────────────────────────────────┘ FAIL float - Expected: 1 - Received: 2 + Expected: `1' + Received: `2' ────────────────────────────────────────────────────────────────────────────── @@ -83,8 +83,8 @@ FAIL float └──────────────────────────────────────────────────────────────────────────────┘ FAIL char - Expected: a - Received: b + Expected: `a' + Received: `b' ────────────────────────────────────────────────────────────────────────────── @@ -93,8 +93,8 @@ FAIL char └──────────────────────────────────────────────────────────────────────────────┘ FAIL string - Expected: Lorem ipsum - Received: dolor sit amet. + Expected: `Lorem ipsum' + Received: `dolor sit amet.' ────────────────────────────────────────────────────────────────────────────── @@ -103,8 +103,8 @@ FAIL string └──────────────────────────────────────────────────────────────────────────────┘ FAIL bytes - Expected: "\001\002\003" - Received: "\001\000\003" + Expected: `"\001\002\003"' + Received: `"\001\000\003"' ────────────────────────────────────────────────────────────────────────────── @@ -113,8 +113,8 @@ FAIL bytes └──────────────────────────────────────────────────────────────────────────────┘ FAIL list - Expected: [a; b] - Received: [a; c] + Expected: `[a; b]' + Received: `[a; c]' ────────────────────────────────────────────────────────────────────────────── @@ -123,8 +123,8 @@ FAIL list └──────────────────────────────────────────────────────────────────────────────┘ FAIL array - Expected: [|0; 9223372036854775807|] - Received: [|0; 1; 9223372036854775807|] + Expected: `[|0; 9223372036854775807|]' + Received: `[|0; 1; 9223372036854775807|]' ────────────────────────────────────────────────────────────────────────────── @@ -133,8 +133,8 @@ FAIL array └──────────────────────────────────────────────────────────────────────────────┘ FAIL option some - Expected: Some 1 - Received: Some 2 + Expected: `Some 1' + Received: `Some 2' ────────────────────────────────────────────────────────────────────────────── @@ -143,8 +143,8 @@ FAIL option some └──────────────────────────────────────────────────────────────────────────────┘ FAIL result - Expected: Ok 1 - Received: Error () + Expected: `Ok 1' + Received: `Error ()' ────────────────────────────────────────────────────────────────────────────── @@ -153,8 +153,8 @@ FAIL result └──────────────────────────────────────────────────────────────────────────────┘ FAIL pair - Expected: (1, a) - Received: (1, b) + Expected: `(1, a)' + Received: `(1, b)' ────────────────────────────────────────────────────────────────────────────── 13 failures! in s. 13 tests run. diff --git a/test/e2e/alcotest/failing/check_long.expected b/test/e2e/alcotest/failing/check_long.expected index f579acd8..b3f82df8 100644 --- a/test/e2e/alcotest/failing/check_long.expected +++ b/test/e2e/alcotest/failing/check_long.expected @@ -13,11 +13,11 @@ This run has ID `'. └──────────────────────────────────────────────────────────────────────────────┘ FAIL list - Expected: [a; b; c; d; e; f; g; h; i; j; k; l; m; n; o; p; q; r; s; - t; u; v; w; x; y; z; A] + Expected: `[a; b; c; d; e; f; g; h; i; j; k; l; m; n; o; p; q; r; + s; t; u; v; w; x; y; z; A]' - Received: [a; b; c; d; e; f; g; h; i; j; k; l; m; n; o; p; q; r; s; - t; u; v; w; x; y; z; B] + Received: `[a; b; c; d; e; f; g; h; i; j; k; l; m; n; o; p; q; r; + s; t; u; v; w; x; y; z; B]' ────────────────────────────────────────────────────────────────────────────── @@ -26,23 +26,23 @@ FAIL list └──────────────────────────────────────────────────────────────────────────────┘ FAIL array - Expected: [|0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; - 16; 17; 18; 19; 20; 21; 22; 23; 24; 25; 26; 27; 28; 29; - 30; 31; 32; 33; 34; 35; 36; 37; 38; 39; 40; 41; 42; 43; - 44; 45; 46; 47; 48; 49; 50; 51; 52; 53; 54; 55; 56; 57; - 58; 59; 60; 61; 62; 63; 64; 65; 66; 67; 68; 69; 70; 71; - 72; 73; 74; 75; 76; 77; 78; 79; 80; 81; 82; 83; 84; 85; - 86; 87; 88; 89; 90; 91; 92; 93; 94; 95; 96; 97; 98; 99; - 9223372036854775807|] + Expected: `[|0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; + 16; 17; 18; 19; 20; 21; 22; 23; 24; 25; 26; 27; 28; 29; + 30; 31; 32; 33; 34; 35; 36; 37; 38; 39; 40; 41; 42; 43; + 44; 45; 46; 47; 48; 49; 50; 51; 52; 53; 54; 55; 56; 57; + 58; 59; 60; 61; 62; 63; 64; 65; 66; 67; 68; 69; 70; 71; + 72; 73; 74; 75; 76; 77; 78; 79; 80; 81; 82; 83; 84; 85; + 86; 87; 88; 89; 90; 91; 92; 93; 94; 95; 96; 97; 98; 99; + 9223372036854775807|]' - Received: [|0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; - 16; 17; 18; 19; 20; 21; 22; 23; 24; 25; 26; 27; 28; 29; - 30; 31; 32; 33; 34; 35; 36; 37; 38; 39; 40; 41; 42; 43; - 44; 45; 46; 47; 48; 49; 50; 51; 52; 53; 54; 55; 56; 57; - 58; 59; 60; 61; 62; 63; 64; 65; 66; 67; 68; 69; 70; 71; - 72; 73; 74; 75; 76; 77; 78; 79; 80; 81; 82; 83; 84; 85; - 86; 87; 88; 89; 90; 91; 92; 93; 94; 95; 96; 97; 98; 99; - -9223372036854775808|] + Received: `[|0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; + 16; 17; 18; 19; 20; 21; 22; 23; 24; 25; 26; 27; 28; 29; + 30; 31; 32; 33; 34; 35; 36; 37; 38; 39; 40; 41; 42; 43; + 44; 45; 46; 47; 48; 49; 50; 51; 52; 53; 54; 55; 56; 57; + 58; 59; 60; 61; 62; 63; 64; 65; 66; 67; 68; 69; 70; 71; + 72; 73; 74; 75; 76; 77; 78; 79; 80; 81; 82; 83; 84; 85; + 86; 87; 88; 89; 90; 91; 92; 93; 94; 95; 96; 97; 98; 99; + -9223372036854775808|]' ────────────────────────────────────────────────────────────────────────────── @@ -51,77 +51,77 @@ FAIL array └──────────────────────────────────────────────────────────────────────────────┘ FAIL nested options - Expected: Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some + Expected: `Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some Some Some Some Some Some Some - Some 1 + Some + Some 1' - Received: Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some - Some + Received: `Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some + Some Some Some Some Some Some Some - Some 2 + Some 2' ────────────────────────────────────────────────────────────────────────────── 3 failures! in s. 3 tests run.