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` "(?