mirror of
https://github.com/ocharles/weeder.git
synced 2024-11-23 06:54:10 +03:00
Tidy
This commit is contained in:
parent
7f5a6a915a
commit
2c7c18b0b0
@ -1,21 +1,21 @@
|
||||
{ mkDerivation, ansi-wl-pprint, base, base-compat, bytestring
|
||||
, containers, criterion, deepseq, doctest, mtl, pgp-wordlist
|
||||
, QuickCheck, random, stdenv, tasty, tasty-hunit, tasty-quickcheck
|
||||
, text, transformers
|
||||
, containers, deepseq, doctest, gauge, mtl, pgp-wordlist
|
||||
, QuickCheck, quickcheck-instances, random, stdenv, tasty
|
||||
, tasty-hunit, tasty-quickcheck, text, transformers
|
||||
}:
|
||||
mkDerivation {
|
||||
pname = "prettyprinter";
|
||||
version = "1.4.0";
|
||||
sha256 = "7f1d9224f9e577eb24dda695beb6bc2f074e93a84a3c9f11bb578aa6ed39cb45";
|
||||
version = "1.6.1";
|
||||
sha256 = "3f9765764db7b55db8fb29b92ad26a02f08364e5947a89e2e1aa6d8a6087d781";
|
||||
isLibrary = true;
|
||||
isExecutable = true;
|
||||
libraryHaskellDepends = [ base text ];
|
||||
testHaskellDepends = [
|
||||
base bytestring doctest pgp-wordlist QuickCheck tasty tasty-hunit
|
||||
tasty-quickcheck text
|
||||
base bytestring doctest pgp-wordlist QuickCheck
|
||||
quickcheck-instances tasty tasty-hunit tasty-quickcheck text
|
||||
];
|
||||
benchmarkHaskellDepends = [
|
||||
ansi-wl-pprint base base-compat containers criterion deepseq mtl
|
||||
ansi-wl-pprint base base-compat containers deepseq gauge mtl
|
||||
QuickCheck random text transformers
|
||||
];
|
||||
homepage = "http://github.com/quchen/prettyprinter";
|
||||
|
@ -1,24 +0,0 @@
|
||||
{ mkDerivation, ansi-wl-pprint, base, base-compat, bytestring
|
||||
, containers, deepseq, doctest, gauge, mtl, pgp-wordlist
|
||||
, QuickCheck, quickcheck-instances, random, stdenv, tasty
|
||||
, tasty-hunit, tasty-quickcheck, text, transformers
|
||||
}:
|
||||
mkDerivation {
|
||||
pname = "prettyprinter";
|
||||
version = "1.6.1";
|
||||
sha256 = "3f9765764db7b55db8fb29b92ad26a02f08364e5947a89e2e1aa6d8a6087d781";
|
||||
isLibrary = true;
|
||||
isExecutable = true;
|
||||
libraryHaskellDepends = [ base text ];
|
||||
testHaskellDepends = [
|
||||
base bytestring doctest pgp-wordlist QuickCheck
|
||||
quickcheck-instances tasty tasty-hunit tasty-quickcheck text
|
||||
];
|
||||
benchmarkHaskellDepends = [
|
||||
ansi-wl-pprint base base-compat containers deepseq gauge mtl
|
||||
QuickCheck random text transformers
|
||||
];
|
||||
homepage = "http://github.com/quchen/prettyprinter";
|
||||
description = "A modern, easy to use, well-documented, extensible pretty-printer";
|
||||
license = stdenv.lib.licenses.bsd2;
|
||||
}
|
19
shell.nix
19
shell.nix
@ -14,31 +14,14 @@ let
|
||||
)
|
||||
( self:
|
||||
super:
|
||||
{ dhall =
|
||||
self.callPackage ./dhall.nix {};
|
||||
|
||||
weeder =
|
||||
{ weeder =
|
||||
self.callCabal2nix
|
||||
"weeder"
|
||||
( cleanSource ./. )
|
||||
{};
|
||||
|
||||
cborg =
|
||||
self.callPackage ./cborg.nix {};
|
||||
|
||||
cborg-json =
|
||||
self.callPackage ./cborg-json.nix {};
|
||||
|
||||
prettyprinter =
|
||||
self.callPackage ./prettyprinter.nix {};
|
||||
|
||||
atomic-write =
|
||||
self.callPackage ./atomic-write.nix {};
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
in
|
||||
haskellPackages.weeder.env
|
||||
# .overrideAttrs
|
||||
# ( old: { buildInputs = old.buildInputs or [] ++ [ haskellPackages.ghcide ]; } )
|
||||
|
179
tests/Main.hs
179
tests/Main.hs
@ -1,179 +0,0 @@
|
||||
{-# language BlockArguments #-}
|
||||
{-# language LambdaCase #-}
|
||||
{-# language PackageImports #-}
|
||||
{-# language NondecreasingIndentation #-}
|
||||
|
||||
module Main where
|
||||
|
||||
import "base" Control.Monad ( unless )
|
||||
import "base" Control.Monad.IO.Class ( liftIO )
|
||||
import "base" Data.Foldable ( for_, traverse_, toList )
|
||||
|
||||
import qualified "containers" Data.Set as Set
|
||||
|
||||
import "directory" System.Directory ( doesPathExist, withCurrentDirectory, canonicalizePath, listDirectory, doesFileExist, doesDirectoryExist )
|
||||
|
||||
import "filepath" System.FilePath ( isExtensionOf, takeBaseName )
|
||||
|
||||
import "ghc" GHC
|
||||
( Target( Target, targetId, targetAllowObjCode, targetContents )
|
||||
, LoadHowMuch( LoadAllTargets )
|
||||
, TargetId ( TargetFile )
|
||||
, TypecheckedModule( TypecheckedModule, tm_internals_, tm_renamed_source )
|
||||
, addTarget
|
||||
, getModSummary
|
||||
, getSession
|
||||
, getSessionDynFlags
|
||||
, load
|
||||
, mkModuleName
|
||||
, parseModule
|
||||
, runGhc
|
||||
, setSessionDynFlags
|
||||
, typecheckModule
|
||||
)
|
||||
import "ghc" HieAst ( mkHieFile )
|
||||
import "ghc" HieTypes ( hie_asts, getAsts )
|
||||
import "ghc" HieDebug ( ppHie )
|
||||
import "ghc" HscTypes ( runHsc )
|
||||
import "ghc" Module
|
||||
( DefUnitId( DefUnitId )
|
||||
, Module( Module )
|
||||
, UnitId( DefiniteUnitId )
|
||||
, mkModuleName
|
||||
, moduleNameString
|
||||
, moduleName
|
||||
, moduleStableString
|
||||
, stringToInstalledUnitId
|
||||
)
|
||||
import "ghc" OccName ( mkOccName, varName )
|
||||
import "ghc" Outputable ( showSDoc )
|
||||
|
||||
import "ghc-paths" GHC.Paths ( libdir )
|
||||
|
||||
import "tasty" Test.Tasty ( TestTree, defaultMain, testGroup )
|
||||
|
||||
import "tasty-hunit" Test.Tasty.HUnit ( testCase )
|
||||
|
||||
import "transformers" Control.Monad.Trans.State.Strict ( execState )
|
||||
|
||||
import "weeder" Weeder
|
||||
( allDeclarations
|
||||
, Declaration( Declaration, declModule, declOccName )
|
||||
, analyseHieFile
|
||||
, declarationStableName
|
||||
, emptyAnalysis
|
||||
, implicitRoots
|
||||
, reachable
|
||||
)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
discoverTests >>= defaultMain . testGroup "Tests"
|
||||
|
||||
|
||||
discoverTests :: IO [ TestTree ]
|
||||
discoverTests =
|
||||
fmap ( map fileToTestCase ) ( getTestCasesIn "tests/test-cases" )
|
||||
|
||||
|
||||
fileToTestCase :: FilePath -> TestTree
|
||||
fileToTestCase sourceFilePath =
|
||||
testCase ( takeBaseName sourceFilePath )
|
||||
$ runGhc ( Just libdir ) do
|
||||
dynFlags <-
|
||||
getSessionDynFlags
|
||||
|
||||
setSessionDynFlags dynFlags
|
||||
|
||||
addTarget
|
||||
Target
|
||||
{ targetId = TargetFile sourceFilePath Nothing
|
||||
, targetAllowObjCode = False
|
||||
, targetContents = Nothing
|
||||
}
|
||||
|
||||
load LoadAllTargets
|
||||
|
||||
let
|
||||
testModuleName =
|
||||
mkModuleName "Test"
|
||||
|
||||
modSummary <-
|
||||
getModSummary testModuleName
|
||||
|
||||
parseModule modSummary
|
||||
>>= typecheckModule
|
||||
>>= \case
|
||||
TypecheckedModule{ tm_renamed_source = Just renamedSource, tm_internals_ = ( tcGblEnv, _ ) } -> do
|
||||
hscEnv <-
|
||||
getSession
|
||||
|
||||
hieFile <-
|
||||
liftIO ( runHsc hscEnv ( mkHieFile modSummary tcGblEnv renamedSource ) )
|
||||
|
||||
let
|
||||
analysis =
|
||||
execState ( analyseHieFile False hieFile ) emptyAnalysis
|
||||
|
||||
testModule =
|
||||
Module
|
||||
( DefiniteUnitId ( DefUnitId ( stringToInstalledUnitId "main" ) ) )
|
||||
testModuleName
|
||||
|
||||
reachableSet =
|
||||
reachable
|
||||
analysis
|
||||
( Set.singleton
|
||||
Declaration
|
||||
{ declModule =
|
||||
testModule
|
||||
, declOccName =
|
||||
mkOccName varName "root"
|
||||
}
|
||||
)
|
||||
|
||||
dead =
|
||||
Set.filter
|
||||
( \d -> declModule d == testModule )
|
||||
( allDeclarations analysis Set.\\ reachableSet )
|
||||
|
||||
unless
|
||||
( Set.null dead )
|
||||
( for_ dead \d ->
|
||||
liftIO ( fail ( declarationStableName d <> " is dead, but should be alive" ) )
|
||||
)
|
||||
|
||||
-- | Recursively search for .hie files in given directory
|
||||
getTestCasesIn :: FilePath -> IO [FilePath]
|
||||
getTestCasesIn path = do
|
||||
exists <-
|
||||
doesPathExist path
|
||||
|
||||
if exists
|
||||
then do
|
||||
isFile <-
|
||||
doesFileExist path
|
||||
|
||||
if isFile && "hs" `isExtensionOf` path
|
||||
then do
|
||||
path' <-
|
||||
canonicalizePath path
|
||||
|
||||
return [ path' ]
|
||||
|
||||
else do
|
||||
isDir <-
|
||||
doesDirectoryExist path
|
||||
|
||||
if isDir
|
||||
then do
|
||||
cnts <-
|
||||
listDirectory path
|
||||
|
||||
withCurrentDirectory path ( foldMap getTestCasesIn cnts )
|
||||
|
||||
else
|
||||
return []
|
||||
|
||||
else
|
||||
return []
|
@ -1,15 +0,0 @@
|
||||
{-# language DefaultSignatures #-}
|
||||
|
||||
module Test () where
|
||||
|
||||
alive :: String
|
||||
alive = "Alive"
|
||||
|
||||
class C a where
|
||||
cmethod :: a -> String
|
||||
default cmethod :: a -> String
|
||||
cmethod _ = alive
|
||||
|
||||
data T
|
||||
|
||||
instance C T
|
@ -1,9 +0,0 @@
|
||||
module Test () where
|
||||
|
||||
alive :: String
|
||||
alive = "Alive"
|
||||
|
||||
data T = T
|
||||
|
||||
instance Show T where
|
||||
show T = alive
|
@ -1,16 +0,0 @@
|
||||
{-# language DefaultSignatures #-}
|
||||
|
||||
module Test ( foo ) where
|
||||
|
||||
{-# noinline foo #-}
|
||||
foo :: Bool -> Int
|
||||
foo _ = 42
|
||||
|
||||
bar :: Int
|
||||
bar = 42
|
||||
|
||||
{-# RULES
|
||||
|
||||
"test rule" foo True = bar
|
||||
|
||||
#-}
|
@ -1,6 +0,0 @@
|
||||
module Test ( root ) where
|
||||
|
||||
data T
|
||||
|
||||
root :: T -> ()
|
||||
root _ = ()
|
Loading…
Reference in New Issue
Block a user