Skip to content

Commit

Permalink
More HasCallStack in yesod-test (#1858)
Browse files Browse the repository at this point in the history
* adding more hascallstack because anything that can fail should mark where it fails

* bump version

* add to changelog
  • Loading branch information
L0neGamer authored Feb 1, 2025
1 parent 32b0d39 commit 84d28cd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
4 changes: 4 additions & 0 deletions yesod-test/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog for yesod-test

## 1.6.20

* Add `HasCallStack` to more functions. [#1858](https://github.com/yesodweb/yesod/pull/1858)

## 1.6.19

* Add `selectByLabel` to yesod-test. [#1845](https://github.com/yesodweb/yesod/pull/1845)
Expand Down
61 changes: 39 additions & 22 deletions yesod-test/Yesod/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ printMatches query = do
-- > {-# LANGUAGE OverloadedStrings #-}
-- > post $ do
-- > addPostParam "key" "value"
addPostParam :: T.Text -> T.Text -> RequestBuilder site ()
addPostParam :: HasCallStack => T.Text -> T.Text -> RequestBuilder site ()
addPostParam name value =
modifySIO $ \rbd -> rbd { rbdPostData = (addPostData (rbdPostData rbd)) }
where addPostData (BinaryPostData _) = error "Trying to add post param to binary content."
Expand Down Expand Up @@ -881,7 +881,8 @@ addBareGetParam name = modifySIO $ \rbd ->
--
-- > request $ do
-- > addFile "profile_picture" "static/img/picture.png" "img/png"
addFile :: T.Text -- ^ The parameter name for the file.
addFile :: HasCallStack
=> T.Text -- ^ The parameter name for the file.
-> FilePath -- ^ The path to the file.
-> T.Text -- ^ The MIME type of the file, e.g. "image/png".
-> RequestBuilder site ()
Expand Down Expand Up @@ -955,15 +956,17 @@ genericNameFromHTML match label html =
name:_ -> Right name
_ -> Left $ "More than one label contained " <> label

byLabelWithMatch :: (T.Text -> T.Text -> Bool) -- ^ The matching method which is used to find labels (i.e. exact, contains)
byLabelWithMatch :: HasCallStack
=> (T.Text -> T.Text -> Bool) -- ^ The matching method which is used to find labels (i.e. exact, contains)
-> T.Text -- ^ The text contained in the @\<label>@.
-> T.Text -- ^ The value to set the parameter to.
-> RequestBuilder site ()
byLabelWithMatch match label value = do
name <- genericNameFromLabel match label
addPostParam name value

bySelectorLabelWithMatch :: (T.Text -> T.Text -> Bool) -- ^ The matching method which is used to find labels (i.e. exact, contains)
bySelectorLabelWithMatch :: HasCallStack
=> (T.Text -> T.Text -> Bool) -- ^ The matching method which is used to find labels (i.e. exact, contains)
-> T.Text -- ^ The CSS selector.
-> T.Text -- ^ The text contained in the @\<label>@.
-> T.Text -- ^ The value to set the parameter to.
Expand Down Expand Up @@ -1017,7 +1020,8 @@ bySelectorLabelWithMatch match selector label value = do
--
-- Therefore, this function is deprecated. Please consider using 'byLabelExact',
-- which performs the exact match over the provided text.
byLabel :: T.Text -- ^ The text contained in the @\<label>@.
byLabel :: HasCallStack
=> T.Text -- ^ The text contained in the @\<label>@.
-> T.Text -- ^ The value to set the parameter to.
-> RequestBuilder site ()
byLabel = byLabelWithMatch T.isInfixOf
Expand Down Expand Up @@ -1047,7 +1051,8 @@ byLabel = byLabelWithMatch T.isInfixOf
-- > </form>
--
-- @since 1.5.9
byLabelExact :: T.Text -- ^ The text in the @\<label>@.
byLabelExact :: HasCallStack
=> T.Text -- ^ The text in the @\<label>@.
-> T.Text -- ^ The value to set the parameter to.
-> RequestBuilder site ()
byLabelExact = byLabelWithMatch (==)
Expand All @@ -1058,7 +1063,8 @@ byLabelExact = byLabelWithMatch (==)
-- Note: Just like 'byLabel', this function throws an error if it finds multiple labels
--
-- @since 1.6.2
byLabelContain :: T.Text -- ^ The text in the @\<label>@.
byLabelContain :: HasCallStack
=> T.Text -- ^ The text in the @\<label>@.
-> T.Text -- ^ The value to set the parameter to.
-> RequestBuilder site ()
byLabelContain = byLabelWithMatch T.isInfixOf
Expand All @@ -1069,7 +1075,8 @@ byLabelContain = byLabelWithMatch T.isInfixOf
-- Note: Just like 'byLabel', this function throws an error if it finds multiple labels
--
-- @since 1.6.2
byLabelPrefix :: T.Text -- ^ The text in the @\<label>@.
byLabelPrefix :: HasCallStack
=> T.Text -- ^ The text in the @\<label>@.
-> T.Text -- ^ The value to set the parameter to.
-> RequestBuilder site ()
byLabelPrefix = byLabelWithMatch T.isPrefixOf
Expand All @@ -1080,7 +1087,8 @@ byLabelPrefix = byLabelWithMatch T.isPrefixOf
-- Note: Just like 'byLabel', this function throws an error if it finds multiple labels
--
-- @since 1.6.2
byLabelSuffix :: T.Text -- ^ The text in the @\<label>@.
byLabelSuffix :: HasCallStack
=> T.Text -- ^ The text in the @\<label>@.
-> T.Text -- ^ The value to set the parameter to.
-> RequestBuilder site ()
byLabelSuffix = byLabelWithMatch T.isSuffixOf
Expand All @@ -1091,13 +1099,15 @@ byLabelSuffix = byLabelWithMatch T.isSuffixOf
-- fragments.
--
-- @since 1.6.15
bySelectorLabelContain :: T.Text -- ^ The CSS selector.
bySelectorLabelContain :: HasCallStack
=> T.Text -- ^ The CSS selector.
-> T.Text -- ^ The text in the @\<label>@.
-> T.Text -- ^ The value to set the parameter to.
-> RequestBuilder site ()
bySelectorLabelContain = bySelectorLabelWithMatch T.isInfixOf

fileByLabelWithMatch :: (T.Text -> T.Text -> Bool) -- ^ The matching method which is used to find labels (i.e. exact, contains)
fileByLabelWithMatch :: HasCallStack
=> (T.Text -> T.Text -> Bool) -- ^ The matching method which is used to find labels (i.e. exact, contains)
-> T.Text -- ^ The text contained in the @\<label>@.
-> FilePath -- ^ The path to the file.
-> T.Text -- ^ The MIME type of the file, e.g. "image/png".
Expand Down Expand Up @@ -1130,7 +1140,8 @@ fileByLabelWithMatch match label path mime = do
-- > </form>
--
-- Warning: This function has the same issue as 'byLabel'. Please use 'fileByLabelExact' instead.
fileByLabel :: T.Text -- ^ The text contained in the @\<label>@.
fileByLabel :: HasCallStack
=> T.Text -- ^ The text contained in the @\<label>@.
-> FilePath -- ^ The path to the file.
-> T.Text -- ^ The MIME type of the file, e.g. "image/png".
-> RequestBuilder site ()
Expand Down Expand Up @@ -1160,7 +1171,8 @@ fileByLabel = fileByLabelWithMatch T.isInfixOf
-- > </form>
--
-- @since 1.5.9
fileByLabelExact :: T.Text -- ^ The text contained in the @\<label>@.
fileByLabelExact :: HasCallStack
=> T.Text -- ^ The text contained in the @\<label>@.
-> FilePath -- ^ The path to the file.
-> T.Text -- ^ The MIME type of the file, e.g. "image/png".
-> RequestBuilder site ()
Expand All @@ -1172,7 +1184,8 @@ fileByLabelExact = fileByLabelWithMatch (==)
-- Note: Just like 'fileByLabel', this function throws an error if it finds multiple labels
--
-- @since 1.6.2
fileByLabelContain :: T.Text -- ^ The text contained in the @\<label>@.
fileByLabelContain :: HasCallStack
=> T.Text -- ^ The text contained in the @\<label>@.
-> FilePath -- ^ The path to the file.
-> T.Text -- ^ The MIME type of the file, e.g. "image/png".
-> RequestBuilder site ()
Expand All @@ -1184,7 +1197,8 @@ fileByLabelContain = fileByLabelWithMatch T.isInfixOf
-- Note: Just like 'fileByLabel', this function throws an error if it finds multiple labels
--
-- @since 1.6.2
fileByLabelPrefix :: T.Text -- ^ The text contained in the @\<label>@.
fileByLabelPrefix :: HasCallStack
=> T.Text -- ^ The text contained in the @\<label>@.
-> FilePath -- ^ The path to the file.
-> T.Text -- ^ The MIME type of the file, e.g. "image/png".
-> RequestBuilder site ()
Expand All @@ -1196,7 +1210,8 @@ fileByLabelPrefix = fileByLabelWithMatch T.isPrefixOf
-- Note: Just like 'fileByLabel', this function throws an error if it finds multiple labels
--
-- @since 1.6.2
fileByLabelSuffix :: T.Text -- ^ The text contained in the @\<label>@.
fileByLabelSuffix :: HasCallStack
=> T.Text -- ^ The text contained in the @\<label>@.
-> FilePath -- ^ The path to the file.
-> T.Text -- ^ The MIME type of the file, e.g. "image/png".
-> RequestBuilder site ()
Expand Down Expand Up @@ -1408,7 +1423,8 @@ setMethod m = modifySIO $ \rbd -> rbd { rbdMethod = m }
--
-- > request $ do
-- > setUrl ("http://google.com/" :: Text)
setUrl :: (Yesod site, RedirectUrl site url)
setUrl :: HasCallStack
=> (Yesod site, RedirectUrl site url)
=> url
-> RequestBuilder site ()
setUrl url' = do
Expand Down Expand Up @@ -1501,7 +1517,8 @@ addBasicAuthHeader username password =
-- > byLabel "First Name" "Felipe"
-- > setMethod "PUT"
-- > setUrl NameR
request :: RequestBuilder site ()
request :: HasCallStack
=> RequestBuilder site ()
-> YesodExample site ()
request reqBuilder = do
YesodExampleData app site oldCookies mRes <- getSIO
Expand Down Expand Up @@ -1706,7 +1723,7 @@ instance YesodDispatch site => Hspec.Example (SIO (YesodExampleData site) a) whe
-- > chooseByLabel "Blue"
--
-- @since 1.6.17
chooseByLabel :: T.Text -> RequestBuilder site ()
chooseByLabel :: HasCallStack => T.Text -> RequestBuilder site ()
chooseByLabel label = do
name <- genericNameFromLabel (==) label
value <- genericValueFromLabel (==) label
Expand Down Expand Up @@ -1740,7 +1757,7 @@ chooseByLabel label = do
-- > checkByLabel "Black"
--
-- @since 1.6.18
checkByLabel :: T.Text -> RequestBuilder site ()
checkByLabel :: HasCallStack => T.Text -> RequestBuilder site ()
checkByLabel label = do
name <- genericNameFromLabel (==) label
value <- genericValueFromLabel (==) label
Expand Down Expand Up @@ -1770,7 +1787,7 @@ checkByLabel label = do
-- > selectByLabel "Selection List" "Blue"
--
-- @since 1.6.19
selectByLabel :: T.Text -> T.Text -> RequestBuilder site ()
selectByLabel :: HasCallStack => T.Text -> T.Text -> RequestBuilder site ()
selectByLabel label option = do
name <- genericNameFromLabel (==) label
parsedHtml <- parseHTML <$> htmlBody "selectByLabel"
Expand Down Expand Up @@ -1830,7 +1847,7 @@ genericValueFromHTML match label html =
value:_ -> Right value
_ -> Left $ "More than one label contained " <> label

htmlBody :: String -> RequestBuilder site BSL8.ByteString
htmlBody :: HasCallStack => String -> RequestBuilder site BSL8.ByteString
htmlBody funcName = do
mres <- fmap rbdResponse getSIO
res <-
Expand Down
2 changes: 1 addition & 1 deletion yesod-test/yesod-test.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: yesod-test
version: 1.6.19
version: 1.6.20
license: MIT
license-file: LICENSE
author: Nubis <[email protected]>
Expand Down

0 comments on commit 84d28cd

Please sign in to comment.