with-location 0.0.0 → 0.1.0
raw patch · 5 files changed
+47/−24 lines, 5 filesdep +hspecdep +with-location
Dependencies added: hspec, with-location
Files
- includes/with-location.h +0/−16
- src/Data/WithLocation.hs +14/−2
- test/Data/WithLocationSpec.hs +16/−0
- test/Spec.hs +1/−0
- with-location.cabal +16/−6
− includes/with-location.h
@@ -1,16 +0,0 @@-#if MIN_VERSION_base(4,8,1)-#define HAS_SOURCE_LOCATIONS-{-# LANGUAGE ImplicitParams #-}-#endif--#ifdef HAS_SOURCE_LOCATIONS--#define with_location (?loc :: CallStack) =>-#define with_location_imports import GHC.Stack (CallStack)--#else--#define with_location-#define with_location_imports--#endif
src/Data/WithLocation.hs view
@@ -1,5 +1,11 @@ {-# LANGUAGE CPP #-}-#include "with-location.h"+{-# LANGUAGE Rank2Types #-}++#if MIN_VERSION_base(4,8,1)+#define HAS_SOURCE_LOCATIONS+{-# LANGUAGE ImplicitParams #-}+#endif+ module Data.WithLocation where #ifdef HAS_SOURCE_LOCATIONS@@ -9,6 +15,12 @@ import GHC.Stack #endif +#ifdef HAS_SOURCE_LOCATIONS+type WithLocation a = (?loc :: CallStack) => a+#else+type WithLocation a = a+#endif+ data Location = Location { locationPackage :: String , locationModule :: String@@ -17,7 +29,7 @@ , locationColumn :: Int } deriving (Eq, Ord, Show) -location :: with_location Maybe Location+location :: WithLocation (Maybe Location) #ifdef HAS_SOURCE_LOCATIONS location = case reverse (getCallStack ?loc) of (_, loc) : _ -> Just $ Location (srcLocPackage loc) (srcLocModule loc) (srcLocFile loc) (srcLocStartLine loc) (srcLocStartCol loc)
+ test/Data/WithLocationSpec.hs view
@@ -0,0 +1,16 @@+{-# LANGUAGE CPP #-}+module Data.WithLocationSpec (spec) where++import Test.Hspec++import Data.WithLocation++spec :: Spec+spec = do+ describe "location" $ do+ it "returns a source location" $ do+#if MIN_VERSION_base(4,8,1)+ location `shouldBe` Just (Location "main" "Data.WithLocationSpec" __FILE__ __LINE__ 7)+#else+ location `shouldBe` Nothing+#endif
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
with-location.cabal view
@@ -1,9 +1,9 @@--- This file has been generated from package.yaml by hpack version 0.10.0.+-- This file has been generated from package.yaml by hpack version 0.11.0. -- -- see: https://github.com/sol/hpack name: with-location-version: 0.0.0+version: 0.1.0 synopsis: Use ImplicitParams-based source locations in a backward compatible way category: Data homepage: https://github.com/sol/with-location#readme@@ -22,12 +22,22 @@ hs-source-dirs: src ghc-options: -Wall- include-dirs:- includes- install-includes:- with-location.h build-depends: base == 4.* exposed-modules: Data.WithLocation+ default-language: Haskell2010++test-suite spec+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ hs-source-dirs:+ test+ ghc-options: -Wall+ build-depends:+ base == 4.*+ , hspec+ , with-location+ other-modules:+ Data.WithLocationSpec default-language: Haskell2010