Skip to content

Commit d3d266a

Browse files
committed
tests: Add a cabal new-build project
1 parent 2fbda8d commit d3d266a

File tree

10 files changed

+121
-0
lines changed

10 files changed

+121
-0
lines changed

test/shell-for/cabal.project

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages: pkga
2+
pkgb

test/shell-for/pkga/PkgA.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module PkgA (decode) where
2+
3+
import Control.Lens
4+
import Data.Text.Lens
5+
import Data.Char
6+
import Data.Text (Text)
7+
8+
decode :: Text -> Text
9+
decode = unpacked . mapped %~ rot 13
10+
11+
rot :: Int -> Char -> Char
12+
rot n c | c >= 'a' && c <= 'z' = r 'a' 'z'
13+
| c >= 'A' && c <= 'Z' = r 'A' 'Z'
14+
| otherwise = c
15+
where
16+
r a b = chr $ ord a + ((ord c - ord a + n) `mod` (ord b - ord a + 1))

test/shell-for/pkga/Setup.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

test/shell-for/pkga/pkga.cabal

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
cabal-version: 2.2
2+
-- Initial package description 'pkga.cabal' generated by 'cabal init'. For
3+
-- further documentation, see http://haskell.org/cabal/users-guide/
4+
5+
name: pkga
6+
version: 0.1.0.0
7+
-- synopsis:
8+
-- description:
9+
-- bug-reports:
10+
license: LicenseRef-PublicDomain
11+
author: Rodney Lorrimar
12+
maintainer: [email protected]
13+
category: Testing
14+
15+
library
16+
exposed-modules: PkgA
17+
build-depends: base
18+
, lens
19+
, text
20+
default-language: Haskell2010

test/shell-for/pkgb/Setup.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

test/shell-for/pkgb/app/Main.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Main where
2+
3+
import ConduitExample (example)
4+
import PkgB (message)
5+
import qualified Data.Text.IO as T
6+
7+
main :: IO ()
8+
main = do
9+
T.putStrLn message
10+
example

test/shell-for/pkgb/pkgb.cabal

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
cabal-version: 2.2
2+
-- Initial package description 'pkgb.cabal' generated by 'cabal init'. For
3+
-- further documentation, see http://haskell.org/cabal/users-guide/
4+
5+
name: pkgb
6+
version: 0.1.0.0
7+
-- synopsis:
8+
-- description:
9+
-- bug-reports:
10+
license: LicenseRef-PublicDomain
11+
author: Rodney Lorrimar
12+
maintainer: [email protected]
13+
category: Testing
14+
15+
library
16+
exposed-modules: ConduitExample
17+
, PkgB
18+
build-depends: base
19+
, pkga
20+
, conduit
21+
, conduit-extra
22+
, directory
23+
, resourcet
24+
hs-source-dirs: src
25+
default-language: Haskell2010
26+
27+
executable pkgb
28+
main-is: Main.hs
29+
-- other-modules:
30+
-- other-extensions:
31+
build-depends: base
32+
, pkgb
33+
, optparse-applicative
34+
, text
35+
hs-source-dirs: app
36+
default-language: Haskell2010
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- https://github.com/snoyberg/conduit#readme
2+
3+
module ConduitExample (example) where
4+
5+
import Conduit
6+
import System.Directory (removeFile)
7+
8+
example = do
9+
-- Pure operations: summing numbers.
10+
print $ runConduitPure $ yieldMany [1..10] .| sumC
11+
12+
-- Exception safe file access: copy a file.
13+
writeFile "input.txt" "This is a test." -- create the source file
14+
runConduitRes $ sourceFileBS "input.txt" .| sinkFile "output.txt" -- actual copying
15+
readFile "output.txt" >>= putStrLn -- prove that it worked
16+
17+
-- Perform transformations.
18+
print $ runConduitPure $ yieldMany [1..10] .| mapC (+ 1) .| sinkList
19+
20+
removeFile "input.txt"
21+
removeFile "output.txt"

test/shell-for/pkgb/src/PkgB.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
3+
module PkgB (message) where
4+
5+
import PkgA (decode)
6+
7+
message = decode "Guvf vf n pnony cebwrpg!"

test/shell-for/pkgb/src/conduit.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Main where
2+
3+
import ConduitExample
4+
5+
main = example

0 commit comments

Comments
 (0)