1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

Add ParseCommandSpec to validate parse output

This commit is contained in:
Timothy Clem 2017-02-28 15:32:04 -08:00
parent 1d9436bb14
commit 4c3feecc77
5 changed files with 46 additions and 5 deletions

View File

@ -151,6 +151,7 @@ test-suite test
, TOCSpec
, IntegrationSpec
, DiffCommandSpec
, ParseCommandSpec
, Test.Hspec.LeanCheck
build-depends: aeson
, array

View File

@ -1,5 +1,5 @@
{-# OPTIONS_GHC -funbox-strict-fields #-}
module Arguments (Arguments(..), CmdLineOptions(..), DiffMode(..), ExtraArg(..), RunMode(..), programArguments, args, args') where
module Arguments (Arguments(..), CmdLineOptions(..), DiffMode(..), ExtraArg(..), RunMode(..), programArguments, args, diffPathsArgs, parseArgs) where
import Data.Functor.Both
import Data.Maybe
@ -96,7 +96,7 @@ programArguments CmdLineOptions{..} = do
-- | Quickly assemble an Arguments data record with defaults.
args :: FilePath -> String -> String -> [String] -> R.Format -> Arguments
args gitDir sha1 sha2 filePaths format = Arguments
{ gitDir = gitDir
{ gitDir = gitDir
, alternateObjectDirs = []
, format = format
, timeoutInMicroseconds = defaultTimeout
@ -108,8 +108,8 @@ args gitDir sha1 sha2 filePaths format = Arguments
, developmentMode = False
}
args' :: FilePath -> Both FilePath -> R.Format -> Arguments
args' gitDir paths format = Arguments
diffPathsArgs :: FilePath -> Both FilePath -> R.Format -> Arguments
diffPathsArgs gitDir paths format = Arguments
{ gitDir = gitDir
, alternateObjectDirs = []
, format = format
@ -122,6 +122,20 @@ args' gitDir paths format = Arguments
, developmentMode = False
}
parseArgs :: [String] -> R.Format -> Arguments
parseArgs filePaths format = Arguments
{ gitDir = ""
, alternateObjectDirs = []
, format = format
, timeoutInMicroseconds = defaultTimeout
, output = Nothing
, diffMode = CommitDiff
, runMode = Parse
, shaRange = both Nothing Nothing
, filePaths = filePaths
, developmentMode = False
}
-- | 7 seconds
defaultTimeout :: Int
defaultTimeout = 7 * 1000000

View File

@ -23,7 +23,7 @@ spec = parallel $ do
context "diff" $ do
prop "all formats should produce output for file paths" $
\format -> do
output <- diff $ args' "" (both "test/fixtures/ruby/and-or.A.rb" "test/fixtures/ruby/and-or.B.rb") format
output <- diff $ diffPathsArgs "" (both "test/fixtures/ruby/and-or.A.rb" "test/fixtures/ruby/and-or.B.rb") format
output `shouldNotBe` ""
prop "all formats should produce output for commit range" $

24
test/ParseCommandSpec.hs Normal file
View File

@ -0,0 +1,24 @@
module ParseCommandSpec where
import Data.Functor.Listable
import Prelude
import Test.Hspec hiding (shouldBe, shouldNotBe, shouldThrow, errorCall)
import Test.Hspec.Expectations.Pretty
import Test.Hspec.LeanCheck
import Test.LeanCheck
import Arguments
import ParseCommand
import Renderer
spec :: Spec
spec = parallel $ do
context "parse" $ do
prop "all valid formats should produce output" . forAll (isParseFormat `filterT` tiers) $
\format -> do
output <- parse $ parseArgs ["test/fixtures/ruby/and-or.A.rb"] format
output `shouldNotBe` ""
isParseFormat :: Format -> Bool
isParseFormat a | JSON <- a = True
| SExpression <- a = True
| otherwise = False

View File

@ -13,6 +13,7 @@ import qualified Source.Spec
import qualified TermSpec
import qualified TOCSpec
import qualified DiffCommandSpec
import qualified ParseCommandSpec
import qualified IntegrationSpec
import Test.Hspec
@ -30,4 +31,5 @@ main = hspec . parallel $ do
describe "Term" TermSpec.spec
describe "TOC" TOCSpec.spec
describe "DiffCommand" DiffCommandSpec.spec
describe "ParseCommand" ParseCommandSpec.spec
describe "Integration" IntegrationSpec.spec