content: module HsBindgen.Test.Readme (
      genTestsReadme
    ) where
  
  import Data.Text qualified as Text
  import System.FilePath qualified as FilePath
  
  import HsBindgen.Language.Haskell qualified as Hs
  
  {-------------------------------------------------------------------------------
    Generation
  -------------------------------------------------------------------------------}
  
  genTestsReadme ::
       FilePath      -- ^ README path
    -> Hs.ModuleName -- ^ Module name (example: @Acme.Foo@)
    -> FilePath      -- ^ Test suite directory path
    -> FilePath      -- ^ C header path
    -> FilePath      -- ^ C source path
    -> IO ()
  genTestsReadme readmePath moduleName testSuitePath cHeaderPath cSourcePath =
      writeFile readmePath $ unlines
        [ "# " ++ moduleNameStr ++ " hs-bindgen Test Suite"
        , ""
        , "The content under this directory is automatically generated by [hs-bindgen][]."
        , ""
        , "[hs-bindgen]: <https://github.com/well-typed/hs-bindgen>"
        , ""
        , "## Example Cabal Configuration"
        , ""
        , "Be sure to add your project to the dependencies."
        , ""
        , "```"
        , "test-suite " ++ testSuite
        , "  type: exitcode-stdio-1.0"
        , "  hs-source-dirs: " ++ testSuite ++ "/src"
        , "  main-is: Main.hs"
        , "  other-modules:"
        , "      " ++ moduleNameStr ++ ".Test"
        , "      Main"
        , "      Spec"
        , "  include-dirs:"
        , "      " ++ testSuite ++ "/cbits"
        , "  install-includes:"
        , "      " ++ FilePath.takeFileName cHeaderPath
        , "  c-sources:"
        , "      " ++ testSuite ++ "/cbits/" ++ FilePath.takeFileName cSourcePath
        , "  build-depends:"
        , "      base"
        , "    , hs-bindgen-test-runtime"
        , "    , QuickCheck"
        , "    , tasty"
        , "    , tasty-hunit"
        , "    , tasty-quickcheck"
        , "  default-language: Haskell2010"
        , "  ghc-options: -Wall"
        , "```"
        ]
    where
      testSuite :: String
      testSuite = FilePath.takeFileName testSuitePath
  
      moduleNameStr :: String
      moduleNameStr = Text.unpack $ Hs.getModuleName moduleName
  