From 828da58f1e2e0dce834f2787ed8f7e0f99af95f7 Mon Sep 17 00:00:00 2001 From: webdevred <148627186+webdevred@users.noreply.github.com> Date: Sun, 26 Oct 2025 19:46:46 +0100 Subject: [PATCH 1/2] Refactor transformation tests into a dedicated test suite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added `jbeam-edit-transformation-test` in the cabal file, separate from other tests. - Removed CPP flags (`ENABLE_TRANSFORMATION_TESTS`) for cleaner conditional compilation. - Moved `TransformationSpec.hs` → `test-extra/transformation/Spec.hs`. - Updated `package.yaml` to use the new test suite and removed old conditional dependencies. - Added `listFilesInDir` helper to dynamically discover `.hs` test files. - Improves test structure, readability, and maintainability. --- jbeam-edit.cabal | 33 +++++++++++++- package.yaml | 14 ++++-- test-extra/transformation/.dir-locals.el | 4 ++ test-extra/transformation/Main.hs | 55 ++++++++++++++++++++++++ test/TransformationSpec.hs | 42 ------------------ 5 files changed, 101 insertions(+), 47 deletions(-) create mode 100644 test-extra/transformation/.dir-locals.el create mode 100644 test-extra/transformation/Main.hs delete mode 100644 test/TransformationSpec.hs diff --git a/jbeam-edit.cabal b/jbeam-edit.cabal index 6b088f18..1f51dfec 100644 --- a/jbeam-edit.cabal +++ b/jbeam-edit.cabal @@ -344,7 +344,6 @@ test-suite jbeam-edit-test Parsing.DSLSpec Parsing.JbeamSpec SpecHelper - TransformationSpec Paths_jbeam_edit autogen-modules: Paths_jbeam_edit @@ -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 diff --git a/package.yaml b/package.yaml index b0307427..1c66723b 100644 --- a/package.yaml +++ b/package.yaml @@ -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 @@ -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 diff --git a/test-extra/transformation/.dir-locals.el b/test-extra/transformation/.dir-locals.el new file mode 100644 index 00000000..ba4b325d --- /dev/null +++ b/test-extra/transformation/.dir-locals.el @@ -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)))))) diff --git a/test-extra/transformation/Main.hs b/test-extra/transformation/Main.hs new file mode 100644 index 00000000..a3134a04 --- /dev/null +++ b/test-extra/transformation/Main.hs @@ -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 diff --git a/test/TransformationSpec.hs b/test/TransformationSpec.hs deleted file mode 100644 index 3faff8a2..00000000 --- a/test/TransformationSpec.hs +++ /dev/null @@ -1,42 +0,0 @@ -{-# LANGUAGE CPP #-} - -module TransformationSpec ( - spec, -) where - -import SpecHelper - -#ifdef ENABLE_TRANSFORMATION_TESTS -import Transformation -import Formatting -import Config -import Data.Map qualified as M -import Data.Text qualified as T - -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 . works $ transformAndFormat `shouldBe` Right (T.pack output) - -spec :: Spec -spec = 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 -#else -spec :: Spec -spec = pure () -#endif From b542ca9398d8ca66b1d91d4adab063d08a3eed1c Mon Sep 17 00:00:00 2001 From: webdevred <148627186+webdevred@users.noreply.github.com> Date: Mon, 27 Oct 2025 17:38:31 +0100 Subject: [PATCH 2/2] Cabal and hls fixes --- cabal.project.dev | 3 +++ hie.yaml | 52 +++++++++++++++++++++++------------------------ 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/cabal.project.dev b/cabal.project.dev index 3a6cba13..eadd925b 100644 --- a/cabal.project.dev +++ b/cabal.project.dev @@ -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 diff --git a/hie.yaml b/hie.yaml index 233aeaa5..69e2e698 100644 --- a/hie.yaml +++ b/hie.yaml @@ -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