From 74f255d59d37dc5f57aed980164a28565c2e16d0 Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Tue, 4 Jun 2019 15:11:50 +0200 Subject: [PATCH] Add coverage support Signed-off-by: Sascha Grunert --- .circleci/config.yml | 7 ++----- .codecov.yml | 20 -------------------- .gitignore | 1 + Makefile | 18 +++++++++++++++++- README.md | 2 +- nix/default.nix | 5 +++-- nix/nixpkgs.json | 6 +++--- nix/shell.nix | 1 + nix/static.nix | 15 +++++++++++++++ performabot.cabal | 11 ++++++----- src/Main.hs | 2 +- src/{Lib.hs => Parser.hs} | 4 ++-- test/Main.hs | 25 +++++++++++++++++++++++++ test/ParserSpec.hs | 13 +++++++++++++ test/Test.hs | 10 ---------- 15 files changed, 90 insertions(+), 50 deletions(-) delete mode 100644 .codecov.yml create mode 100644 nix/static.nix rename src/{Lib.hs => Parser.hs} (57%) create mode 100644 test/Main.hs create mode 100644 test/ParserSpec.hs delete mode 100644 test/Test.hs diff --git a/.circleci/config.yml b/.circleci/config.yml index c56ec1d..af43d32 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -128,11 +128,8 @@ jobs: keys: - v1-test-{{ checksum "nix/nixpkgs.json" }} - run: - name: test - command: make test - - run: - name: Upload coverage - command: /bin/bash -c 'bash <(curl -s https://codecov.io/bash)' + name: test and coverage report + command: make coverage - save_cache: key: v1-test-{{ checksum "nix/nixpkgs.json" }} paths: diff --git a/.codecov.yml b/.codecov.yml deleted file mode 100644 index 807afb9..0000000 --- a/.codecov.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- -codecov: - notify: - after_n_builds: 1 - require_ci_to_pass: false - -coverage: - precision: 1 - round: down - range: 50..75 - - status: - project: true - patch: true - changes: false - -comment: - layout: "header, diff" - behavior: default - require_changes: false diff --git a/.gitignore b/.gitignore index 184f716..41db5ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.orig +*.tix .ghc.environment.* dist dist-* diff --git a/Makefile b/Makefile index 5229c42..e908e36 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,13 @@ -all: +all: build + +.PHONY: build +build: nix-build nix/release.nix +.PHONY: build-static +build-static: + nix-build nix/static.nix + define nix-shell nix-shell nix/shell.nix --pure $(1) endef @@ -17,6 +24,15 @@ cabal2nix: clean: $(call nix-shell-run,git clean -fdx) +.PHONY: coverage +coverage: + nix-shell nix/shell.nix --run \ + "cabal configure --enable-tests --enable-coverage &&\ + cabal test &&\ + hpc-coveralls performabot-test \ + -r ehCDKUtRSiNfht5xyC580BaZqCCjSBICz \ + --exclude-dir=test" + .PHONY: doc doc: $(call nix-shell-run,cabal new-haddock) diff --git a/README.md b/README.md index 4bc997d..38e3a7a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # performabot [![CircleCI](https://circleci.com/gh/saschagrunert/performabot.svg?style=shield)](https://circleci.com/gh/saschagrunert/performabot) -[![Coverage](https://codecov.io/gh/saschagrunert/performabot/branch/master/graph/badge.svg)](https://codecov.io/gh/saschagrunert/performabot) +[![Coverage](https://coveralls.io/repos/github/saschagrunert/performabot/badge.svg?branch=master)](https://coveralls.io/github/saschagrunert/performabot?branch=master) [![Doc](https://img.shields.io/badge/doc-performabot-orange.svg)](https://saschagrunert.github.io/performabot) [![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/saschagrunert/performabot/blob/master/LICENSE) diff --git a/nix/default.nix b/nix/default.nix index b2ac329..b8edb01 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,4 +1,5 @@ -{ mkDerivation, base, heavy-logger, mtl, stdenv, text-format-heavy +{ mkDerivation, base, heavy-logger, mtl, stdenv, tasty, tasty-hspec +, tasty-quickcheck, text-format-heavy }: mkDerivation { pname = "performabot"; @@ -10,6 +11,6 @@ mkDerivation { executableHaskellDepends = [ base heavy-logger mtl text-format-heavy ]; - testHaskellDepends = [ base ]; + testHaskellDepends = [ base tasty tasty-hspec tasty-quickcheck ]; license = stdenv.lib.licenses.mit; } diff --git a/nix/nixpkgs.json b/nix/nixpkgs.json index 0476828..63aa384 100644 --- a/nix/nixpkgs.json +++ b/nix/nixpkgs.json @@ -1,7 +1,7 @@ { "url": "https://github.com/nixos/nixpkgs", - "rev": "1a28cf89432d5f3c06134c20f866570a2594e149", - "date": "2019-06-03T05:52:47-07:00", - "sha256": "18prhyilncrmrh6n4bprzs37g8q5bfa68n39d3pc1cm77p67zma5", + "rev": "741d20c900025c4e5bc6f14a5703bd9340461640", + "date": "2019-06-04T17:02:45+02:00", + "sha256": "07qfbd7hlzncyv0bxyyqy5ifchmvfw0rfrf0g9zc8jq71810rqx9", "fetchSubmodules": false } diff --git a/nix/shell.nix b/nix/shell.nix index 3ce0782..0ceacce 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -8,6 +8,7 @@ pkgs.stdenv.mkDerivation { cabal-install cabal2nix git + haskellPackages.hpc-coveralls hlint nix-prefetch-git ]; diff --git a/nix/static.nix b/nix/static.nix new file mode 100644 index 0000000..8e93ce0 --- /dev/null +++ b/nix/static.nix @@ -0,0 +1,15 @@ +let + pkgs = (import ./nixpkgs.nix { }).pkgsMusl; +in + (pkgs.haskellPackages.callPackage ./default.nix { }).overrideAttrs(old: { + enableSharedExecutables = false; + enableSharedLibraries = false; + configureFlags = [ + "--ghc-option=-optl=-static" + "--extra-lib-dirs=${pkgs.gmp6.override { withStatic = true; }}/lib" + "--extra-lib-dirs=${pkgs.zlib.static}/lib" + "--extra-lib-dirs=${pkgs.libffi.overrideAttrs + (old: { dontDisableStatic = true; })}/lib" + "--disable-executable-stripping" + ]; + }) diff --git a/performabot.cabal b/performabot.cabal index 43b7336..5c11401 100644 --- a/performabot.cabal +++ b/performabot.cabal @@ -14,7 +14,7 @@ source-repository head library build-depends: base default-language: Haskell2010 - exposed-modules: Lib + exposed-modules: Parser ghc-options: -Werror -Weverything @@ -49,10 +49,10 @@ executable performabot -with-rtsopts=-N hs-source-dirs: src main-is: Main.hs - other-modules: Lib + other-modules: Parser -test-suite test-performabot - build-depends: base, performabot +test-suite performabot-test + build-depends: base, performabot, tasty, tasty-hspec, tasty-quickcheck ghc-options: -Werror -Weverything @@ -69,5 +69,6 @@ test-suite test-performabot -threaded -with-rtsopts=-N hs-source-dirs: test - main-is: Test.hs + main-is: Main.hs + other-modules: ParserSpec type: exitcode-stdio-1.0 diff --git a/src/Main.hs b/src/Main.hs index ef62e85..e05f2a2 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -10,7 +10,7 @@ import Control.Monad.Trans ( liftIO ) import Data.Text.Format.Heavy ( Single(Single) ) -import Lib ( parse ) +import Parser ( parse ) import System.IO ( BufferMode(LineBuffering), hSetBuffering, stdout ) diff --git a/src/Lib.hs b/src/Parser.hs similarity index 57% rename from src/Lib.hs rename to src/Parser.hs index d43e4a7..dfd44fb 100644 --- a/src/Lib.hs +++ b/src/Parser.hs @@ -1,5 +1,5 @@ --- | The main library interface -module Lib ( parse ) where +-- | All parser relevant implementations +module Parser ( parse ) where -- | Parse the provided string and return True on success parse :: String -> Bool diff --git a/test/Main.hs b/test/Main.hs new file mode 100644 index 0000000..f88262d --- /dev/null +++ b/test/Main.hs @@ -0,0 +1,25 @@ +-- | The main test module +-- +-- @since 0.1.0 +module Main ( main ) where + +import ParserSpec ( parserSpec ) + +import Test.Tasty + ( TestTree, defaultMain, localOption, testGroup ) +import Test.Tasty.Hspec ( testSpec ) +import Test.Tasty.QuickCheck ( QuickCheckTests(QuickCheckTests) ) + +-- The main test routine +main :: IO () +main = do + uTests <- unitTests + defaultMain . opts $ testGroup "Tests" [ uTests ] + where + opts = localOption $ QuickCheckTests 5000 + +-- Unit tests based on hspec +unitTests :: IO TestTree +unitTests = do + parserUnitTests <- testSpec "Parser.hs" parserSpec + return $ testGroup "Unit" [ parserUnitTests ] diff --git a/test/ParserSpec.hs b/test/ParserSpec.hs new file mode 100644 index 0000000..9616d5e --- /dev/null +++ b/test/ParserSpec.hs @@ -0,0 +1,13 @@ +-- | The parser tests +-- +-- @since 0.1.0 +module ParserSpec ( parserSpec ) where + +import Parser ( parse ) + +import Test.Tasty.Hspec ( Spec, it, parallel, shouldBe ) + +-- Parser.hs related unit tests +parserSpec :: Spec +parserSpec = parallel $ it "should succeed" $ parse "test" `shouldBe` True + diff --git a/test/Test.hs b/test/Test.hs deleted file mode 100644 index 87d733c..0000000 --- a/test/Test.hs +++ /dev/null @@ -1,10 +0,0 @@ -module Main ( main ) where - -import Lib ( parse ) - -import System.Exit ( exitFailure, exitSuccess ) - -main :: IO () -main = do - let success = parse "test" - if success then exitSuccess else exitFailure