diff --git a/.travis.yml b/.travis.yml index d92dfd6..b350f09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ # This Travis job script has been generated by a script via # -# runghc make_travis_yml_2.hs 'sv.cabal' +# runghc make_travis_yml_2.hs 'cabal.project' # # For more information, see https://github.com/hvr/multi-ghc-travis # @@ -38,8 +38,9 @@ matrix: # env: TEST=--disable-tests BENCH=--disable-benchmarks addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.2.2], sources: [hvr-ghc]}} - compiler: "ghc-8.4.1" - # env: TEST=--disable-tests BENCH=--disable-benchmarks + env: GHCHEAD=true addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.4.1], sources: [hvr-ghc]}} + allow_failures: - compiler: "ghc-8.4.1" @@ -64,16 +65,34 @@ install: - travis_retry cabal update -v - "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config" - rm -fv cabal.project cabal.project.local + # Overlay Hackage Package Index for GHC HEAD: https://github.com/hvr/head.hackage + - | + if $GHCHEAD; then + sed -i.bak 's/-- allow-newer:.*/allow-newer: *:base, *:template-haskell, *:ghc, *:Cabal/' ${HOME}/.cabal/config + + echo 'repository head.hackage' >> ${HOME}/.cabal/config + echo ' url: http://head.hackage.haskell.org/' >> ${HOME}/.cabal/config + echo ' secure: True' >> ${HOME}/.cabal/config + echo ' root-keys: 07c59cb65787dedfaef5bd5f987ceb5f7e5ebf88b904bbd4c5cbdeb2ff71b740' >> ${HOME}/.cabal/config + echo ' 2e8555dde16ebd8df076f1a8ef13b8f14c66bad8eafefd7d9e37d0ed711821fb' >> ${HOME}/.cabal/config + echo ' 8f79fd2389ab2967354407ec852cbe73f2e8635793ac446d09461ffb99527f6e' >> ${HOME}/.cabal/config + echo ' key-threshold: 3' >> ${HOME}/.cabal.config + + cabal new-update head.hackage -v + fi - grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$' - - "printf 'packages: \".\"\\n' > cabal.project" + - "printf 'packages: \".\" \"./examples\"\\n' > cabal.project" - cat cabal.project - if [ -f "./configure.ac" ]; then (cd "." && autoreconf -i); fi + - if [ -f "./examples/configure.ac" ]; then + (cd "./examples" && autoreconf -i); + fi - rm -f cabal.project.freeze - cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 all - cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project" --dep -j2 all - - rm -rf "."/.ghc.environment.* "."/dist + - rm -rf "."/.ghc.environment.* "./examples"/.ghc.environment.* "."/dist "./examples"/dist - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX) # Here starts the actual work to be performed for the package under test; @@ -81,10 +100,11 @@ install: script: # test that source-distributions can be generated - (cd "." && cabal sdist) - - mv "."/dist/sv-*.tar.gz ${DISTDIR}/ + - (cd "./examples" && cabal sdist) + - mv "."/dist/sv-*.tar.gz "./examples"/dist/sv-examples-*.tar.gz ${DISTDIR}/ - cd ${DISTDIR} || false - find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \; - - "printf 'packages: sv-*/*.cabal\\n' > cabal.project" + - "printf 'packages: sv-*/*.cabal sv-examples-*/*.cabal\\n' > cabal.project" - cat cabal.project # this builds all libraries and executables (without tests/benchmarks) - cabal new-build -w ${HC} --disable-tests --disable-benchmarks all @@ -98,10 +118,11 @@ script: # cabal check - (cd sv-* && cabal check) + - (cd sv-examples-* && cabal check) # haddock - rm -rf ./dist-newstyle - if $HADDOCK; then cabal new-haddock -w ${HC} ${TEST} ${BENCH} all; else echo "Skipping haddock generation";fi -# REGENDATA ["sv.cabal"] +# REGENDATA ["cabal.project"] # EOF diff --git a/LICENCE b/LICENCE index 9dd6055..ec2b1bd 100644 --- a/LICENCE +++ b/LICENCE @@ -1,4 +1,4 @@ -Copyright (c) 2017, Commonwealth Scientific and Industrial Research Organisation +Copyright (c) 2017-2018, Commonwealth Scientific and Industrial Research Organisation (CSIRO) ABN 41 687 119 230. All rights reserved. diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..f0f08cb --- /dev/null +++ b/cabal.project @@ -0,0 +1,4 @@ +packages: + ./ + ./examples + diff --git a/examples/ChangeLog.md b/examples/ChangeLog.md new file mode 100644 index 0000000..b0b4451 --- /dev/null +++ b/examples/ChangeLog.md @@ -0,0 +1,5 @@ +# Revision history for sv-examples + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/examples/LICENCE b/examples/LICENCE new file mode 100644 index 0000000..bbc1858 --- /dev/null +++ b/examples/LICENCE @@ -0,0 +1,31 @@ +Copyright (c) 2017-2018, Commonwealth Scientific and Industrial Research Organisation +(CSIRO) ABN 41 687 119 230. + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of George Wilson nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/examples/Setup.hs b/examples/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/examples/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/test/concat.csv b/examples/csv/concat.csv similarity index 100% rename from test/concat.csv rename to examples/csv/concat.csv diff --git a/test/ragged.csv b/examples/csv/ragged.csv similarity index 100% rename from test/ragged.csv rename to examples/csv/ragged.csv diff --git a/test/requote.csv b/examples/csv/requote.csv similarity index 100% rename from test/requote.csv rename to examples/csv/requote.csv diff --git a/test/requote.golden.csv b/examples/csv/requote.fixed.csv similarity index 100% rename from test/requote.golden.csv rename to examples/csv/requote.fixed.csv diff --git a/examples/csv/requote.golden.csv b/examples/csv/requote.golden.csv new file mode 100644 index 0000000..1071057 --- /dev/null +++ b/examples/csv/requote.golden.csv @@ -0,0 +1,4 @@ +"name", "age" +"Frank", "30" +"George", "25", """functional"" programmer" +"Harry","32" diff --git a/test/species.csv b/examples/csv/species.csv similarity index 100% rename from test/species.csv rename to examples/csv/species.csv diff --git a/test/tt-handicap.csv b/examples/csv/tt-handicap.csv similarity index 100% rename from test/tt-handicap.csv rename to examples/csv/tt-handicap.csv diff --git a/test/concat.hs b/examples/src/Data/Sv/Example/Concat.hs similarity index 95% rename from test/concat.hs rename to examples/src/Data/Sv/Example/Concat.hs index f4ff65c..c97a620 100644 --- a/test/concat.hs +++ b/examples/src/Data/Sv/Example/Concat.hs @@ -1,3 +1,5 @@ +module Data.Sv.Example.Concat where + import Data.ByteString (ByteString) import Data.Text (Text) import Text.Trifecta (TokenParsing, CharParsing, integer, parseFromFile, string) @@ -7,7 +9,7 @@ import Data.Sv hiding (integer, parser, string) import Text.Babel (Textual) file :: FilePath -file = "test/concat.csv" +file = "csv/concat.csv" type Name = Text type Age = Int diff --git a/test/ragged.hs b/examples/src/Data/Sv/Example/Ragged.hs similarity index 91% rename from test/ragged.hs rename to examples/src/Data/Sv/Example/Ragged.hs index 9f23108..4628ba1 100644 --- a/test/ragged.hs +++ b/examples/src/Data/Sv/Example/Ragged.hs @@ -1,3 +1,5 @@ +module Data.Sv.Example.Ragged where + import Data.Functor.Alt import Data.ByteString (ByteString) import Data.Text (Text) @@ -6,7 +8,7 @@ import System.Exit (exitFailure) import Data.Sv file :: FilePath -file = "test/ragged.csv" +file = "csv/ragged.csv" type Name = Text type Age = Int diff --git a/test/requote.hs b/examples/src/Data/Sv/Example/Requote.hs similarity index 84% rename from test/requote.hs rename to examples/src/Data/Sv/Example/Requote.hs index 82849b7..f63ad5a 100644 --- a/test/requote.hs +++ b/examples/src/Data/Sv/Example/Requote.hs @@ -1,3 +1,5 @@ +module Data.Sv.Example.Requote where + import Control.Lens import Data.Text (Text) import System.Exit (exitFailure) @@ -12,11 +14,14 @@ import Data.Sv.Print (writeSvToFile) import Text.Escape (Unescaped (Unescaped)) import Text.Quote (Quote (DoubleQuote)) +original :: FilePath +original = "csv/requote.csv" + fixed :: FilePath -fixed = "test/requote.fixed.csv" +fixed = "csv/requote.fixed.csv" golden :: FilePath -golden = "test/requote.golden.csv" +golden = "csv/requote.golden.csv" main :: IO () main = defaultMain $ @@ -30,7 +35,7 @@ config = defaultParseOptions requote :: IO () requote = do - svMay <- parseFromFile (separatedValuesWithOpts config) "test/requote.csv" + svMay <- parseFromFile (separatedValuesWithOpts config) original case svMay of Nothing -> exitFailure Just s -> diff --git a/test/species.lhs b/examples/src/Data/Sv/Example/Species.lhs similarity index 99% rename from test/species.lhs rename to examples/src/Data/Sv/Example/Species.lhs index 2ae77a5..ece2473 100644 --- a/test/species.lhs +++ b/examples/src/Data/Sv/Example/Species.lhs @@ -10,7 +10,7 @@ -- -- This is a literate Haskell file. If you are reading the haddock, -- we recommend that instead you view the source to follow along. -module Main where +module Data.Sv.Example.Species where import Control.Lens ((&), (.~)) import Data.ByteString (ByteString) @@ -35,7 +35,7 @@ incompatible with UTF-8. \begin{code} file :: FilePath -file = "test/species.csv" +file = "csv/species.csv" \end{code} The parser needs some configuration to parse our file. For example, it diff --git a/test/tt.hs b/examples/src/Data/Sv/Example/TableTennis.hs similarity index 94% rename from test/tt.hs rename to examples/src/Data/Sv/Example/TableTennis.hs index bfb7ef4..af712d0 100644 --- a/test/tt.hs +++ b/examples/src/Data/Sv/Example/TableTennis.hs @@ -1,5 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} +module Data.Sv.Example.TableTennis where + import Control.Applicative ((<|>)) import Control.Lens import Control.Monad (unless) @@ -17,7 +19,7 @@ import Data.Sv hiding (integer) -- Table tennis handicaps file :: FilePath -file = "test/tt-handicap.csv" +file = "csv/tt-handicap.csv" config :: ParseOptions config = defaultParseOptions & (headedness .~ Unheaded) diff --git a/examples/sv-examples.cabal b/examples/sv-examples.cabal new file mode 100644 index 0000000..7643122 --- /dev/null +++ b/examples/sv-examples.cabal @@ -0,0 +1,52 @@ +name: sv-examples +version: 0.1.0.0 +synopsis: Examples of sv usage +description: Examples of sv usage. This can be run as a test-suite +homepage: https://github.com/qfpl/sv +license: BSD3 +license-file: LICENCE +author: George Wilson +maintainer: george@wils.online +copyright: +category: Example +build-type: Simple +extra-source-files: ChangeLog.md + , csv/species.csv + , csv/ragged.csv + , csv/concat.csv + , csv/requote.csv + , csv/requote.golden.csv + , csv/tt-handicap.csv +cabal-version: >=1.10 +tested-with: GHC == 7.10.3 + , GHC == 8.0.2 + , GHC == 8.2.2 + , GHC == 8.4.1 + +library + exposed-modules: Data.Sv.Example.Concat + , Data.Sv.Example.Ragged + , Data.Sv.Example.Requote + , Data.Sv.Example.Species + , Data.Sv.Example.TableTennis + build-depends: base >= 4.8 && < 4.11 + , sv + , bytestring >= 0.9.1.10 && < 0.11 + , lens >= 4 && < 5 + , parsers >= 0.12 && <0.13 + , semigroupoids >= 5 && <6 + , tasty >= 0.11 && < 0.12 + , tasty-golden >= 2.3 && < 2.4 + , text >= 1.0 && < 1.3 + , time >= 1.6 && < 1.10 + , trifecta >= 1.5 && < 1.8 + hs-source-dirs: src + default-language: Haskell2010 + +test-suite test + type: exitcode-stdio-1.0 + default-language: Haskell2010 + hs-source-dirs: test + main-is: test.hs + build-depends: base >= 4.8 && < 4.11 + , sv-examples diff --git a/examples/test/test.hs b/examples/test/test.hs new file mode 100644 index 0000000..09fd77f --- /dev/null +++ b/examples/test/test.hs @@ -0,0 +1,13 @@ +import qualified Data.Sv.Example.Concat as Concat +import qualified Data.Sv.Example.Ragged as Ragged +import qualified Data.Sv.Example.Requote as Requote +import qualified Data.Sv.Example.Species as Species +import qualified Data.Sv.Example.TableTennis as TableTennis + +main :: IO () +main = do + Concat.main + Ragged.main + Requote.main + Species.main + TableTennis.main diff --git a/sv.cabal b/sv.cabal index 7644a0a..4baf94b 100644 --- a/sv.cabal +++ b/sv.cabal @@ -38,14 +38,11 @@ homepage: https://github.com/qfpl/sv bug-reports: https://github.com/qfpl/sv/issues build-type: Simple extra-source-files: changelog.md - , test/species.csv - , test/ragged.csv - , test/concat.csv - , test/requote.csv - , test/requote.golden.csv - , test/tt-handicap.csv cabal-version: >=1.10 -tested-with: GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2 +tested-with: GHC == 7.10.3 + , GHC == 8.0.2 + , GHC == 8.2.2 + , GHC == 8.4.1 source-repository head type: git @@ -136,103 +133,3 @@ test-suite tasty -Wall hs-source-dirs: test - - -test-suite species - type: - exitcode-stdio-1.0 - main-is: - species.lhs - default-language: - Haskell2010 - build-depends: - base >=4.8 && <5 - , bytestring >= 0.9.1.10 && < 0.11 - , lens >= 4 && < 5 - , sv - ghc-options: - -Wall - hs-source-dirs: - test - - -test-suite requote - type: - exitcode-stdio-1.0 - main-is: - requote.hs - default-language: - Haskell2010 - build-depends: - base >=4.8 && <5 - , bytestring >= 0.9.1.10 && < 0.11 - , lens >= 4 && < 5 - , tasty >= 0.11 && < 0.12 - , tasty-golden >= 2.3 && < 2.4 - , text >= 1.0 && < 1.3 - , trifecta >= 1.5 && < 1.8 - , sv - ghc-options: - -Wall - hs-source-dirs: - test - -test-suite ragged - type: - exitcode-stdio-1.0 - main-is: - ragged.hs - default-language: - Haskell2010 - build-depends: - base >=4.8 && <5 - , bytestring >= 0.9.1.10 && < 0.11 - , lens >= 4 && < 5 - , semigroupoids >= 5 && <6 - , sv - , text >= 1.0 && < 1.3 - ghc-options: - -Wall - hs-source-dirs: - test - - -test-suite concat - type: - exitcode-stdio-1.0 - main-is: - concat.hs - default-language: - Haskell2010 - build-depends: - base >=4.8 && <5 - , bytestring >= 0.9.1.10 && < 0.11 - , lens >= 4 && < 5 - , text >= 1.0 && < 1.3 - , trifecta >= 1.5 && < 1.8 - , sv - ghc-options: - -Wall - hs-source-dirs: - test - - -test-suite tt - type: - exitcode-stdio-1.0 - main-is: - tt.hs - default-language: - Haskell2010 - build-depends: - base >=4.8 && <5 - , bytestring >= 0.9.1.10 && < 0.11 - , lens >= 4 && < 5 - , parsers >=0.12 && <0.13 - , text >= 1.0 && < 1.3 - , time >= 1.6 && < 1.10 - , sv - ghc-options: - -Wall - hs-source-dirs: - test diff --git a/sv.nix b/sv.nix index 5a5f7cb..1629afc 100644 --- a/sv.nix +++ b/sv.nix @@ -1,9 +1,8 @@ { mkDerivation, ansi-wl-pprint, attoparsec, base, bifunctors , bytestring, charset, containers, contravariant, hedgehog, lens , mtl, parsec, parsers, profunctors, readable, semigroupoids -, semigroups, separated, stdenv, tasty, tasty-golden -, tasty-hedgehog, tasty-hunit, text, time, transformers, trifecta -, validation, void +, semigroups, separated, stdenv, tasty, tasty-hedgehog, tasty-hunit +, text, transformers, trifecta, validation, void }: mkDerivation { pname = "sv"; @@ -17,8 +16,8 @@ mkDerivation { ]; testHaskellDepends = [ ansi-wl-pprint base bytestring contravariant hedgehog lens parsers - semigroupoids semigroups separated tasty tasty-golden - tasty-hedgehog tasty-hunit text time trifecta validation + semigroupoids semigroups separated tasty tasty-hedgehog tasty-hunit + text trifecta validation ]; homepage = "https://github.com/qfpl/sv"; description = "Parse and decode values which are separated, often by commas";