Skip to content

Commit 79d8586

Browse files
Add GitHub Actions CI and test for symbolic link (#50)
1 parent eccdead commit 79d8586

File tree

9 files changed

+257
-27
lines changed

9 files changed

+257
-27
lines changed

.github/workflows/ci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI
2+
on:
3+
- push
4+
- pull_request
5+
jobs:
6+
7+
cabal:
8+
name: ${{ matrix.os }} - GHC ${{ matrix.ghc }}
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
os: [ubuntu-latest, macOS-latest, windows-latest]
13+
ghc:
14+
- 8.8.4
15+
- 8.10.7
16+
- 9.0.1
17+
- 9.2.1
18+
fail-fast: false
19+
continue-on-error: ${{ startsWith(matrix.os, 'windows') && startsWith(matrix.ghc, '9.2') }}
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
24+
- uses: haskell/actions/setup@v1
25+
id: setup-haskell-cabal
26+
name: Setup Haskell
27+
with:
28+
ghc-version: ${{ matrix.ghc }}
29+
30+
- name: Freeze
31+
run: |
32+
cabal freeze
33+
34+
- uses: actions/cache@v2
35+
name: Cache ~/.cabal/store
36+
with:
37+
path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
38+
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }}
39+
40+
- name: Build
41+
run: |
42+
cabal configure --enable-tests --enable-benchmarks --test-show-details=direct
43+
cabal build all
44+
45+
- name: Test
46+
run: |
47+
cabal test all

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/test/dist/
44
*.swp
55
.ghc.*
6+
.stack-work

stack.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# This file was automatically generated by 'stack init'
2+
#
3+
# Some commonly used options have been documented as comments in this file.
4+
# For advanced use and comprehensive documentation of the format, please see:
5+
# https://docs.haskellstack.org/en/stable/yaml_configuration/
6+
7+
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
8+
# A snapshot resolver dictates the compiler version and the set of packages
9+
# to be used for project dependencies. For example:
10+
#
11+
# resolver: lts-3.5
12+
# resolver: nightly-2015-09-21
13+
# resolver: ghc-7.10.2
14+
#
15+
# The location of a snapshot can be provided as a file or url. Stack assumes
16+
# a snapshot provided as a file might change, whereas a url resource does not.
17+
#
18+
# resolver: ./custom-snapshot.yaml
19+
# resolver: https://example.com/snapshots/2018-01-01.yaml
20+
resolver: lts-18.16
21+
22+
# User packages to be built.
23+
# Various formats can be used as shown in the example below.
24+
#
25+
# packages:
26+
# - some-directory
27+
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
28+
# subdirs:
29+
# - auto-update
30+
# - wai
31+
packages:
32+
- .
33+
# Dependency packages to be pulled from upstream that are not in the resolver.
34+
# These entries can reference officially published versions as well as
35+
# forks / in-progress versions pinned to a git hash. For example:
36+
#
37+
# extra-deps:
38+
# - acme-missiles-0.3
39+
# - git: https://github.com/commercialhaskell/stack.git
40+
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
41+
#
42+
# extra-deps: []
43+
44+
# Override default flag values for local packages and extra-deps
45+
# flags: {}
46+
47+
# Extra package databases containing global packages
48+
# extra-package-dbs: []
49+
50+
# Control whether we use the GHC we find on the path
51+
# system-ghc: true
52+
#
53+
# Require a specific version of stack, using version ranges
54+
# require-stack-version: -any # Default
55+
# require-stack-version: ">=2.7"
56+
#
57+
# Override the architecture used by stack, especially useful on Windows
58+
# arch: i386
59+
# arch: x86_64
60+
#
61+
# Extra directories used by stack for building
62+
# extra-include-dirs: [/path/to/dir]
63+
# extra-lib-dirs: [/path/to/dir]
64+
#
65+
# Allow a newer minor version of GHC than the snapshot specifies
66+
# compiler-check: newer-minor

stack.yaml.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file was autogenerated by Stack.
2+
# You should not edit this file by hand.
3+
# For more information, please see the documentation at:
4+
# https://docs.haskellstack.org/en/stable/lock_files
5+
6+
packages: []
7+
snapshots:
8+
- completed:
9+
size: 586286
10+
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/16.yaml
11+
sha256: cdead65fca0323144b346c94286186f4969bf85594d649c49c7557295675d8a5
12+
original: lts-18.16

