Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Start with a testing infrastructure.

  • Loading branch information...
commit 85f6f6d6e622855c89720f8ccfa329b667ae140f 1 parent bad0b9d
@nominolo nominolo authored
Showing with 42 additions and 2 deletions.
  1. +7 −2 scion.cabal
  2. +35 −0 src/Test/GHC/Gen.hs
View
9 scion.cabal
@@ -13,19 +13,24 @@ build-type: Simple
cabal-version: >= 1.4
-- tested-with: GHC ==6.10.1
-- extra-source-files: README
+flag testing
+ description: Enable Debugging things like QuickCheck properties, etc.
+ default: False
library
build-depends: base == 4.*,
directory == 1.0.*,
Cabal >= 1.5 && < 1.8
hs-source-dirs: src
--- extensions: Rank2Types
+ extensions: CPP, PatternGuards
exposed-modules:
Scion.Types,
Scion.Inspect,
Scion.Utils,
Scion
-
+ if flag(testing)
+ build-depends: QuickCheck == 2.*
+ cpp-options: -DDEBUG
executable test_get_imports
main-is: GetImports.hs
View
35 src/Test/GHC/Gen.hs
@@ -0,0 +1,35 @@
+{-# LANGUAGE CPP #-}
+module Test.GHC.Gen where
+
+#ifdef DEBUG
+import Test.QuickCheck
+
+import SrcLoc
+import FastString
+
+instance Arbitrary SrcSpan where
+ arbitrary = sized $ \s -> do
+ let file = mkFastString "<testing>"
+ l_from <- choose (1, s+1)
+ c_from <- choose (0, s)
+ l_len <- choose (0, s)
+ c_len <- choose (1, s+1)
+ return $
+ mkSrcSpan
+ (mkSrcLoc file l_from c_from)
+ (mkSrcLoc file (l_from+l_len) (c_from+c_len))
+ -- XXX: if l_len > 0 then c_len + c_from >= 0 is enough
+
+instance Show SrcSpan where
+ show s
+ | not (isGoodSrcSpan s) = "<unhelpful span>"
+ | isOneLineSpan s = show (srcSpanStartLine s) ++ ":" ++
+ let c1 = srcSpanStartCol s
+ c2 = srcSpanEndCol s - 1
+ in if c1 < c2
+ then show c1 ++ "-" ++ show c2
+ else show c1
+ | otherwise =
+ show (srcSpanStartLine s) ++ ":" ++ show (srcSpanStartCol s) ++ "-"
+ ++ show (srcSpanEndLine s) ++ ":" ++ show (srcSpanEndCol s)
+#endif
Please sign in to comment.
Something went wrong with that request. Please try again.