on master help sign in
Add should-not-typecheck test
commitd921d7c76880045b556bdf524497419bdac8ec46 authorSridhar Ratnakumar <srid@srid.ca> dateFri 28 Aug 2020, 17:32 (6 years ago) parent2175b25
4 files changed+11−10
bin/test+3−1 jrec.cabal+2−1 src/JRec.hs+1−1 test/JRecSpec.hs+5−7
bin/test+3−1
@@ -1,3 +1,5 @@
11#!/usr/bin/env bash
22set -xe
3−nix-shell --pure --run "ghcid $* -c 'cabal new-repl test:jrec-test' -T \":main $*\""
3+
4+# NOTE: ghcid should be run with -W to allow warnings from should-not-typecheck
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
8282 base,
8383 hspec,
8484 QuickCheck,
85− lens
85+ lens,
86+ should-not-typecheck
src/JRec.hs+1−1
@@ -90,7 +90,7 @@ insert ::
9090 KnownSymbol label,
9191 R.RecCopy lts lts res,
9292 res ~ ((label := value) : lts),
93− R.KeyDoesNotExist label lts
93+ R.RemoveAccessTo label lts ~ lts
9494 ) =>
9595 label := value ->
9696 Rec lts -> Rec res
test/JRecSpec.hs+5−7
@@ -1,8 +1,10 @@
1+{-# OPTIONS_GHC -fdefer-type-errors #-}
12module JRecSpec (spec) where
23
34import Control.Lens ((&), (.~), (^.))
45import JRec
56import Test.Hspec
7+import Test.ShouldNotTypecheck
68
79spec :: Spec
810spec = do
@@ -50,7 +52,7 @@ spec = do
5052 Rec (#a := 1) `append` Rec (#b := 2)
5153 `shouldBe` Rec (#a := 1, #b := 2)
5254 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
5456 -- implementation, the last value (here, 8) will overwrite all duplicate
5557 -- fields. See `union` if you want to deal with duplicates sensibly.
5658 pendingWith "append should just append?"
@@ -71,12 +73,8 @@ spec = do
7173 it "simple insert" $ do
7274 (#a := 1) `insert` Rec (#b := 2, #c := 3)
7375 `shouldBe` Rec (#a := 1, #b := 2, #c := 3)
74− -- TODO: type check should fail
75− -- it "insert of already existing field should fail" $ do
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"
76+ it "type-check fails if field already exists" $ do
77+ shouldNotTypecheck ((#a := '1') `insert` Rec (#b := '2', #a := '0'))
8078 describe "insertOrSet" $ do
8179 it "distinct" $ do
8280 insertOrSet (#a := 1) (Rec (#b := 2, #c := 3))