Skip to content

Commit

Permalink
Split examples into their own cabal project.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwils committed Feb 5, 2018
1 parent 9f4e1d8 commit 7995c94
Show file tree
Hide file tree
Showing 22 changed files with 167 additions and 128 deletions.
35 changes: 28 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down Expand Up @@ -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"

Expand All @@ -64,27 +65,46 @@ 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;
# any command which exits with a non-zero exit code causes the build to fail.
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
Expand 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
2 changes: 1 addition & 1 deletion LICENCE
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 4 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
packages:
./
./examples

5 changes: 5 additions & 0 deletions examples/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Revision history for sv-examples

## 0.1.0.0 -- YYYY-mm-dd

* First version. Released on an unsuspecting world.
31 changes: 31 additions & 0 deletions examples/LICENCE
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions examples/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions examples/csv/requote.golden.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"name", "age"
"Frank", "30"
"George", "25", """functional"" programmer"
"Harry","32"
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion test/concat.hs → examples/src/Data/Sv/Example/Concat.hs
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion test/ragged.hs → examples/src/Data/Sv/Example/Ragged.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Data.Sv.Example.Ragged where

import Data.Functor.Alt
import Data.ByteString (ByteString)
import Data.Text (Text)
Expand All @@ -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
Expand Down
11 changes: 8 additions & 3 deletions test/requote.hs → examples/src/Data/Sv/Example/Requote.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Data.Sv.Example.Requote where

import Control.Lens
import Data.Text (Text)
import System.Exit (exitFailure)
Expand All @@ -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 $
Expand All @@ -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 ->
Expand Down
4 changes: 2 additions & 2 deletions test/species.lhs → examples/src/Data/Sv/Example/Species.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion test/tt.hs → examples/src/Data/Sv/Example/TableTennis.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{-# LANGUAGE OverloadedStrings #-}

module Data.Sv.Example.TableTennis where

import Control.Applicative ((<|>))
import Control.Lens
import Control.Monad (unless)
Expand All @@ -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)
Expand Down
52 changes: 52 additions & 0 deletions examples/sv-examples.cabal
Original file line number Diff line number Diff line change
@@ -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: [email protected]
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
13 changes: 13 additions & 0 deletions examples/test/test.hs
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 7995c94

Please sign in to comment.