-
Notifications
You must be signed in to change notification settings - Fork 459
Use tasty-golden for golden tests and ditch vendored hspec-expectations package. #125
Changes from all commits
2754e26
99c4bb2
6a24b9c
0292506
acbacbe
3363ecc
11442cf
14bbf68
b8cb9d1
6a15695
7d88f93
2e84c63
2795bc7
a465212
d50c081
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -274,7 +274,7 @@ library | |
| autogen-modules: Paths_semantic | ||
| other-modules: Paths_semantic | ||
| build-depends: base >= 4.12 && < 5 | ||
| , ansi-terminal ^>= 0.8.2 | ||
| , ansi-terminal >= 0.8.2 && <1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pourquoi?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not technically needed, but ansi-terminal just hit 0.9.0, and the old
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha. |
||
| , array ^>= 0.5.3.0 | ||
| , attoparsec ^>= 0.13.2.2 | ||
| , cmark-gfm == 0.1.8 | ||
|
|
@@ -340,6 +340,7 @@ test-suite test | |
| import: haskell, dependencies, executable-flags | ||
| type: exitcode-stdio-1.0 | ||
| hs-source-dirs: test | ||
| ghc-options: -Wunused-imports | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we apply this in a common stanza?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup. We should really just turn on -Wall everywhere, but I’ll file a separate issue about that.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dig it; the thing |
||
| main-is: Spec.hs | ||
| other-modules: Analysis.Go.Spec | ||
| , Analysis.PHP.Spec | ||
|
|
@@ -381,13 +382,16 @@ test-suite test | |
| , Test.Hspec.LeanCheck | ||
| build-depends: semantic | ||
| , tree-sitter-json | ||
| , Glob | ||
| , Glob ^>= 0.10.0 | ||
| , hspec >= 2.6 && <3 | ||
| , hspec-core >= 2.6 && <3 | ||
| , hspec-expectations-pretty-diff ^>= 0.7.2.5 | ||
| , hspec-expectations ^>= 0.8.2 | ||
| , tasty ^>= 1.2.3 | ||
| , tasty-golden ^>= 2.3.2 | ||
| , tasty-hspec ^>= 1.1.5.1 | ||
| , HUnit ^>= 1.6.0.0 | ||
| , leancheck >= 0.8 && <1 | ||
| , temporary | ||
| , temporary ^>= 1.3 | ||
| if flag(release) | ||
| ghc-options: -dynamic | ||
|
|
||
|
|
@@ -398,9 +402,9 @@ test-suite parse-examples | |
| main-is: Examples.hs | ||
| build-depends: semantic | ||
| , Glob | ||
| , hspec >= 2.4.1 | ||
| , hspec | ||
| , hspec-core | ||
| , hspec-expectations-pretty-diff | ||
| , hspec-expectations | ||
|
|
||
| benchmark evaluation | ||
| import: haskell, executable-flags | ||
|
|
@@ -409,7 +413,7 @@ benchmark evaluation | |
| main-is: Main.hs | ||
| ghc-options: -static | ||
| build-depends: base | ||
| , criterion | ||
| , criterion ^>= 1.5 | ||
| , semantic | ||
|
|
||
| source-repository head | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,52 @@ | ||
| {-# LANGUAGE ImplicitParams, LambdaCase, NamedFieldPuns #-} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Countdown to Rob requesting
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I do think implicit params are a better solution than plumbing parameters everywhere or
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. u wot m8 The purist in me would prefer a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I kid, I kid. I’m cool with this 👍) |
||
| module Integration.Spec (spec) where | ||
|
|
||
| import Control.Exception (throw) | ||
| import Data.Foldable (find, traverse_, for_) | ||
| import Data.Foldable (find) | ||
| import Data.List (union, concat, transpose) | ||
| import qualified Data.ByteString as B | ||
| import qualified Data.ByteString.Lazy as BL | ||
| import System.FilePath.Glob | ||
| import System.FilePath.Posix | ||
| import System.IO.Unsafe | ||
|
|
||
| import SpecHelpers | ||
|
|
||
| import Test.Tasty | ||
| import Test.Tasty.Golden | ||
|
|
||
| languages :: [FilePath] | ||
| languages = ["go", "javascript", "json", "python", "ruby", "typescript", "tsx"] | ||
|
|
||
| spec :: TaskSession -> Spec | ||
| spec config = parallel $ do | ||
| for_ languages $ \language -> do | ||
| let dir = "test/fixtures" </> language </> "corpus" | ||
| it (language <> " corpus exists") $ examples dir `shouldNotReturn` [] | ||
| describe (language <> " corpus") $ runTestsIn dir [] | ||
| spec :: TaskSession -> TestTree | ||
| spec config = let ?session = config in testGroup "Integration (golden tests)" $ fmap testsForLanguage languages | ||
|
|
||
| where | ||
| runTestsIn :: FilePath -> [(FilePath, String)] -> SpecWith () | ||
| runTestsIn directory pending = do | ||
| examples <- runIO $ examples directory | ||
| traverse_ (runTest pending) examples | ||
| runTest pending ParseExample{..} = it ("parses " <> file) $ maybe (testParse config file parseOutput) pendingWith (lookup parseOutput pending) | ||
| runTest pending DiffExample{..} = it ("diffs " <> diffOutput) $ maybe (testDiff config (Both fileA fileB) diffOutput) pendingWith (lookup diffOutput pending) | ||
| testsForLanguage :: (?session :: TaskSession) => FilePath -> TestTree | ||
| testsForLanguage language = do | ||
| let dir = "test/fixtures" </> language </> "corpus" | ||
| let items = unsafePerformIO (examples dir) | ||
| localOption (mkTimeout 3000000) $ testGroup language $ fmap testForExample items | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests sometimes get held up; I’m not sure why (I think it’s a race condition w/r/t file I/O), but this timeout remedies it so the builders won’t get stuck for 10 minutes before it happens. (Worth filing a bug about, I think.) |
||
| {-# NOINLINE testsForLanguage #-} | ||
|
|
||
| data Example = DiffExample { fileA :: FilePath, fileB :: FilePath, diffOutput :: FilePath } | ||
| | ParseExample { file :: FilePath, parseOutput :: FilePath } | ||
| deriving (Eq, Show) | ||
|
|
||
| testForExample :: (?session :: TaskSession) => Example -> TestTree | ||
| testForExample = \case | ||
| DiffExample{fileA, fileB, diffOutput} -> | ||
| goldenVsStringDiff | ||
| ("diffs " <> diffOutput) | ||
| (\ref new -> ["git", "diff", ref, new]) | ||
| diffOutput | ||
| (BL.fromStrict <$> diffFilePaths ?session (Both fileA fileB)) | ||
| ParseExample{file, parseOutput} -> | ||
| goldenVsStringDiff | ||
| ("parses " <> parseOutput) | ||
| (\ref new -> ["git", "diff", ref, new]) | ||
| parseOutput | ||
| (parseFilePath ?session file >>= either throw (pure . BL.fromStrict)) | ||
|
|
||
|
|
||
| -- | Return all the examples from the given directory. Examples are expected to | ||
| -- | have the form: | ||
| -- | | ||
|
|
@@ -81,18 +97,3 @@ examples directory = do | |
| -- | Given a test name like "foo.A.js", return "foo". | ||
| normalizeName :: FilePath -> FilePath | ||
| normalizeName path = dropExtension $ dropExtension path | ||
|
|
||
| testParse :: TaskSession -> FilePath -> FilePath -> Expectation | ||
| testParse session path expectedOutput = do | ||
| actual <- fmap verbatim <$> parseFilePath session path | ||
| case actual of | ||
| Left err -> throw err | ||
| Right actual -> do | ||
| expected <- verbatim <$> B.readFile expectedOutput | ||
| actual `shouldBe` expected | ||
|
|
||
| testDiff :: TaskSession -> Both FilePath -> FilePath -> Expectation | ||
| testDiff config paths expectedOutput = do | ||
| actual <- verbatim <$> diffFilePaths config paths | ||
| expected <- verbatim <$> B.readFile expectedOutput | ||
| actual `shouldBe` expected | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Down to only two vendored packages left (the hard ones, unfortunately).