Blame 0001-tests-Don-t-break-when-a-file-unexpectedly-exists.patch

Siteshwar Vashisht 1d41bd
From 29ebd4a5ff5c0a0eefe802a4bcaa8ef32cc5795a Mon Sep 17 00:00:00 2001
Siteshwar Vashisht 1d41bd
From: Fabian Homborg <FHomborg@gmail.com>
Siteshwar Vashisht 1d41bd
Date: Sat, 13 Mar 2021 17:22:35 +0100
Siteshwar Vashisht 1d41bd
Subject: [PATCH] tests: Don't break when a file unexpectedly exists
Siteshwar Vashisht 1d41bd
Siteshwar Vashisht 1d41bd
Creating a file called "xfoo" could break the highlight tests because
Siteshwar Vashisht 1d41bd
we'd suddenly get a color with valid_path set to true.
Siteshwar Vashisht 1d41bd
Siteshwar Vashisht 1d41bd
So what we do is simply compare foreground/background and forced
Siteshwar Vashisht 1d41bd
underline, but only check for path validity if we're expecting a valid
Siteshwar Vashisht 1d41bd
path.
Siteshwar Vashisht 1d41bd
Siteshwar Vashisht 1d41bd
If we're not expecting a valid path, we don't fail whether it is there
Siteshwar Vashisht 1d41bd
or not.
Siteshwar Vashisht 1d41bd
Siteshwar Vashisht 1d41bd
This means that we can't check for a non-valid path, but we don't
Siteshwar Vashisht 1d41bd
currently do that anyway and we can just burn that bridge when we get
Siteshwar Vashisht 1d41bd
to it.
Siteshwar Vashisht 1d41bd
Siteshwar Vashisht 1d41bd
cc @siteshwar @krobelus, who both came across this
Siteshwar Vashisht 1d41bd
---
Siteshwar Vashisht 1d41bd
 src/fish_tests.cpp | 11 ++++++++++-
Siteshwar Vashisht 1d41bd
 1 file changed, 10 insertions(+), 1 deletion(-)
Siteshwar Vashisht 1d41bd
Siteshwar Vashisht 1d41bd
diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp
Siteshwar Vashisht 1d41bd
index 5f57f9e64..3f7777138 100644
Siteshwar Vashisht 1d41bd
--- a/src/fish_tests.cpp
Siteshwar Vashisht 1d41bd
+++ b/src/fish_tests.cpp
Siteshwar Vashisht 1d41bd
@@ -5386,7 +5386,16 @@ static void test_highlighting() {
Siteshwar Vashisht 1d41bd
             // Hackish space handling. We don't care about the colors in spaces.
Siteshwar Vashisht 1d41bd
             if (text.at(i) == L' ') continue;
Siteshwar Vashisht 1d41bd
 
Siteshwar Vashisht 1d41bd
-            if (expected_colors.at(i) != colors.at(i)) {
Siteshwar Vashisht 1d41bd
+            auto e = expected_colors.at(i);
Siteshwar Vashisht 1d41bd
+            auto c = colors.at(i);
Siteshwar Vashisht 1d41bd
+            // Compare the colors, but don't care about pathness
Siteshwar Vashisht 1d41bd
+            // unless we're asking for a valid path.
Siteshwar Vashisht 1d41bd
+            //
Siteshwar Vashisht 1d41bd
+            // That way stray files in the build directory don't break the test.
Siteshwar Vashisht 1d41bd
+            if (e.foreground != c.foreground
Siteshwar Vashisht 1d41bd
+                || e.background != c.background
Siteshwar Vashisht 1d41bd
+                || e.force_underline != c.force_underline
Siteshwar Vashisht 1d41bd
+                || (e.valid_path && !c.valid_path)) {
Siteshwar Vashisht 1d41bd
                 const wcstring spaces(i, L' ');
Siteshwar Vashisht 1d41bd
                 err(L"Wrong color in test at index %lu in text (expected %#x, actual "
Siteshwar Vashisht 1d41bd
                     L"%#x):\n%ls\n%ls^",
Siteshwar Vashisht 1d41bd
-- 
Siteshwar Vashisht 1d41bd
2.29.2
Siteshwar Vashisht 1d41bd