tests/LinksSpec.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module LinksSpec(linksSpec) where
2+
import System.PosixCompat ( createSymbolicLink, removeLink, fileExist )
3+
import Test.Hspec
4+
import Test.HUnit
5+
import System.IO.Error (tryIOError)
6+
import System.Info(os)
7+
import Control.Monad.Extra (whenM)
8+
9+
isWindows :: Bool
10+
isWindows = os == "mingw32"
11+
12+
linksSpec :: Spec
13+
linksSpec = describe "createSymbolicLink" $ do
14+
it "should error on Windows and succeed on other OSes" $ do
15+
whenM (fileExist "README2.md") $ removeLink "README2.md"
16+
result <- tryIOError $ createSymbolicLink "README.md" "README2.md"
17+
case result of
18+
Left _ | isWindows -> return ()
19+
Right _ | isWindows -> do
20+
removeLink "README2.md"
21+
assertFailure "Succeeded while expected to fail on Windows"
22+
Left e -> assertFailure $ "Expected to succeed, but failed with " ++ show e
23+
Right _ -> removeLink "README2.md"

tests/MkstempSpec.hs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module MkstempSpec(mkstempSpec) where
2+
import Control.Monad.Parallel
3+
import System.Directory
4+
import System.IO
5+
import System.PosixCompat ( mkstemp )
6+
import Test.Hspec
7+
8+
mkstempSpec :: Spec
9+
mkstempSpec = describe "mkstemp" $ do
10+
it "TODO" $ do
11+
let n = 10000
12+
hSetBuffering stdout NoBuffering
13+
14+
putStr $ "Creating " ++ show n ++ " temp files..."
15+
xs <- replicateM n createTempFile
16+
if length xs == n
17+
then putStrLn "ok"
18+
else putStrLn "FAIL"
19+
20+
putStr "Deleting temp files..."
21+
Control.Monad.Parallel.mapM_ removeFile xs
22+
putStrLn "ok"
23+
24+
createTempFile :: IO FilePath
25+
createTempFile = do
26+
(p,h) <- mkstemp "tempfileXXXXXXX"
27+
hPutStrLn h "this is a temporary file"
28+
hClose h
29+
return p

tests/main.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Main where
2+
3+
import MkstempSpec
4+
import LinksSpec
5+
6+
import Test.Hspec
7+
8+
main :: IO ()
9+
main = hspec $ do
10+
mkstempSpec
11+
linksSpec

tests/mkstemp.hs

Lines changed: 0 additions & 27 deletions
This file was deleted.

unix-compat.cabal

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,71 @@ Library
7171
c-sources: cbits/HsUnixCompat.c
7272
if os(solaris)
7373
cc-options: -DSOLARIS
74+
75+
Test-Suite unix-compat-testsuite
76+
default-language: Haskell2010
77+
type: exitcode-stdio-1.0
78+
hs-source-dirs: tests
79+
ghc-options: -Wall
80+
main-is: main.hs
81+
82+
other-modules:
83+
MkstempSpec
84+
LinksSpec
85+
86+
-- ghc-options:
87+
-- -Wall
88+
-- -fwarn-tabs
89+
-- -funbox-strict-fields
90+
-- -threaded
91+
-- -fno-warn-unused-do-bind
92+
-- -fno-warn-type-defaults
93+
94+
-- extensions:
95+
-- OverloadedStrings
96+
-- ExtendedDefaultRules
97+
98+
-- if flag(lifted)
99+
-- cpp-options: -DLIFTED
100+
101+
build-depends:
102+
unix-compat
103+
, base == 4.*
104+
, monad-parallel
105+
, hspec
106+
, HUnit
107+
, directory
108+
, extra
109+
110+
if os(windows)
111+
-- c-sources:
112+
-- cbits/HsUname.c
113+
-- cbits/mktemp.c
114+
115+
-- extra-libraries: msvcrt
116+
-- build-depends: Win32 >= 2.5.0.0
117+
118+
if flag(old-time)
119+
build-depends: old-time >= 1.0.0.0 && < 1.2.0.0
120+
cpp-options: -DOLD_TIME
121+
122+
if impl(ghc < 7)
123+
build-depends: directory == 1.0.*
124+
cpp-options: -DDIRECTORY_1_0
125+
else
126+
build-depends: directory == 1.1.*
127+
else
128+
build-depends: time >= 1.0 && < 1.10
129+
build-depends: directory >= 1.2 && < 1.4
130+
131+
-- other-modules:
132+
-- System.PosixCompat.Internal.Time
133+
134+
else
135+
-- build-depends: unix >= 2.4 && < 2.9
136+
-- include-dirs: include
137+
-- includes: HsUnixCompat.h
138+
-- install-includes: HsUnixCompat.h
139+
-- c-sources: cbits/HsUnixCompat.c
140+
if os(solaris)
141+
cc-options: -DSOLARIS

0 commit comments

Comments
 (0)