Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 99c4bb2

Browse files
author
Patrick Thomson
committed
Overhaul test harnesses and add tasty bounds.
1 parent 2754e26 commit 99c4bb2

File tree

7 files changed

+80
-50
lines changed

7 files changed

+80
-50
lines changed

cabal.project

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,3 @@ source-repository-package
1414
type: git
1515
location: https://github.com/joshvera/proto3-wire.git
1616
tag: 84664e22f01beb67870368f1f88ada5d0ad01f56
17-
18-
source-repository-package
19-
type: git
20-
location: https://github.com/rewinfrey/hspec-expectations-pretty-diff
21-
tag: 94af5871c24ba319f7f72fefa53c1a4d074c9a29

semantic.cabal

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ library
274274
autogen-modules: Paths_semantic
275275
other-modules: Paths_semantic
276276
build-depends: base >= 4.12 && < 5
277-
, ansi-terminal ^>= 0.8.2
277+
, ansi-terminal >= 0.8.2 && <1
278278
, array ^>= 0.5.3.0
279279
, attoparsec ^>= 0.13.2.2
280280
, cmark-gfm == 0.1.8
@@ -384,7 +384,10 @@ test-suite test
384384
, Glob
385385
, hspec >= 2.6 && <3
386386
, hspec-core >= 2.6 && <3
387-
, hspec-expectations-pretty-diff ^>= 0.7.2.5
387+
, hspec-expectations ^>= 0.8.2
388+
, tasty ^>= 1.2.3
389+
, tasty-golden ^>= 2.3.2
390+
, tasty-hspec ^>= 1.1.5.1
388391
, HUnit ^>= 1.6.0.0
389392
, leancheck >= 0.8 && <1
390393
, temporary
@@ -400,7 +403,7 @@ test-suite parse-examples
400403
, Glob
401404
, hspec >= 2.4.1
402405
, hspec-core
403-
, hspec-expectations-pretty-diff
406+
, hspec-expectations
404407

405408
benchmark evaluation
406409
import: haskell, executable-flags

test/Data/Term/Spec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Data.Term.Spec (spec) where
44
import Data.Functor.Listable
55
import Data.Term
66
import Test.Hspec (Spec, describe, parallel)
7-
import Test.Hspec.Expectations.Pretty
7+
import Test.Hspec.Expectations
88
import Test.Hspec.LeanCheck
99

1010
spec :: Spec

test/Diffing/Interpreter/Spec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Data.These
1515
import Diffing.Interpreter
1616
import qualified Data.Syntax as Syntax
1717
import Test.Hspec (Spec, describe, it, parallel)
18-
import Test.Hspec.Expectations.Pretty
18+
import Test.Hspec.Expectations
1919
import Test.Hspec.LeanCheck
2020
import Test.LeanCheck.Core
2121
import SpecHelpers ()

test/Integration/Spec.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import SpecHelpers
1414

1515
import Test.Tasty
1616
import Test.Tasty.Golden
17-
import Test.Tasty.HUnit
1817

