diff --git a/.travis.yml b/.travis.yml index 0e5fcbe..2c651c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,4 @@ script: - stylish-haskell-lhs -i . - git diff --exit-code - stack --no-terminal test --coverage -#- shc tokstyle testsuite +- shc tokstyle testsuite diff --git a/BUILD.bazel b/BUILD.bazel index fb21853..471a028 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,7 +1,7 @@ -load("@io_tweag_rules_haskell//haskell:haskell.bzl", "haskell_library") +load("@io_tweag_rules_haskell//haskell:haskell.bzl", "haskell_library", "haskell_test") load("//tools:project.bzl", "project") -project("tokstyle") +project("hs-tokstyle") genrule( name = "Lexer", @@ -18,7 +18,7 @@ genrule( ) haskell_library( - name = "tokstyle", + name = "hs-tokstyle", srcs = glob(["src/**/*.*hs"]) + [ "src/Tokstyle/Cimple/Lexer.hs", "src/Tokstyle/Cimple/Parser.hs", @@ -39,3 +39,19 @@ haskell_library( "@haskell_language_c//:language-c", ], ) + +haskell_test( + name = "test", + srcs = glob(["test/**/*.*hs"]), + compiler_flags = [ + "-Wall", + "-Werror", + ], + src_strip_prefix = "test", + visibility = ["//visibility:public"], + deps = [ + ":hs-tokstyle", + "//third_party/haskell:base", + "@haskell_hspec//:hspec", + ], +) diff --git a/test/Tokstyle/CimpleSpec.hs b/test/Tokstyle/CimpleSpec.hs new file mode 100644 index 0000000..804bb33 --- /dev/null +++ b/test/Tokstyle/CimpleSpec.hs @@ -0,0 +1,18 @@ +module Tokstyle.CimpleSpec where + +import Test.Hspec + +import Tokstyle.Cimple.Lexer (runAlex) +import Tokstyle.Cimple.Parser (parseCimple) + + +spec :: Spec +spec = + describe "C parsing" $ do + it "should parse a simple function" $ do + let ast = runAlex "int a(void) { return 3; }" parseCimple + ast `shouldBe` Right [()] + + it "should parse a type declaration" $ do + let ast = runAlex "typedef struct Foo { int x; } Foo;" parseCimple + ast `shouldBe` Right [()] diff --git a/test/testsuite.hs b/test/testsuite.hs new file mode 100644 index 0000000..a824f8c --- /dev/null +++ b/test/testsuite.hs @@ -0,0 +1 @@ +{-# OPTIONS_GHC -F -pgmF hspec-discover #-} diff --git a/tokstyle.cabal b/tokstyle.cabal index bc20266..b576475 100644 --- a/tokstyle.cabal +++ b/tokstyle.cabal @@ -20,11 +20,11 @@ library exposed-modules: Tokstyle.C , Tokstyle.Cimple + , Tokstyle.Cimple.Lexer + , Tokstyle.Cimple.Parser , Tokstyle.Sources other-modules: Tokstyle.C.Naming - , Tokstyle.Cimple.Lexer - , Tokstyle.Cimple.Parser , Tokstyle.Result ghc-options: -Wall @@ -57,3 +57,18 @@ executable check-cimple base < 5 , tokstyle main-is: check-cimple.hs + +test-suite testsuite + type: exitcode-stdio-1.0 + default-language: Haskell2010 + hs-source-dirs: test + main-is: testsuite.hs + other-modules: + Tokstyle.CimpleSpec + ghc-options: + -Wall + -fno-warn-unused-imports + build-depends: + base < 5 + , tokstyle + , hspec diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel index c82c694..f854222 100644 --- a/tools/BUILD.bazel +++ b/tools/BUILD.bazel @@ -8,8 +8,8 @@ haskell_binary( "-Werror", ], deps = [ + "//hs-tokstyle", "//third_party/haskell:base", - "//tokstyle", ], ) @@ -21,7 +21,7 @@ haskell_binary( "-Werror", ], deps = [ + "//hs-tokstyle", "//third_party/haskell:base", - "//tokstyle", ], )