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