简体   繁体   English

如何在DocTest中使用ByteStrings和QuickTest?

[英]How to use ByteStrings with QuickTest in DocTest?

How do I define the Arbitrary instance (as stated here ) when using doctest and quickcheck? 如何定义的Arbitrary实例(如说这里使用文档测试和快速检查时)?

Doctest and Cabal are set up as described here with a separate directory for tests. Doctest和Cabal按照此处所述进行设置,并提供单独的测试目录。

The doctest line looks like this: doctest行看起来像这样:

-- prop> (\s -> (decode . encode $ s == s)) :: ByteString -> Bool
decode :: ByteString -> ByteString
encode :: ByteString -> ByteString

Where and how do I define the Arbitrary instance, so that doctest can find it? 我在哪里以及如何定义Arbitrary实例,以便doctest可以找到它? Note that I would want to define it in the test project. 请注意,我想在测试项目中定义它。

Try 尝试

-- $setup
-- >>> import Control.Applicative
-- >>> import qualified Data.ByteString as ByteString
-- >>> import Test.QuickCheck
-- >>> instance Arbitrary ByteString where arbitrary = ByteString.pack <$> arbitrary
-- >>> instance CoArbitrary ByteString where coarbitrary = coarbitrary . ByteString.unpack

-- |
-- prop> \ s -> (decode . encode) s == s
decode:: ByteString -> ByteString
encode :: ByteString -> ByteString

Named chunks can be used for such definitions. 命名块可用于此类定义。 However, each complete definition must be on one line, and doctest will report each use of >>> as a success or failure - so in this case, 6 attempts will be reported, even though only 1 of them is actually a test. 但是,每个完整的定义必须在一行上,doctest将报告每次使用>>>作为成功或失败 - 因此在这种情况下,将报告6次尝试,即使其中只有1次实际上是测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM