I have some specs (written with HSpec) and would like to have a test that checks whether the re-exporting of some functions takes place as intended.
Code:
https://github.com/Wizek/compose-ltr/blob/ab954f00beb56c6c1a595261381d40e7e824e3bc/spec/Spec.hs#L4
If I go into this file, I can run all tests with either import if I manually switch whether line 4 or 5 is commented out. Is there a simple way to have an automated specification that ensures that both modules export the same functions?
The first thing I thought of is to import one of the modules qualified, and check for equality:
(($>) == (ComposeLTR.$>)) `shouldBe` True
-- Or more succintly
($>) `shouldBe` (ComposeLTR.$>)
But that won't work since functions are not directly comparable, they are not part of the Eq
type class.
The only thing I can think of that would work automatically is to import qualified and to define QuickCheck properties for all 4 functions like so:
import qualified ComposeLTR
it "should re-export the same function" $ do
let
prop :: (Fun Int Int) -> Int -> Bool
prop (Fun _ f) g = (g $> f) == (g ComposeLTR.$> f)
property prop
-- ... Essentially repeated 3 more times
But that seems awfully long-handed and redundant. Is there an elegant way to check this?
You can use StableName
s in IO:
Prelude Data.List System.Mem.StableName> v <- makeStableName Prelude.takeWhile
Prelude Data.List System.Mem.StableName> v' <- makeStableName Data.List.takeWhile
Prelude Data.List System.Mem.StableName> v == v'
True
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.