mirror of
https://github.com/nix-community/nixpkgs-update.git
synced 2024-11-22 21:52:15 +03:00
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
This commit is contained in:
parent
e2050fb126
commit
df23042be0
28
src/Check.hs
28
src/Check.hs
@ -7,7 +7,8 @@
|
|||||||
module Check
|
module Check
|
||||||
( result,
|
( result,
|
||||||
-- exposed for testing:
|
-- exposed for testing:
|
||||||
hasVersion
|
hasVersion,
|
||||||
|
versionWithoutPath
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
@ -90,13 +91,36 @@ checkTestsBuildReport False =
|
|||||||
checkTestsBuildReport True =
|
checkTestsBuildReport True =
|
||||||
"- The tests defined in `passthru.tests`, if any, passed"
|
"- 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
|
||||||
|
-- /^(?<!${storePathWithoutVersion})${version}/
|
||||||
|
-- Note we also escape the version with \Q/\E for grep -P
|
||||||
|
let storePath = fromMaybe (T.pack resultPath) $ T.stripPrefix "/nix/store/" (T.pack resultPath) in
|
||||||
|
case T.breakOn expectedVersion storePath of
|
||||||
|
(_, "") ->
|
||||||
|
-- no version in prefix, just match version
|
||||||
|
"\\Q"
|
||||||
|
<> T.unpack expectedVersion
|
||||||
|
<> "\\E"
|
||||||
|
(storePrefix, _) ->
|
||||||
|
"(?<!\\Q"
|
||||||
|
<> T.unpack storePrefix
|
||||||
|
<> "\\E)\\Q"
|
||||||
|
<> T.unpack expectedVersion
|
||||||
|
<> "\\E"
|
||||||
|
|
||||||
foundVersionInOutputs :: Text -> String -> IO (Maybe Text)
|
foundVersionInOutputs :: Text -> String -> IO (Maybe Text)
|
||||||
foundVersionInOutputs expectedVersion resultPath =
|
foundVersionInOutputs expectedVersion resultPath =
|
||||||
hush
|
hush
|
||||||
<$> runExceptT
|
<$> runExceptT
|
||||||
( do
|
( do
|
||||||
|
let regex = versionWithoutPath resultPath expectedVersion
|
||||||
(exitCode, _) <-
|
(exitCode, _) <-
|
||||||
proc "grep" ["-r", T.unpack expectedVersion, resultPath]
|
proc "grep" ["-rP", regex, resultPath]
|
||||||
& ourReadProcessInterleaved
|
& ourReadProcessInterleaved
|
||||||
case exitCode of
|
case exitCode of
|
||||||
ExitSuccess ->
|
ExitSuccess ->
|
||||||
|
@ -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 "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 (T.pack "12.34 is the version") (T.pack "2.34") `shouldBe` False
|
||||||
Check.hasVersion seaweedVersion234 (T.pack "2.35") `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` "(?<!\\Qz9l2xakz7cgw6yfh83nh542pvc0g4rkq-geeqie-\\E)\\Q2.0.1\\E"
|
||||||
|
Check.versionWithoutPath "/nix/store/z9l2xakz7cgw6yfh83nh542pvc0g4rkq-abc" (T.pack "2.0.1") `shouldBe` "\\Q2.0.1\\E"
|
||||||
|
Check.versionWithoutPath "/nix/store/z9l2xakz7cgw6yfh83nh542pvc0g4rkq-2.0.1-dev" (T.pack "2.0.1") `shouldBe` "(?<!\\Qz9l2xakz7cgw6yfh83nh542pvc0g4rkq-\\E)\\Q2.0.1\\E"
|
||||||
|
Loading…
Reference in New Issue
Block a user