-
Notifications
You must be signed in to change notification settings - Fork 111
/
tasty-travis.hsfiles
408 lines (331 loc) · 12.5 KB
/
tasty-travis.hsfiles
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
{-# START_FILE {{name}}.cabal #-}
name: {{name}}
version: 0.1.0.0
-- synopsis:
-- description:
license: ISC
license-file: LICENSE
author: {{author-name}}{{^author-name}}TODO:<Author name here>{{/author-name}}
maintainer: {{author-email}}{{^author-email}}TODO:<example@example.com>{{/author-email}}
copyright: © {{year}}{{^year}}2024{{/year}} {{author-name}}{{^author-name}}TODO:<Author name here>{{/author-name}}
homepage: https://github.com/{{github-username}}{{^github-username}}TODO:<githubuser>{{/github-username}}/{{name}}
bug-reports: https://github.com/{{github-username}}{{^github-username}}TODO:<githubuser>{{/github-username}}/{{name}}/issues
category: Test
build-type: Simple
stability: alpha (experimental)
cabal-version: >=1.10
extra-source-files:
README.md
CHANGELOG.md
stack.yaml
source-repository head
type: git
location: https://github.com/{{github-username}}{{^github-username}}TODO:<githubuser>{{/github-username}}/{{name}}
library
default-language: Haskell2010
hs-source-dirs: src
exposed-modules: Lib
build-depends: base >= 4.8 && < 5
ghc-options: -Wall
-Werror
-Wcompat
-Widentities
-Wincomplete-record-updates
-Wincomplete-uni-patterns
-Wmissing-export-lists
-Wmissing-home-modules
-Wpartial-fields
-Wredundant-constraints
-O2
executable {{name}}-exe
default-language: Haskell2010
hs-source-dirs: src-exe
main-is: Main.hs
build-depends: base >= 4.8 && < 5
, {{name}}
ghc-options: -Wall
-Werror
-Wcompat
-Widentities
-Wincomplete-record-updates
-Wincomplete-uni-patterns
-Wmissing-export-lists
-Wmissing-home-modules
-Wpartial-fields
-Wredundant-constraints
-O2
-threaded
-rtsopts
-with-rtsopts=-N
test-suite {{name}}-test
type: exitcode-stdio-1.0
default-language: Haskell2010
hs-source-dirs: src-test
main-is: Main.hs
build-depends: base >= 4.8 && < 5
, tasty >= 0.11
, tasty-hunit >= 0.9
, tasty-smallcheck >= 0.8
, {{name}}
ghc-options: -Wall
-Werror
-Wcompat
-Widentities
-Wincomplete-record-updates
-Wincomplete-uni-patterns
-Wmissing-export-lists
-Wmissing-home-modules
-Wpartial-fields
-Wredundant-constraints
-O2
-threaded
-rtsopts
-with-rtsopts=-N
test-suite {{name}}-doctest
type: exitcode-stdio-1.0
default-language: Haskell2010
hs-source-dirs: src-doctest
main-is: Main.hs
build-depends: base >= 4.8 && < 5
, doctest >=0.10
, Glob >= 0.7
, QuickCheck >= 2.5
, {{name}}
ghc-options: -Wall
-Werror
-Wcompat
-Widentities
-Wincomplete-record-updates
-Wincomplete-uni-patterns
-Wmissing-export-lists
-Wmissing-home-modules
-Wpartial-fields
-Wredundant-constraints
-O2
-threaded
-rtsopts
-with-rtsopts=-N
benchmark {{name}}-benchmark
type: exitcode-stdio-1.0
default-language: Haskell2010
hs-source-dirs: src-benchmark
main-is: Main.hs
build-depends: base >= 4.8 && < 5
, criterion >= 1.1
, {{name}}
ghc-options: -Wall
-Werror
-Wcompat
-Widentities
-Wincomplete-record-updates
-Wincomplete-uni-patterns
-Wmissing-export-lists
-Wmissing-home-modules
-Wpartial-fields
-Wredundant-constraints
-O2
-threaded
-rtsopts
-with-rtsopts=-N
{-# START_FILE Setup.hs #-}
import Distribution.Simple
main = defaultMain
{-# START_FILE src/Lib.hs #-}
-- | Example of a library file. It is also used for testing the test suites.
module Lib
(
-- * Exported functions
inc
) where
-- | Increment one 'Num' value.
--
-- >>> let answer = 42 :: Int
-- >>> let prev = answer - 1
-- >>> inc prev
-- 42
-- >>> succ . Prelude.last . Prelude.take prev . iterate inc $ 1
-- 42
--
-- Properties:
--
-- prop> succ x == inc x
-- prop> inc (negate x) == negate (pred x)
--
inc :: Num a => a -- ^ value to increment
-> a -- ^ result
inc x = x + 1
{-# START_FILE src-exe/Main.hs #-}
import Lib (inc)
main :: IO ()
main = print . inc $ (41 :: Int)
{-# START_FILE src-test/Main.hs #-}
import Test.Tasty
import Test.Tasty.HUnit
import Test.Tasty.SmallCheck
import Lib (inc)
main :: IO ()
main = defaultMain $ testGroup "all-tests" tests
tests :: [TestTree]
tests =
[ testGroup "SmallCheck" scTests
, testGroup "Unit tests" huTests
]
scTests :: [TestTree]
scTests =
[ testProperty "inc == succ" prop_succ
, testProperty "inc . negate == negate . pred" prop_pred
]
huTests :: [TestTree]
huTests =
[ testCase "Increment below TheAnswer" case_inc_below
, testCase "Decrement above TheAnswer" case_dec_above
]
prop_succ :: Int -> Bool
prop_succ n = inc n == succ n
prop_pred :: Int -> Bool
prop_pred n = inc (negate n) == negate (pred n)
case_inc_below :: Assertion
case_inc_below = inc 41 @?= (42 :: Int)
case_dec_above :: Assertion
case_dec_above = negate (inc (negate 43)) @?= (42 :: Int)
{-# START_FILE src-doctest/Main.hs #-}
import System.FilePath.Glob
import Test.DocTest
main :: IO ()
main = glob "src/**/*.hs" >>= doctest
{-# START_FILE src-benchmark/Main.hs #-}
import Criterion
import Criterion.Main
import Lib (inc)
main :: IO ()
main = defaultMain [bench "inc 41" (whnf inc (41 :: Int))]
{-# START_FILE README.md #-}
{{name}}
==========
New Haskell project using stack template `tasty-travis`.
Please read file `tutorial.md` for first steps in using the template.
{-# START_FILE CHANGELOG.md #-}
Change log
==========
{{name}} uses [Semantic Versioning][1].
The change log is available [on GitHub][2].
[1]: http://semver.org/spec/v2.0.0.html
[2]: https://github.com/{{github-username}}{{^github-username}}githubuser{{/github-username}}/{{name}}/releases
## v0.1.0.0
* Initially created.
{-# START_FILE LICENSE #-}
Copyright {{year}}{{^year}}2024{{/year}} {{author-name}}{{^author-name}}TODO:<Author name here>{{/author-name}}
Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
{-# START_FILE .gitignore #-}
/tutorial.md
/.stack-work/
{-# START_FILE .travis.yml #-}
# Use new container infrastructure to enable caching
sudo: false
# Choose a lightweight base image; we provide our own build tools.
language: c
# GHC depends on GMP. You can add other dependencies here as well.
addons:
apt:
packages:
- libgmp-dev
# The different configurations we want to test. You could also do things like
# change flags or use --stack-yaml to point to a different file.
env:
- ARGS=""
#- ARGS="--resolver lts-2"
- ARGS="--resolver lts"
- ARGS="--resolver nightly"
before_install:
# Download and unpack the stack executable
- mkdir -p ~/.local/bin
- export PATH=$HOME/.local/bin:$PATH
- travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
# This line does all of the work: installs GHC if necessary, builds the
# library, executables, and test suites, and runs the test suites.
# `--no-terminal works` around some quirks in Travis's terminal implementation.
script: stack $ARGS --no-terminal --install-ghc test
# Caching so the next build will be fast too.
cache:
directories:
- $HOME/.stack
{-# START_FILE tutorial.md #-}
Thanks for using the stack template `tasty-travis`! This file is here to guide
you through customizing the template files.
This template allows you to start a simple Haskell project, either to create a
library or an application. It offers you the choice to customize the source
directory while providing hints on the proposed hierarchy that the author uses
(inspired by other Haskell projects).
In the following sections, I will explain how to use the template.
1. Initial configurations
=========================
Before you get started, there are a few things that this template couldn't
provide for you. You should:
* Add a synopsis to `{{name}}.cabal`. It should be a short, one sentence
explanation of your project.
* Edit the description field in `{{name}}.cabal` if you don't like having
the description in the `README.md` file.
* In `{{name}}.cabal`, the category of the project has been set as 'Test'.
You might wish to change it to a more descriptive value. A list of
categories that you can use for the project is available on Hackage at
<http://hackage.haskell.org/packages>. Alternatively, you might prefer using
a name from the shorter list at
<https://byorgey.wordpress.com/2010/04/15/cabal-init/>.
* If you haven't provided the `author-email`, `author-name`, and
`github-username` to the `config.yaml` global file, you will have to search
for "TODO" markup and complete this information in `{{name}}.cabal` and/or
in `LICENSE`.
2. Creating the git repository
==============================
If this project is a subdirectory of a larger project with an existing version
control or you want to use another version control system or another setup,
then you can ignore this section.
From the root directory of the project (the directory of this file) you will
need to run the following three commands:
git init
git add .
git commit -m "Initial commit"
Now you can create a repository on GitHub to publish the code.
Note that this file is excluded from the repository by being included in the
`.gitignore` file. If you want this file to be tracked, you can remove the
line `/tutorial.md` from that file.
3. Testing the initial code
===========================
These are the stack commands you will likely use the most:
``` sh
# Build the project.
stack build
# Run the binary
stack exec {{name}}-exe
# Run the test suite.
stack test
# Run the benchmarks.
stack bench
# Generate documentation.
stack haddock
```
4. Customizing
==============
As you see, the template creates both a library and a binary and tests the
library using two test suites (doctests from comments and tests with Tasty).
Both test suites can test both properties and expected testcases. Finally,
the template also offers a way to benchmark the code.
Your project might differ significantly from this template. For example, you
might want to have a different number of executables. In that case, you should
remove/add more executable stanzas in `{{name}}.cabal`.
Similarly, if you don't want both test suites, you can remove one of the
stanzas. You could do the same for the benchmarks.
*More importantly* you might want to change the contents of the library.
Rename `src/Lib` to whatever you want your top-module to be, usually the name
of your project but using `CamelCase`. Don't forget to change this name in all
places where it is referenced (executable(s), test(s) and benchmark(s)).
Thanks again, and happy hacking!