Skip to content

Commit

Permalink
[#559] Add example with haskell and stack
Browse files Browse the repository at this point in the history
  • Loading branch information
mengdaming committed Jul 22, 2024
1 parent 933d8fe commit 0478d6d
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Here are some simple examples for using TCR with various languages & toolchains
- With [make](go-make/README.md)
- With [bazel](go-bazel/README.md)

## Haskell

- With [stack](haskell-stack/README.md)

## Java

- With [gradle](java-gradle/README.md)
Expand Down
2 changes: 2 additions & 0 deletions examples/haskell-stack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# haskell downloaded or generated stuff
.stack-work/
9 changes: 9 additions & 0 deletions examples/haskell-stack/.tcr/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
config:
git:
auto-push: false
polling-period: 2s
mob-timer:
duration: 5m0s
tcr:
language: haskell
toolchain: stack
9 changes: 9 additions & 0 deletions examples/haskell-stack/.tcr/language/haskell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
toolchains:
default: stack
compatible-with: [ stack ]
source-files:
directories: [ src ]
patterns: [ '(?i)^.*\.hs$' ]
test-files:
directories: [ test ]
patterns: [ '(?i)^.*\.hs$' ]
11 changes: 11 additions & 0 deletions examples/haskell-stack/.tcr/toolchain/stack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
build:
- os: [ darwin, linux, windows ]
arch: [ "386", amd64, arm64 ]
command: stack
arguments: [ build ]
test:
- os: [ darwin, linux, windows ]
arch: [ "386", amd64, arm64 ]
command: stack
arguments: [ test, --color, always, --test-arguments=--format=progress ]
test-result-dir: .stack-work/report
51 changes: 51 additions & 0 deletions examples/haskell-stack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Using TCR with Haskell and Stack

## Prerequisites

- macOS, Linux or Windows
- [git](https://git-scm.com/) client
- [curl](https://curl.se/download.html) command line utility
- [haskell](https://www.haskell.org/downloads/)

## Instructions

### 1 - Open a terminal

> ***Note to Windows users***
>
> Use a **git bash** terminal for running the commands below.
> _Windows CMD and PowerShell are not supported_
### 2 - Launch TCR

> ***Reminder***: the command below should be run from
> [examples/haskell-stack](.)
> directory
From the built-in terminal:

```shell
./tcrw
```

### Cheat Sheet

Here are the main shortcuts available once TCR utility is running:

| Shortcut | Description |
|-----------|----------------------------------------------|
| `o` / `O` | Open in browser (with `web` subcommand only) |
| `d` / `D` | Enter driver role |
| `n` / `N` | Enter navigator role |
| `t` / `T` | Query timer status |
| `p` / `P` | Toggle on/off git auto-push |
| `l` / `L` | Pull from remote |
| `s` / `S` | Push to remote |
| `a` / `A` | Abort current command (when in driver role) |
| `q` / `Q` | Quit current role / Quit TCR |
| `?` | List available options |

### Additional Details

Refer to [tcr.md](../../doc/tcr.md) page for additional details and explanations about TCR
available subcommands and options
34 changes: 34 additions & 0 deletions examples/haskell-stack/hello-world.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.36.0.
--
-- see: https://github.com/sol/hpack

name: hello-world
version: 1.0.0.0
build-type: Simple

library
exposed-modules:
HelloWorld
other-modules:
Paths_hello_world
hs-source-dirs:
src
ghc-options: -Wall
build-depends:
base
default-language: Haskell2010

test-suite test
type: exitcode-stdio-1.0
main-is: Tests.hs
other-modules:
Paths_hello_world
hs-source-dirs:
test
build-depends:
base
, hello-world
, hspec
default-language: Haskell2010
21 changes: 21 additions & 0 deletions examples/haskell-stack/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: hello-world
version: 1.0.0.0

dependencies:
- base

library:
exposed-modules: HelloWorld
source-dirs: src
ghc-options: -Wall
# dependencies:
# - foo # List here the packages you
# - bar # want to use in your solution.

tests:
test:
main: Tests.hs
source-dirs: test
dependencies:
- hello-world
- hspec
4 changes: 4 additions & 0 deletions examples/haskell-stack/src/HelloWorld.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module HelloWorld (sayHello) where

sayHello :: String -> String
sayHello name = "Hello, " ++ name ++ "!"
1 change: 1 addition & 0 deletions examples/haskell-stack/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
resolver: lts-21.25
12 changes: 12 additions & 0 deletions examples/haskell-stack/stack.yaml.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages: []
snapshots:
- completed:
sha256: a81fb3877c4f9031e1325eb3935122e608d80715dc16b586eb11ddbff8671ecd
size: 640086
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/25.yaml
original: lts-21.25
4 changes: 4 additions & 0 deletions examples/haskell-stack/tcrw
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

base_dir="$(cd "$(dirname -- "$0")" && pwd)"
. "${base_dir}/../tcr/tcr.sh"
11 changes: 11 additions & 0 deletions examples/haskell-stack/test/Tests.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Test.Hspec (Spec, it, shouldBe)
import Test.Hspec.Runner (configFailFast, defaultConfig, hspecWith)

import HelloWorld (sayHello)

main :: IO ()
main = hspecWith defaultConfig {configFailFast = True} specs

specs :: Spec
specs = it "say hello" $
sayHello "Sue" `shouldBe` "Hello, Sue!"

0 comments on commit 0478d6d

Please sign in to comment.