1918
languages :: [FilePath]
2019
languages = ["go", "javascript", "json", "python", "ruby", "typescript", "tsx"]
@@ -27,6 +26,7 @@ testsForLanguage language = do
2726
let dir = "test/fixtures" </> language </> "corpus"
2827
let items = unsafePerformIO (examples dir)
2928
testGroup language (fmap testForExample items)
29+
{-# NOINLINE testsForLanguage #-}
3030

3131
data Example = DiffExample { fileA :: FilePath, fileB :: FilePath, diffOutput :: FilePath }
3232
| ParseExample { file :: FilePath, parseOutput :: FilePath }
@@ -40,7 +40,12 @@ testForExample = \case
4040
(\ref new -> ["git", "diff", ref, new])
4141
diffOutput
4242
(BL.fromStrict <$> diffFilePaths ?session (Both fileA fileB))
43-
ParseExample{file, parseOutput} -> testCase ("parses " <> file) (pure ())
43+
ParseExample{file, parseOutput} ->
44+
goldenVsStringDiff
45+
("parses " <> parseOutput)
46+
(\ref new -> ["git", "diff", ref, new])
47+
parseOutput
48+
(parseFilePath ?session file >>= either throw (pure . BL.fromStrict))
4449

4550

4651
-- | Return all the examples from the given directory. Examples are expected to

test/Spec.hs

Lines changed: 64 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,43 +37,70 @@ import qualified Semantic.Stat.Spec
3737
import Semantic.Config (defaultOptions, optionsLogLevel)
3838
import Semantic.Task (withOptions, TaskSession(..))
3939
import Test.Hspec
40+
import Test.Tasty as Tasty
41+
import Test.Tasty.Hspec as Tasty
42+
import Test.Tasty.Options as Tasty
43+
44+
tests :: TaskSession -> [TestTree]
45+
tests session =
46+
[ Integration.Spec.spec session
47+
]
48+
49+
-- We can't bring this out of the IO monad until we divest
50+
-- from hspec, since testSpec operates in IO.
51+
allTests :: TaskSession -> IO TestTree
52+
allTests session = do
53+
let nativeSpecs = tests session
54+
asTastySpecs <- Tasty.testSpecs $ legacySpecs session
55+
let allSpecs = nativeSpecs <> asTastySpecs
56+
pure . Tasty.localOption Tasty.Success $ testGroup "semantic" allSpecs
57+
58+
-- If you're writing new test modules, please don't add to this
59+
-- stanza: it is only there to prevent massive rewrites, and is
60+
-- converted into a Tasty TestTree in 'main'. (Quoth the tasty-hspec
61+
-- documentation: "hspec and tasty serve similar purposes; consider
62+
-- using one or the other.") Instead,
63+
legacySpecs :: TaskSession -> Spec
64+
legacySpecs args = do
65+
describe "Semantic.Stat" Semantic.Stat.Spec.spec
66+
parallel $ do
67+
describe "Analysis.Go" (Analysis.Go.Spec.spec args)
68+
describe "Analysis.PHP" (Analysis.PHP.Spec.spec args)
69+
describe "Analysis.Python" (Analysis.Python.Spec.spec args)
70+
describe "Analysis.Ruby" (Analysis.Ruby.Spec.spec args)
71+
describe "Analysis.TypeScript" (Analysis.TypeScript.Spec.spec args)
72+
describe "Assigning.Assignment" Assigning.Assignment.Spec.spec
73+
describe "Control.Abstract.Evaluator" Control.Abstract.Evaluator.Spec.spec
74+
describe "Data.Diff" Data.Diff.Spec.spec
75+
describe "Data.Graph" Data.Graph.Spec.spec
76+
describe "Data.Abstract.Path" Data.Abstract.Path.Spec.spec
77+
describe "Data.Abstract.Name" Data.Abstract.Name.Spec.spec
78+
describe "Data.Functor.Classes.Generic" Data.Functor.Classes.Generic.Spec.spec
79+
describe "Data.Range" Data.Range.Spec.spec
80+
describe "Data.Scientific" Data.Scientific.Spec.spec
81+
describe "Data.Semigroup.App" Data.Semigroup.App.Spec.spec
82+
describe "Data.Source" Data.Source.Spec.spec
83+
describe "Data.Term" Data.Term.Spec.spec
84+
describe "Diffing.Algorithm.RWS" Diffing.Algorithm.RWS.Spec.spec
85+
describe "Diffing.Algorithm.SES" Diffing.Algorithm.SES.Spec.spec
86+
describe "Diffing.Interpreter" Diffing.Interpreter.Spec.spec
87+
describe "Graphing.Calls" Graphing.Calls.Spec.spec
88+
describe "Numeric" Numeric.Spec.spec
89+
describe "Rendering.TOC" Rendering.TOC.Spec.spec
90+
describe "Reprinting.Spec" Reprinting.Spec.spec
91+
describe "Rewriting.Go" Rewriting.Go.Spec.spec
92+
describe "Rewriting.JSON" Rewriting.JSON.Spec.spec
93+
describe "Rewriting.Python" Rewriting.Python.Spec.spec
94+
describe "Tags.Spec" Tags.Spec.spec
95+
describe "Semantic" Semantic.Spec.spec
96+
describe "Semantic.CLI" Semantic.CLI.Spec.spec
97+
describe "Semantic.IO" Semantic.IO.Spec.spec
98+
describe "Parsing" Parsing.Spec.spec
99+
40100

41101
main :: IO ()
42102
main = do
43-
withOptions defaultOptions { optionsLogLevel = Nothing } $ \ config logger statter -> hspec $ do
44-
let args = TaskSession config "-" False logger statter
45-
describe "Semantic.Stat" Semantic.Stat.Spec.spec
46-
parallel $ do
47-
describe "Analysis.Go" (Analysis.Go.Spec.spec args)
48-
describe "Analysis.PHP" (Analysis.PHP.Spec.spec args)
49-
describe "Analysis.Python" (Analysis.Python.Spec.spec args)
50-
describe "Analysis.Ruby" (Analysis.Ruby.Spec.spec args)
51-
describe "Analysis.TypeScript" (Analysis.TypeScript.Spec.spec args)
52-
describe "Assigning.Assignment" Assigning.Assignment.Spec.spec
53-
describe "Control.Abstract.Evaluator" Control.Abstract.Evaluator.Spec.spec
54-
describe "Data.Diff" Data.Diff.Spec.spec
55-
describe "Data.Graph" Data.Graph.Spec.spec
56-
describe "Data.Abstract.Path" Data.Abstract.Path.Spec.spec
57-
describe "Data.Abstract.Name" Data.Abstract.Name.Spec.spec
58-
describe "Data.Functor.Classes.Generic" Data.Functor.Classes.Generic.Spec.spec
59-
describe "Data.Range" Data.Range.Spec.spec
60-
describe "Data.Scientific" Data.Scientific.Spec.spec
61-
describe "Data.Semigroup.App" Data.Semigroup.App.Spec.spec
62-
describe "Data.Source" Data.Source.Spec.spec
63-
describe "Data.Term" Data.Term.Spec.spec
64-
describe "Diffing.Algorithm.RWS" Diffing.Algorithm.RWS.Spec.spec
65-
describe "Diffing.Algorithm.SES" Diffing.Algorithm.SES.Spec.spec
66-
describe "Diffing.Interpreter" Diffing.Interpreter.Spec.spec
67-
describe "Graphing.Calls" Graphing.Calls.Spec.spec
68-
describe "Numeric" Numeric.Spec.spec
69-
describe "Rendering.TOC" Rendering.TOC.Spec.spec
70-
describe "Reprinting.Spec" Reprinting.Spec.spec
71-
describe "Rewriting.Go" Rewriting.Go.Spec.spec
72-
describe "Rewriting.JSON" Rewriting.JSON.Spec.spec
73-
describe "Rewriting.Python" Rewriting.Python.Spec.spec
74-
describe "Tags.Spec" Tags.Spec.spec
75-
describe "Semantic" Semantic.Spec.spec
76-
describe "Semantic.CLI" Semantic.CLI.Spec.spec
77-
describe "Semantic.IO" Semantic.IO.Spec.spec
78-
describe "Integration" (Integration.Spec.spec args)
79-
describe "Parsing" Parsing.Spec.spec
103+
withOptions defaultOptions { optionsLogLevel = Nothing } $ \ config logger statter ->
104+
let session = TaskSession config "-" False logger statter
105+
in allTests session >>= defaultMain
106+

test/SpecHelpers.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import Data.Semigroup as X (Semigroup(..))
7171
import Control.Monad as X
7272

7373
import Test.Hspec as X (Spec, SpecWith, context, describe, it, xit, parallel, pendingWith, around, runIO)
74-
import Test.Hspec.Expectations.Pretty as X
74+
import Test.Hspec.Expectations as X
7575
import Test.Hspec.LeanCheck as X
7676
import Test.LeanCheck as X
7777

0 commit comments

Comments
 (0)