on master help sign in
Add should-not-typecheck test
d921d7cSridhar Ratnakumar
bin/test+3−1
@@ -1,3 +1,5 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2set -xe
2set -xe
3+
4+# NOTE: ghcid should be run with -W to allow warnings from should-not-typecheck
3−nix-shell --pure --run "ghcid $* -c 'cabal new-repl test:jrec-test' -T \":main $*\""
5+nix-shell --pure --run "ghcid $* -W -c 'cabal new-repl test:jrec-test' -T \":main $*\""
jrec.cabal+2−1
@@ -82,4 +82,5 @@ test-suite jrec-test
82 base,
82 base,
83 hspec,
83 hspec,
84 QuickCheck,
84 QuickCheck,
85− lens
85+ lens,
86+ should-not-typecheck
src/JRec.hs+1−1
@@ -90,7 +90,7 @@ insert ::
90 KnownSymbol label,
90 KnownSymbol label,
91 R.RecCopy lts lts res,
91 R.RecCopy lts lts res,
92 res ~ ((label := value) : lts),
92 res ~ ((label := value) : lts),
93− R.KeyDoesNotExist label lts
93+ R.RemoveAccessTo label lts ~ lts
94 ) =>
94 ) =>
95 label := value ->
95 label := value ->
96 Rec lts -> Rec res
96 Rec lts -> Rec res
test/JRecSpec.hs+5−7
@@ -1,8 +1,10 @@
1+{-# OPTIONS_GHC -fdefer-type-errors #-}
1module JRecSpec (spec) where
2module JRecSpec (spec) where
2
3
3import Control.Lens ((&), (.~), (^.))
4import Control.Lens ((&), (.~), (^.))
4import JRec
5import JRec
5import Test.Hspec
6import Test.Hspec
7+import Test.ShouldNotTypecheck
6
8
7spec :: Spec
9spec :: Spec
8spec = do
10spec = do
@@ -50,7 +52,7 @@ spec = do
50 Rec (#a := 1) `append` Rec (#b := 2)
52 Rec (#a := 1) `append` Rec (#b := 2)
51 `shouldBe` Rec (#a := 1, #b := 2)
53 `shouldBe` Rec (#a := 1, #b := 2)
52 it "append with duplicates" $ do
54 it "append with duplicates" $ do
53− -- `append` will not deal with duplicates; based on current
55+ -- TODO: `append` will not deal with duplicates; based on current
54 -- implementation, the last value (here, 8) will overwrite all duplicate
56 -- implementation, the last value (here, 8) will overwrite all duplicate
55 -- fields. See `union` if you want to deal with duplicates sensibly.
57 -- fields. See `union` if you want to deal with duplicates sensibly.
56 pendingWith "append should just append?"
58 pendingWith "append should just append?"
@@ -71,12 +73,8 @@ spec = do
71 it "simple insert" $ do
73 it "simple insert" $ do
72 (#a := 1) `insert` Rec (#b := 2, #c := 3)
74 (#a := 1) `insert` Rec (#b := 2, #c := 3)
73 `shouldBe` Rec (#a := 1, #b := 2, #c := 3)
75 `shouldBe` Rec (#a := 1, #b := 2, #c := 3)
74− -- TODO: type check should fail
76+ it "type-check fails if field already exists" $ do
75− -- it "insert of already existing field should fail" $ do
77+ shouldNotTypecheck ((#a := '1') `insert` Rec (#b := '2', #a := '0'))
76− -- (#a := 1) `insert` Rec (#b := 2, #a := 0, #c := 3)
77− -- `shouldBe` Rec (#a := 1, #b := 2, #a := 0, #c := 3)
78− it "duplicate insert should be disallowed" $ do
79− pendingWith "TODO"
80 describe "insertOrSet" $ do
78 describe "insertOrSet" $ do
81 it "distinct" $ do
79 it "distinct" $ do
82 insertOrSet (#a := 1) (Rec (#b := 2, #c := 3))
80 insertOrSet (#a := 1) (Rec (#b := 2, #c := 3))