From df23042be065b7363515e88007edb4cd136fafbb Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 4 Mar 2023 11:11:26 +0900 Subject: [PATCH] Check: version grep: filter out matches on store path Use a negative lookahead on store path to avoid false positive on version grep when there are wrappers that contain the full store path and that store path includes the version. Link: https://github.com/NixOS/nixpkgs/pull/186698 --- src/Check.hs | 28 ++++++++++++++++++++++++++-- test/CheckSpec.hs | 5 +++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Check.hs b/src/Check.hs index 1636c9a..fec3359 100644 --- a/src/Check.hs +++ b/src/Check.hs @@ -7,7 +7,8 @@ module Check ( result, -- exposed for testing: - hasVersion + hasVersion, + versionWithoutPath ) where @@ -90,13 +91,36 @@ checkTestsBuildReport False = checkTestsBuildReport True = "- The tests defined in `passthru.tests`, if any, passed" +versionWithoutPath :: String -> Text -> String +versionWithoutPath resultPath expectedVersion = + -- We want to match expectedVersion, except when it is preceeded by + -- the new store path (as wrappers contain the full store path which + -- often includes the version) + -- This can be done with negative lookbehind e.g + -- /^(? + -- no version in prefix, just match version + "\\Q" + <> T.unpack expectedVersion + <> "\\E" + (storePrefix, _) -> + "(? T.unpack storePrefix + <> "\\E)\\Q" + <> T.unpack expectedVersion + <> "\\E" + foundVersionInOutputs :: Text -> String -> IO (Maybe Text) foundVersionInOutputs expectedVersion resultPath = hush <$> runExceptT ( do + let regex = versionWithoutPath resultPath expectedVersion (exitCode, _) <- - proc "grep" ["-r", T.unpack expectedVersion, resultPath] + proc "grep" ["-rP", regex, resultPath] & ourReadProcessInterleaved case exitCode of ExitSuccess -> diff --git a/test/CheckSpec.hs b/test/CheckSpec.hs index 2e37969..c7b69ad 100644 --- a/test/CheckSpec.hs +++ b/test/CheckSpec.hs @@ -25,3 +25,8 @@ spec = do Check.hasVersion (T.pack "2.345 is the version") (T.pack "2.34") `shouldBe` False Check.hasVersion (T.pack "12.34 is the version") (T.pack "2.34") `shouldBe` False Check.hasVersion seaweedVersion234 (T.pack "2.35") `shouldBe` False + + it "negative lookahead construction" do + Check.versionWithoutPath "/nix/store/z9l2xakz7cgw6yfh83nh542pvc0g4rkq-geeqie-2.0.1" (T.pack "2.0.1") `shouldBe` "(?