on master help sign in
broken wip
commitbbba0558f80a98328ac43ad8fcaa5ef312ffbcac authorMark Wotton <mwotton@gmail.com> dateThu 26 Nov 2020, 14:48 (6 years ago) parentec36997
4 files changed+22−32
src/Roboservant/Direct.hs+5−4 src/Roboservant/Types/Breakdown.hs+5−21 stack.yaml+6−1 test/Spec.hs+6−6
src/Roboservant/Direct.hs+5−4
@@ -73,7 +73,6 @@ data RoboservantException
7373 = RoboservantException
7474 { failureReason :: FailureType
7575 , serverException :: Maybe SomeException
76− , something :: Int
7776 , fuzzState :: FuzzState
7877 } deriving (Show)
7978
@@ -151,9 +150,11 @@ fuzz server Config{..} checker = handle (pure . Just . formatException) $ do
151150 mapM_ print (Set.toList $ Set.fromList $ map apiOffset path)
152151 putStrLn ""
153152 putStrLn "types in stash"
154− mapM_
155− (print . second NEL.length)
156− (sortOn (show . fst) . Map.toList stash)
153+ DM.forWithKey_ (getStash stash) $ \k v ->
154+ print (k,NEL.length $ getStashValue v)
155+ -- mapM_
156+ -- (print . second NEL.length)
157+ -- (sortOn (show . fst) $ Map.toList $ getStash stash)
157158
158159 -- evaluateCoverage :: FuzzState -> m ()
159160 evaluateCoverage f@FuzzState{..}
src/Roboservant/Types/Breakdown.hs+5−21
@@ -25,10 +25,7 @@ import Data.List.NonEmpty (NonEmpty(..))
2525import qualified Data.List.NonEmpty as NEL
2626import qualified Data.Map.Strict as Map
2727import Data.Maybe (fromMaybe)
28−import Data.Proxy (Proxy (..))
29−import Data.Typeable (TypeRep, Typeable, typeRep)
3028import GHC.Generics(Generic)
31−import qualified GHC.Generics as Generics
3229import Data.Typeable (Typeable)
3330import qualified Data.Dependent.Map as DM
3431import Data.Dependent.Map (DMap)
@@ -42,9 +39,6 @@ data Provenance
4239
4340class Breakdown x where
4441 breakdown :: x -> NonEmpty Dynamic
45−-- default breakdown :: Typeable x => x -> NonEmpty Dynamic
46−-- breakdown = pure . toDyn
47−
4842
4943-- | Can't be built up from parts
5044newtype Atom x = Atom { unAtom :: x }
@@ -55,15 +49,15 @@ newtype Compound x = Compound { unCompound :: x }
5549-- | so, this is quite tricky. we need to witness the structure of `x`, but
5650-- we don't have an example of it yet. not entirely sure where to go.
5751instance (Typeable x, Generic x) => BuildFrom (Compound x) where
58− buildFrom stash = error "oops"
52+ buildFrom _stash = error "oops"
5953-- breakdown = Map.fromListWith (<>) . fmap ((dynTypeRep &&& (\x -> NEL.fromList [x])) . toDyn . Generics.to) . _ . Generics.from
6054
61−-- | this should be a bit more tractable.
62−instance (Typeable x, Generic x) => Breakdown (Compound x) where
63− breakdown x = _ . Generics.from . unCompound $ x
55+-- -- | this should be a bit more tractable.
56+-- instance (Typeable x, Generic x) => Breakdown (Compound x) where
57+-- breakdown x = _ . Generics.from . unCompound $ x
6458
6559instance Typeable x => BuildFrom (Atom x) where
66− buildFrom = Map.lookup (typeRep (Proxy @x))
60+ buildFrom = DM.lookup R.typeRep . getStash
6761
6862newtype StashValue a = StashValue { getStashValue :: NonEmpty ([Provenance], a) }
6963 deriving (Functor, Show)
@@ -79,21 +73,11 @@ instance Show Stash where
7973
8074class Typeable x => BuildFrom (x :: Type) where
8175 buildFrom :: Stash -> Maybe (StashValue x)
82− default buildFrom :: Stash -> Maybe (StashValue x)
83− buildFrom = DM.lookup R.typeRep . getStash
84−
85− -- (fmap promisedDyn . NEL.toList) . Map.lookup (typeRep (Proxy @x))
86−
87−
88−-- baseLookup :: TypeRep -> Stash -> Maybe (NonEmpty ([Provenance], Dynamic))
89−-- baseLookup tr mmm = -- Map.lookup (typeRep (Proxy @x)) mmm
90−-- Map.lookup tr mmm
9176
9277-- | only use this when we are using the internal typerep map.
9378promisedDyn :: Typeable a => Dynamic -> a
9479promisedDyn = fromMaybe (error "internal error, typerep map misconstructed") . fromDynamic
9580
96−-- instance BuildFrom Bool
9781deriving via (Atom Bool) instance BuildFrom Bool
9882
9983instance (Typeable x, BuildFrom x) => BuildFrom (Maybe x) where
stack.yaml+6−1
@@ -1,4 +1,5 @@
1−resolver: lts-16.8 #lts-16.16
1+# nb: 16.8 doesn't work because the version of servant is too old to have FoldLenient', fixme.
2+resolver: lts-16.16
23packages:
34- .
45
@@ -8,3 +9,7 @@ extra-deps:
89- dependent-sum-0.7.1.0
910- constraints-extras-0.3.0.2
1011- dependent-map-0.4.0.0
12+- servant-0.18.2
13+- servant-client-0.18.2
14+- servant-client-core-0.18.2
15+- servant-server-0.18.2
test/Spec.hs+6−6
@@ -63,10 +63,10 @@ spec = do
6363 RS.fuzz @Headers.Api Headers.server defaultConfig noCheck
6464 >>= (`shouldSatisfy` isJust)
6565
66− describe "can build from pieces" $ do
67− it "should find a failure that requires some assembly" $ do
68− RS.fuzz @BuildFrom.Api BuildFrom.server defaultConfig noCheck
69− >>= (`shouldSatisfy` isJust)
66+ -- describe "can build from pieces" $ do
67+ -- it "should find a failure that requires some assembly" $ do
68+ -- RS.fuzz @BuildFrom.Api BuildFrom.server defaultConfig noCheck
69+ -- >>= (`shouldSatisfy` isJust)
7070
7171
7272
@@ -103,8 +103,8 @@ deriving via (Atom Post.FooPost) instance RS.BuildFrom Post.FooPost
103103deriving via (Atom Post.FooPost) instance RS.Breakdown Post.FooPost
104104
105105
106−deriving via (Compound BuildFrom.Wrapped) instance RS.BuildFrom BuildFrom.Wrapped
107−deriving via (Compound BuildFrom.Wrapped) instance RS.Breakdown BuildFrom.Wrapped
106+--deriving via (Compound BuildFrom.Wrapped) instance RS.BuildFrom BuildFrom.Wrapped
107+--deriving via (Compound BuildFrom.Wrapped) instance RS.Breakdown BuildFrom.Wrapped
108108
109109
110110