packages feed

cabal-hoogle-0.1.0.0: test/IntegrationTest.hs

module IntegrationTest where

import Data.List (isInfixOf)
import Hoogle.Cabal
import System.Environment (withArgs)
import System.IO.Silently (capture_)
import Test.Tasty
import Test.Tasty.HUnit

test_searchInCommandLine :: IO [TestTree]
test_searchInCommandLine = do
  withArgs ["generate"] main

  let testCase' :: String -> [String] -> String -> TestTree
      testCase' name args wantResult =
        testCase name $ do
          output <- withArgs (["run", "--"] ++ args) (capture_ main)
          wantResult `isInfixOf` output @? "actual output: " <> output

  pure
    [ testCase' "test dependency doesn't work" ["testCase"] "No results found",
      testCase' "core library" ["lift"] "Control.Monad.Trans.Class lift",
      testCase' "non-core library" ["runProcess_"] "System.Process.Typed runProcess_"
    ]