Skip to content

Commit ccf28df

Browse files
committed
Re-enable QuickCheck + hspec tests
I can put the tests in `Main.hs` without seeing it come up in the size, provided it's not exported or used from `main`: -rwxr-xr-x 1 chris chris 9.1M Dec 15 08:56 hell-static-hspec-quickcheck-imported-not-used -rwxr-xr-x 1 chris chris 9.1M Dec 15 08:56 hell-static-hspec-quickcheck-imported-used -rwxr-xr-x 1 chris chris 9.1M Dec 15 08:58 hell-static-hspec-quickcheck-imported-used-more -rwxr-xr-x 1 chris chris 9.1M Dec 15 08:55 hell-static-hspec-quickcheck-no-import -rwxr-xr-x 1 chris chris 9.1M Dec 15 08:52 hell-static-no-hspec If I use the tests in `main`, then it shows up: -rwxr-xr-x 1 chris chris 12M Dec 15 09:01 hell-static-hspec-quickcheck-imported-used-in-main
1 parent 4eb1e0e commit ccf28df

File tree

3 files changed

+42
-35
lines changed

3 files changed

+42
-35
lines changed

Hell.hs

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ import Data.Constraint
4545
import GHC.Types
4646
import Type.Reflection (SomeTypeRep(..), TypeRep, typeRepKind, typeRep, pattern TypeRep)
4747

48+
import Test.Hspec
49+
import Test.QuickCheck
50+
4851
--------------------------------------------------------------------------------
4952
-- Untyped AST
5053

@@ -413,17 +416,17 @@ applyTypes (SomeTypeRep f) (SomeTypeRep a) = do
413416
pure $ SomeTypeRep $ Type.App f a
414417
| otherwise -> Nothing
415418

416-
-- desugarTypeSpec :: Spec
417-
-- desugarTypeSpec = do
418-
-- it "desugarType" $ do
419-
-- shouldBe (try "Bool") (Right (SomeStarType $ typeRep @Bool))
420-
-- shouldBe (try "Int") (Right (SomeStarType $ typeRep @Int))
421-
-- shouldBe (try "Bool -> Int") (Right (SomeStarType $ typeRep @(Bool -> Int)))
422-
-- shouldBe (try "()") (Right (SomeStarType $ typeRep @()))
423-
-- shouldBe (try "[Int]") (Right (SomeStarType $ typeRep @[Int]))
424-
-- where try e = case fmap desugarType $ HSE.parseType e of
425-
-- HSE.ParseOk r -> r
426-
-- _ -> error "Parse failed."
419+
desugarTypeSpec :: Spec
420+
desugarTypeSpec = do
421+
it "desugarType" $ do
422+
shouldBe (try "Bool") (Right (SomeStarType $ typeRep @Bool))
423+
shouldBe (try "Int") (Right (SomeStarType $ typeRep @Int))
424+
shouldBe (try "Bool -> Int") (Right (SomeStarType $ typeRep @(Bool -> Int)))
425+
shouldBe (try "()") (Right (SomeStarType $ typeRep @()))
426+
shouldBe (try "[Int]") (Right (SomeStarType $ typeRep @[Int]))
427+
where try e = case fmap desugarType $ HSE.parseType e of
428+
HSE.ParseOk r -> r
429+
_ -> error "Parse failed."
427430

428431
--------------------------------------------------------------------------------
429432
-- Desugar all bindings
@@ -454,19 +457,19 @@ stronglyConnected =
454457
Graph.stronglyConnComp .
455458
map \thing@(name, e) -> (thing, name, freeVariables e)
456459

457-
-- anyCyclesSpec :: Spec
458-
-- anyCyclesSpec = do
459-
-- it "anyCycles" do
460-
-- shouldBe (try [("foo","\\z -> x * Z.y"), ("bar","\\z -> Main.bar * Z.y")]) True
461-
-- shouldBe (try [("foo","\\z -> Main.bar * Z.y"), ("bar","\\z -> Main.foo * Z.y")]) True
462-
-- shouldBe (try [("foo","\\z -> x * Z.y"), ("bar","\\z -> Main.mu * Z.y")]) False
463-
-- shouldBe (try [("foo","\\z -> x * Z.y"), ("bar","\\z -> Main.foo * Z.y")]) False
460+
anyCyclesSpec :: Spec
461+
anyCyclesSpec = do
462+
it "anyCycles" do
463+
shouldBe (try [("foo","\\z -> x * Z.y"), ("bar","\\z -> Main.bar * Z.y")]) True
464+
shouldBe (try [("foo","\\z -> Main.bar * Z.y"), ("bar","\\z -> Main.foo * Z.y")]) True
465+
shouldBe (try [("foo","\\z -> x * Z.y"), ("bar","\\z -> Main.mu * Z.y")]) False
466+
shouldBe (try [("foo","\\z -> x * Z.y"), ("bar","\\z -> Main.foo * Z.y")]) False
464467

465-
-- where
466-
-- try named =
467-
-- case traverse (\(n, e) -> (n, ) <$> HSE.parseExp e) named of
468-
-- HSE.ParseOk decls -> anyCycles decls
469-
-- _ -> error "Parse failed."
468+
where
469+
try named =
470+
case traverse (\(n, e) -> (n, ) <$> HSE.parseExp e) named of
471+
HSE.ParseOk decls -> anyCycles decls
472+
_ -> error "Parse failed."
470473

471474
--------------------------------------------------------------------------------
472475
-- Get free variables of an HSE expression
@@ -480,21 +483,21 @@ freeVariables =
480483
HSE.Qual _ (HSE.ModuleName _ "Main") (HSE.Ident _ name) -> pure name
481484
_ -> Nothing
482485

483-
-- freeVariablesSpec :: Spec
484-
-- freeVariablesSpec = do
485-
-- it "freeVariables" $ shouldBe (try "\\z -> Main.x * Z.y") ["x"]
486-
-- where try e = case fmap freeVariables $ HSE.parseExp e of
487-
-- HSE.ParseOk names -> names
488-
-- _ -> error "Parse failed."
486+
freeVariablesSpec :: Spec
487+
freeVariablesSpec = do
488+
it "freeVariables" $ shouldBe (try "\\z -> Main.x * Z.y") ["x"]
489+
where try e = case fmap freeVariables $ HSE.parseExp e of
490+
HSE.ParseOk names -> names
491+
_ -> error "Parse failed."
489492

490493
--------------------------------------------------------------------------------
491494
-- Test everything
492495

493-
-- spec :: Spec
494-
-- spec = do
495-
-- anyCyclesSpec
496-
-- freeVariablesSpec
497-
-- desugarTypeSpec
496+
spec :: Spec
497+
spec = do
498+
anyCyclesSpec
499+
freeVariablesSpec
500+
desugarTypeSpec
498501

499502
--------------------------------------------------------------------------------
500503
-- Supported type constructors

brossa.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ executable hell
1818
Paths_brossa
1919
ghc-options: -threaded -rtsopts -with-rtsopts=-N
2020
build-depends:
21-
async
21+
QuickCheck
22+
, async
2223
, base >=4.17.2.1
2324
, bytestring
2425
, constraints
2526
, containers
2627
, directory
2728
, ghc-prim
2829
, haskell-src-exts
30+
, hspec
2931
, mtl
3032
, optparse-applicative
3133
, syb

package.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ dependencies:
1818
- constraints
1919
- typed-process
2020
- optparse-applicative
21+
- hspec
22+
- QuickCheck
2123

2224
executables:
2325
hell:

0 commit comments

Comments
 (0)