Skip to content

Commit

Permalink
Rename repo to hs-tokstyle and add a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Aug 12, 2018
1 parent 8c709c6 commit 654db40
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -13,4 +13,4 @@ script:
- stylish-haskell-lhs -i .
- git diff --exit-code
- stack --no-terminal test --coverage
#- shc tokstyle testsuite
- shc tokstyle testsuite
22 changes: 19 additions & 3 deletions 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",
Expand All @@ -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",
Expand All @@ -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",
],
)
18 changes: 18 additions & 0 deletions 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 [()]
1 change: 1 addition & 0 deletions test/testsuite.hs
@@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
19 changes: 17 additions & 2 deletions tokstyle.cabal
Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions tools/BUILD.bazel
Expand Up @@ -8,8 +8,8 @@ haskell_binary(
"-Werror",
],
deps = [
"//hs-tokstyle",
"//third_party/haskell:base",
"//tokstyle",
],
)

Expand All @@ -21,7 +21,7 @@ haskell_binary(
"-Werror",
],
deps = [
"//hs-tokstyle",
"//third_party/haskell:base",
"//tokstyle",
],
)

0 comments on commit 654db40

Please sign in to comment.