|
1 | 1 | {-# LANGUAGE CPP #-} |
2 | 2 | {-# LANGUAGE OverloadedStrings #-} |
| 3 | +{-# LANGUAGE CPP #-} |
3 | 4 | module Main |
4 | 5 | ( main |
5 | 6 | ) where |
6 | 7 |
|
7 | 8 | import qualified Ide.Plugin.CabalFmt as CabalFmt |
| 9 | +import System.Directory (findExecutable) |
8 | 10 | import System.FilePath |
9 | 11 | import Test.Hls |
10 | 12 |
|
| 13 | +data CabalFmtFound = Found | NotFound |
| 14 | + |
| 15 | +isTestIsolated :: Bool |
| 16 | +#if isolateTests |
| 17 | +isTestIsolated = True |
| 18 | +#else |
| 19 | +isTestIsolated = False |
| 20 | +#endif |
| 21 | + |
| 22 | +isCabalFmtFound :: IO CabalFmtFound |
| 23 | +isCabalFmtFound = case isTestIsolated of |
| 24 | + True -> pure Found |
| 25 | + False-> do |
| 26 | + cabalFmt <- findExecutable "cabal-fmt" |
| 27 | + pure $ maybe NotFound (const Found) cabalFmt |
| 28 | + |
11 | 29 | main :: IO () |
12 | | -main = defaultTestRunner tests |
| 30 | +main = do |
| 31 | + foundCabalFmt <- isCabalFmtFound |
| 32 | + defaultTestRunner (tests foundCabalFmt) |
13 | 33 |
|
14 | 34 | cabalFmtPlugin :: PluginDescriptor IdeState |
15 | 35 | cabalFmtPlugin = CabalFmt.descriptor mempty "cabal-fmt" |
16 | 36 |
|
17 | | -tests :: TestTree |
18 | | -tests = testGroup "cabal-fmt" |
19 | | - [ cabalFmtGolden "formats a simple document" "simple_testdata" "formatted_document" $ \doc -> do |
| 37 | +tests :: CabalFmtFound -> TestTree |
| 38 | +tests found = testGroup "cabal-fmt" |
| 39 | + [ cabalFmtGolden found "formats a simple document" "simple_testdata" "formatted_document" $ \doc -> do |
20 | 40 | formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) |
21 | 41 |
|
22 | | - , cabalFmtGolden "formats a document with expand:src comment" "commented_testdata" "formatted_document" $ \doc -> do |
| 42 | + , cabalFmtGolden found "formats a document with expand:src comment" "commented_testdata" "formatted_document" $ \doc -> do |
23 | 43 | formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) |
24 | 44 |
|
25 | | - , cabalFmtGolden "formats a document with lib information" "lib_testdata" "formatted_document" $ \doc -> do |
| 45 | + , cabalFmtGolden found "formats a document with lib information" "lib_testdata" "formatted_document" $ \doc -> do |
26 | 46 | formatDoc doc (FormattingOptions 10 True Nothing Nothing Nothing) |
27 | 47 | ] |
28 | 48 |
|
29 | | -cabalFmtGolden :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree |
30 | | -cabalFmtGolden title path desc = goldenWithCabalDocFormatter cabalFmtPlugin "cabal-fmt" conf title testDataDir path desc "cabal" |
| 49 | +cabalFmtGolden :: CabalFmtFound -> TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree |
| 50 | +cabalFmtGolden NotFound title _ _ _ = |
| 51 | + testCase title $ |
| 52 | + assertFailure $ "Couldn't find cabal-fmt on PATH or this is not an isolated run. " |
| 53 | + <> "Use cabal flag 'isolateTests' to make it isolated or install cabal-fmt locally." |
| 54 | +cabalFmtGolden Found title path desc act = goldenWithCabalDocFormatter cabalFmtPlugin "cabal-fmt" conf title testDataDir path desc "cabal" act |
31 | 55 | where |
32 | 56 | conf = def |
33 | 57 |
|
|
0 commit comments