简体   繁体   English

Haskell Cabal QuickCheck集成

[英]Haskell Cabal QuickCheck Integration

I've been trying to use cabal-install as a way to build and, more importantly, test my haskell projects, a bit alike to the way Maven is used in Java projects, mainly because it seems to be a good way as well to integrate in Jenkins or a ci or so, and it seems to be very reliable in a sense that you don't need a development environment and so on set up to check and confirm whether code is compiling and correct or not. 我一直在尝试使用cabal-install作为一种构建方式,更重要的是,测试我的haskell项目,与Maven在Java项目中使用的方式有点相似,主要是因为它似乎也是一种好方法。集成在Jenkins或ci左右,从某种意义上说它似乎非常可靠,你不需要开发环境等设置来检查和确认代码是否正在编译和纠正。

Anyways, I'm using QuickCheck and HUnit for this. 无论如何,我正在使用QuickCheck和HUnit。 In another post here on stack exchange I found a nice way to integrate HUnit and cabal, by using the function test in Distribution.TestSuite.HUnit to create an exposed tests array in my test module. 在另一篇文章在这里堆栈交流我发现了一个很好的方式,通过使用功能测试中Distribution.TestSuite.HUnit建立在我的测试模块暴露试验阵列整合HUnit和阴谋。 Works. 作品。

I tried to do the same style of set up with quickcheck, 我尝试使用quickcheck进行相同的设置,

    import qualified Distribution.TestSuite.QuickCheck2 as CabalQuickCheck

    alwaysFalseOneArg::Int->(Int,Int)
    alwaysFalseOneArg x = (x,x)

    quickCheckPropOneArg = \s->let (a,b)=alwaysFalseOneArg s  in a==b && a/=b

    cabalQCTest = CabalQuickCheck.test "test" quickCheckPropOneArg

    tests=cabalQCTest:[]

I want to see this test fail. 我想看到这个测试失败了。

The cabal file I have works with the HUnit set up, with HUnit tests running and failing or not failing as they should. 我与HUnit设置的cabal文件,HUnit测试正在运行,失败或没有失败,因为他们应该。 If I use the same set up to perform quickcheck tests however, cabal tells me that it indeed found a test suite, but there are no tests in it. 但是,如果我使用相同的设置来执行quickcheck测试,cabal告诉我它确实找到了一个测试套件,但它没有测试。 I tried the approach that is mentioned on the site of Distribution.TestSuite.QuickCheck2 as well, but there they don't seem to mention how to expose the test and I don't seem to manage to make that run. 我尝试了在Distribution.TestSuite.QuickCheck2 网站上提到的方法,但是他们似乎没有提到如何公开测试,我似乎没有设法做到这一点。 I'm a bit at a loss now, I can run those quickcheck tests with quickcheck itself but not with cabal and I would like to have this to be able to quickly verify all my tests and code and use it in a Jenkins or so. 我现在有点不知所措,我可以用quickcheck本身运行那些quickcheck测试,但不能用cabal运行,我希望能够快速验证我的所有测试和代码并在Jenkins中使用它。 Anybody an idea? 有人有想法吗?

I tried to give all the info that I think is necessary without over-complicating stuff so I didn't post the complete cabal file and so on, if that would be necessary, I of course will do so. 我试图提供我认为必要的所有信息,而不会过于复杂的东西,所以我没有发布完整的cabal文件等等,如果有必要,我当然会这样做。 I found quite a few similar posts, but most of them boil down to using something else than detailed-0.9 which would be a pity as it seems to work quite nicely with HUnit as a set up and I would like to use both HUnit and QuickCheck in the same way of course, preferrably exposing one tests array containing HUnit and QuickCheck tests alike. 我发现了很多类似的帖子,但是大多数都归结为使用了除了详细的0.9之外的其他东西,这可能是一个遗憾,因为它似乎与HUnit作为一个设置很好地工作,我想同时使用HUnit和QuickCheck当然,以同样的方式,最好暴露一个包含HUnit和QuickCheck测试的测试数组。

Kasper 卡斯帕

I agree with isturdy : I would definitely have a go at test-framework + test-framework-quickcheck2 . 我同意isturdy :我肯定会参加test-framework + test-framework-quickcheck2 Check out this example of how to use them together in a project. 查看这个如何在项目中一起使用它们的示例 Notice the properties called prop_* . 注意名为prop_*的属性。

You can also check out the project haskell-minecraft-tool to see what the test output looks like. 您还可以查看项目haskell-minecraft-tool以查看测试输出的样子。 Run the tests with 运行测试

cabal configure --enable-tests && cabal build && cabal test

Look at the .cabal file here to see what packages are required. 查看此处的.cabal文件以查看所需的包。 Namely these are test-framework , test-framework-quickcheck2 , QuickCheck . 即这些是test-frameworktest-framework-quickcheck2QuickCheck

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

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