Skip to content

Commit

Permalink
fix enforce-pact-version decimal parser (#1334)
Browse files Browse the repository at this point in the history
* fix enforce-pact-version decimal parser

* Update tests/pact/versions.repl

Co-authored-by: rsoeldner <[email protected]>

* Update tests/pact/versions.repl

Co-authored-by: rsoeldner <[email protected]>

---------

Co-authored-by: rsoeldner <[email protected]>
  • Loading branch information
emilypi and rsoeldner authored Feb 13, 2024
1 parent d37f549 commit 3fefa52
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Pact/Native.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,21 +1238,23 @@ enforceVersion i as = do
pactVersion'
<- if cond then pure compatVersion else checkNonLocalAllowed i $> pactVersion
case as of
[TLitString minVersion] -> doMin minVersion pactVersion' >> return (toTerm True)
[TLitString minVersion] -> doMin minVersion pactVersion' $> toTerm True
[TLitString minVersion,TLitString maxVersion] ->
doMin minVersion pactVersion' >> doMax maxVersion pactVersion' >> return (toTerm True)
doMin minVersion pactVersion' >> doMax maxVersion pactVersion' $> toTerm True
_ -> argsError i as
where
compatVersion :: Text
compatVersion = "4.2.1"
doMin = doMatch "minimum" (>) (<)
doMax = doMatch "maximum" (<) (>)
doMatch msg failCmp succCmp fullV pactVersion' =
doMatch msg failCmp succCmp fullV pactVersion' = do
foldM_ matchPart False $ zip (T.splitOn "." pactVersion') (T.splitOn "." fullV)
where
parseNum orgV s = case AP.parseOnly (AP.many1 AP.digit) s of
parseNum :: Text -> Text -> Eval e Integer
parseNum orgV s = case AP.parseOnly AP.decimal s of
Left _ -> evalError' i $ "Invalid version component: " <> pretty (orgV,s)
Right v -> return v

matchPart True _ = return True
matchPart _ (pv,mv) = do
pv' <- parseNum pactVersion' pv
Expand Down
26 changes: 26 additions & 0 deletions tests/pact/versions.repl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


(expect
"pact version bounds work for current pact version"
true
(enforce-pact-version "3.0.0" "6.0.0"))

(expect
"enforce-pact-version works for current pact version"
true
(enforce-pact-version (pact-version)))

(expect-failure
"pact version bounds fail for current version if wrong bounds"
(enforce-pact-version "6.0.0" "100.0.0"))

;; regression #1327
(expect
"enforce-pact-version succeeds for current version if lower bound set"
true
(enforce-pact-version "1.0.0"))

(expect
"enforce-pact-version succeeds (double digit regression)"
true
(enforce-pact-version "3.0000.0" "88.420.0"))

0 comments on commit 3fefa52

Please sign in to comment.