Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cabal.project.dev
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ package *
documentation: True
library-for-ghci: True

package bitvec
library-for-ghci: False

package jbeam-edit
tests: True
haddock-executables: True
Expand Down
52 changes: 25 additions & 27 deletions hie.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
cradle:
multi:
- path: ./examples/ast
config:
cradle:
none:
- path: ./
config:
cradle:
cabal:
cabalProject: ./cabal.project.dev
components:
- path: ./src
component: lib:jbeam-edit
- path: ./src-extra/transformation
component: jbeam-edit:lib:jbeam-edit-transformation
- path: ./src-extra/language-server
component: jbeam-edit:lib:jbeam-language-server
- path: ./exe/jbeam-edit
component: exe:jbeam-edit
- path: ./exe/jbeam-lsp-server
component: jbeam-edit:exe:jbeam-lsp-server
- path: ./tools/lsp-test-server
component: jbeam-edit:exe:jbeam-lsp-test-server
- path: ./tools/dump_ast
component: exe:jbeam-edit-dump-ast
- path: ./test
component: test:jbeam-edit-test
cabal:
cabalProject: ./cabal.project.dev
components:
- path: ./src
component: lib:jbeam-edit
- path: ./src-extra/transformation
component: jbeam-edit:lib:jbeam-edit-transformation
- path: ./src-extra/language-server
component: jbeam-edit:lib:jbeam-language-server
- path: ./exe/jbeam-edit/Main.hs
component: jbeam-edit:exe:jbeam-edit
- path: ./exe/jbeam-edit/CommandLineOptions.hs
component: jbeam-edit:exe:jbeam-edit
- path: ./tools/dump_ast/Main.hs
component: jbeam-edit:exe:jbeam-edit-dump-ast
- path: ./exe/jbeam-lsp-server/Main.hs
component: jbeam-edit:exe:jbeam-lsp-server
- path: ./tools/lsp-test-server/Main.hs
component: jbeam-edit:exe:jbeam-lsp-test-server
- path: ./test
component: jbeam-edit:test:jbeam-edit-test
- path: ./test-extra/transformation
component: jbeam-edit:test:jbeam-edit-transformation-test
- path: ./test-extra/language-server
component: jbeam-edit:test:jbeam-language-server-test
33 changes: 31 additions & 2 deletions jbeam-edit.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ test-suite jbeam-edit-test
Parsing.DSLSpec
Parsing.JbeamSpec
SpecHelper
TransformationSpec
Paths_jbeam_edit

autogen-modules: Paths_jbeam_edit
Expand Down Expand Up @@ -373,10 +372,40 @@ test-suite jbeam-edit-test
if True
build-depends: hspec-megaparsec >=2.2

test-suite jbeam-edit-transformation-test
type: exitcode-stdio-1.0
main-is: Main.hs
hs-source-dirs: test-extra/transformation
other-modules: Paths_jbeam_edit
autogen-modules: Paths_jbeam_edit
default-language: GHC2021
default-extensions: OverloadedStrings ImportQualifiedPost
ghc-options:
-Wall -Wcompat -Widentities -Wincomplete-record-updates
-Wincomplete-uni-patterns -Wmissing-export-lists
-Wmissing-home-modules -Wpartial-fields -Wredundant-constraints
-threaded -rtsopts -with-rtsopts=-N

build-depends:
base >=4.17 && <5,
bytestring >=0.12,
containers >=0.6,
directory >=1.3,
filepath >=1.4,
hspec >=2.11,
jbeam-edit,
megaparsec >=9.6,
mtl >=2.3,
scientific >=0.3,
text >=2.1,
vector >=0.13

if flag(transformation)
cpp-options: -DENABLE_TRANSFORMATION_TESTS
build-depends: jbeam-edit-transformation

else
buildable: False

test-suite jbeam-language-server-test
type: exitcode-stdio-1.0
main-is: Spec.hs
Expand Down
14 changes: 11 additions & 3 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ tests:
when:
- condition: true
dependencies: [hspec-megaparsec>=2.2]
- condition: flag(transformation)
dependencies: [jbeam-edit-transformation]
cpp-options: -DENABLE_TRANSFORMATION_TESTS
jbeam-language-server-test:
<<: *jbeam-test-common
source-dirs: test-extra/language-server
Expand All @@ -174,3 +171,14 @@ tests:
dependencies: [jbeam-language-server, lsp-test, lsp>=2.7]
else:
buildable: false
jbeam-edit-transformation-test:
<<: *jbeam-test-common
main: Main.hs
build-tools: []
source-dirs: test-extra/transformation
when:
- condition: flag(transformation)
then:
dependencies: [jbeam-edit-transformation]
else:
buildable: false
4 changes: 4 additions & 0 deletions test-extra/transformation/.dir-locals.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
((haskell-mode
. ((haskell-process-type . cabal-repl)
(eval . (setq-local haskell-process-args-cabal-repl
(append '("jbeam-edit:test:jbeam-edit-transformation-test" "--project-file" "cabal.project.dev") haskell-process-args-cabal-repl))))))
55 changes: 55 additions & 0 deletions test-extra/transformation/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module Main (
main,
) where

import Config
import Data.List (isPrefixOf, isSuffixOf)
import Data.Map qualified as M
import Data.Text qualified as T
import Formatting
import System.Directory (getDirectoryContents)
import Test.Hspec
import Transformation

listFilesInDir
:: FilePath
-> IO [String]
listFilesInDir dir =
filter (\f -> isSuffixOf ".hs" f && not (".#" `isPrefixOf` f))
<$> getDirectoryContents dir

topNodeSpec
:: RuleSet -> String -> TransformationConfig -> FilePath -> FilePath -> Spec
topNodeSpec rs cfName tfConfig inFilename outFilename = do
let inputPath = "examples/ast/jbeam/" ++ inFilename
input <- runIO $ readFile inputPath
output <- runIO $ readFile outFilename
let desc =
"with "
++ cfName
++ ": should transform AST in "
++ inFilename
++ " to Jbeam in "
++ outFilename
transformAndFormat =
do
(_, _, node) <- transform M.empty tfConfig (read input)
Right (formatNode rs node)
describe desc . it "works" $ transformAndFormat `shouldBe` Right (T.pack output)

main :: IO ()
main = hspec $ do
let exampleConfigPath = "examples/jbeam-edit.yaml"
rs <- runIO $ readFile "examples/ast/jbfl/minimal.hs"
tfConfig <- runIO $ loadTransformationConfig exampleConfigPath
inputFiles <-
runIO $ listFilesInDir "examples/ast/jbeam"
let outputFile cfName inFile =
"examples/transformed_jbeam/"
++ takeWhile (/= '.') inFile
++ "-"
++ cfName
++ ".jbeam"
testInputFile cfName tfConfig' inFile = topNodeSpec (read rs) cfName tfConfig' inFile (outputFile cfName inFile)
mapM_ (testInputFile "cfg-default" newTransformationConfig) inputFiles
mapM_ (testInputFile "cfg-example" tfConfig) inputFiles
42 changes: 0 additions & 42 deletions test/TransformationSpec.hs

This file was deleted.