Skip to content

Commit bc54cce

Browse files
authored
Merge pull request #229 from bgamari/fix-T227
Addresses #227 and #221
2 parents 0b507a3 + a19121e commit bc54cce

File tree

6 files changed

+141
-72
lines changed

6 files changed

+141
-72
lines changed

.travis.yml

Lines changed: 111 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This Travis job script has been generated by a script via
22
#
3-
# make_travis_yml_2.hs '-o' '.travis.yml' 'text.cabal'
3+
# runghc make_travis_yml_2.hs 'text.cabal'
44
#
55
# For more information, see https://github.com/hvr/multi-ghc-travis
66
#
@@ -11,6 +11,9 @@ sudo: false
1111
notifications:
1212
email: false
1313

14+
git:
15+
submodules: false # whether to recursively clone submodules
16+
1417
cache:
1518
directories:
1619
- $HOME/.cabal/packages
@@ -25,87 +28,129 @@ before_cache:
2528
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar
2629
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx
2730

31+
- rm -rfv $HOME/.cabal/packages/head.hackage
32+
2833
matrix:
2934
include:
30-
- compiler: "ghc-7.0.4"
31-
# env: TEST=--disable-tests BENCH=--disable-benchmarks
32-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.0.4], sources: [hvr-ghc]}}
33-
- compiler: "ghc-7.2.2"
35+
- compiler: "ghc-8.6.1"
36+
env: GHCHEAD=true
37+
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.6.1], sources: [hvr-ghc]}}
38+
- compiler: "ghc-8.4.3"
39+
# Fails due to GHC #15436
40+
env: TEST=--disable-tests BENCH=--disable-benchmarks
41+
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-8.4.3], sources: [hvr-ghc]}}
42+
- compiler: "ghc-8.2.2"
3443
# env: TEST=--disable-tests BENCH=--disable-benchmarks
35-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.2.2], sources: [hvr-ghc]}}
36-
- compiler: "ghc-7.4.2"
44+
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-8.2.2], sources: [hvr-ghc]}}
45+
- compiler: "ghc-8.0.2"
3746
# env: TEST=--disable-tests BENCH=--disable-benchmarks
38-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.4.2], sources: [hvr-ghc]}}
39-
- compiler: "ghc-7.6.3"
47+
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-8.0.2], sources: [hvr-ghc]}}
48+
- compiler: "ghc-7.10.3"
4049
# env: TEST=--disable-tests BENCH=--disable-benchmarks
41-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.6.3], sources: [hvr-ghc]}}
50+
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-7.10.3], sources: [hvr-ghc]}}
4251
- compiler: "ghc-7.8.4"
4352
# env: TEST=--disable-tests BENCH=--disable-benchmarks
44-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.8.4], sources: [hvr-ghc]}}
45-
- compiler: "ghc-7.10.3"
53+
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-7.8.4], sources: [hvr-ghc]}}
54+
- compiler: "ghc-7.6.3"
4655
# env: TEST=--disable-tests BENCH=--disable-benchmarks
47-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.10.3], sources: [hvr-ghc]}}
48-
- compiler: "ghc-8.0.2"
56+
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-7.6.3], sources: [hvr-ghc]}}
57+
- compiler: "ghc-7.4.2"
4958
# env: TEST=--disable-tests BENCH=--disable-benchmarks
50-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.0.2], sources: [hvr-ghc]}}
51-
- compiler: "ghc-8.2.2"
59+
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-7.4.2], sources: [hvr-ghc]}}
60+
- compiler: "ghc-7.2.2"
61+
# env: TEST=--disable-tests BENCH=--disable-benchmarks
62+
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-7.2.2], sources: [hvr-ghc]}}
63+
- compiler: "ghc-7.0.4"
5264
# env: TEST=--disable-tests BENCH=--disable-benchmarks
53-
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.2.2], sources: [hvr-ghc]}}
65+
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-7.0.4], sources: [hvr-ghc]}}
66+
67+
allow_failures:
68+
- compiler: "ghc-8.6.1"
5469

5570
before_install:
56-
- HC=${CC}
57-
- HCPKG=${HC/ghc/ghc-pkg}
58-
- unset CC
59-
- PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$PATH
60-
- PKGNAME='text'
71+
- HC=${CC}
72+
- HCPKG=${HC/ghc/ghc-pkg}
73+
- unset CC
74+
- ROOTDIR=$(pwd)
75+
- mkdir -p $HOME/.local/bin
76+
- "PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$HOME/local/bin:$PATH"
77+
- HCNUMVER=$(( $(${HC} --numeric-version|sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1 * 10000 + \2 * 100 + \3/') ))
78+
- echo $HCNUMVER
6179

6280
install:
63-
- cabal --version
64-
- echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
65-
- BENCH=${BENCH---enable-benchmarks}
66-
- TEST=${TEST---enable-tests}
67-
- HADDOCK=${HADDOCK-true}
68-
- INSTALLED=${INSTALLED-true}
69-
- travis_retry cabal update -v
70-
- sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
71-
- rm -fv cabal.project.local
72-
- "echo 'packages: .' > cabal.project"
73-
- rm -f cabal.project.freeze
74-
- cabal new-build -w ${HC} ${TEST} ${BENCH} --dep -j2 all
75-
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks --dep -j2 all
81+
- cabal --version
82+
- echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
83+
- BENCH=${BENCH---enable-benchmarks}
84+
- TEST=${TEST---enable-tests}
85+
- HADDOCK=${HADDOCK-true}
86+
- UNCONSTRAINED=${UNCONSTRAINED-true}
87+
- NOINSTALLEDCONSTRAINTS=${NOINSTALLEDCONSTRAINTS-false}
88+
- GHCHEAD=${GHCHEAD-false}
89+
- travis_retry cabal update -v
90+
- "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config"
91+
- rm -fv cabal.project cabal.project.local
92+
# Overlay Hackage Package Index for GHC HEAD: https://github.com/hvr/head.hackage
93+
- |
94+
if $GHCHEAD; then
95+
sed -i 's/-- allow-newer: .*/allow-newer: *:base/' ${HOME}/.cabal/config
96+
for pkg in $($HCPKG list --simple-output); do pkg=$(echo $pkg | sed 's/-[^-]*$//'); sed -i "s/allow-newer: /allow-newer: *:$pkg, /" ${HOME}/.cabal/config; done
97+
98+
echo 'repository head.hackage' >> ${HOME}/.cabal/config
99+
echo ' url: http://head.hackage.haskell.org/' >> ${HOME}/.cabal/config
100+
echo ' secure: True' >> ${HOME}/.cabal/config
101+
echo ' root-keys: 07c59cb65787dedfaef5bd5f987ceb5f7e5ebf88b904bbd4c5cbdeb2ff71b740' >> ${HOME}/.cabal/config
102+
echo ' 2e8555dde16ebd8df076f1a8ef13b8f14c66bad8eafefd7d9e37d0ed711821fb' >> ${HOME}/.cabal/config
103+
echo ' 8f79fd2389ab2967354407ec852cbe73f2e8635793ac446d09461ffb99527f6e' >> ${HOME}/.cabal/config
104+
echo ' key-threshold: 3' >> ${HOME}/.cabal.config
105+
106+
grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$'
107+
108+
cabal new-update head.hackage -v
109+
fi
110+
- grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$'
111+
- "printf 'packages: \".\"\\n' > cabal.project"
112+
- touch cabal.project.local
113+
- "if ! $NOINSTALLEDCONSTRAINTS; then for pkg in $($HCPKG list --simple-output); do echo $pkg | grep -vw -- text | sed 's/^/constraints: /' | sed 's/-[^-]*$/ installed/' >> cabal.project.local; done; fi"
114+
- cat cabal.project || true
115+
- cat cabal.project.local || true
116+
- if [ -f "./configure.ac" ]; then
117+
(cd "." && autoreconf -i);
118+
fi
119+
- rm -f cabal.project.freeze
120+
- cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 all
121+
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project" --dep -j2 all
122+
- rm -rf .ghc.environment.* "."/dist
123+
- DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)
76124

77125
# Here starts the actual work to be performed for the package under test;
78126
# any command which exits with a non-zero exit code causes the build to fail.
79127
script:
80-
- if [ -f configure.ac ]; then autoreconf -i; fi
81-
- rm -rf .ghc.environment.* dist/
82-
- cabal sdist # test that a source-distribution can be generated
83-
- cd dist/
84-
- SRCTAR=(${PKGNAME}-*.tar.gz)
85-
- SRC_BASENAME="${SRCTAR/%.tar.gz}"
86-
- tar -xvf "./$SRC_BASENAME.tar.gz"
87-
- cd "$SRC_BASENAME/"
88-
## from here on, CWD is inside the extracted source-tarball
89-
- rm -fv cabal.project.local
90-
- "echo 'packages: .' > cabal.project"
91-
# this builds all libraries and executables (without tests/benchmarks)
92-
- rm -f cabal.project.freeze
93-
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks all
94-
# this builds all libraries and executables (including tests/benchmarks)
95-
# - rm -rf ./dist-newstyle
96-
97-
# Build with installed constraints for packages in global-db
98-
- if $INSTALLED; then
99-
echo cabal new-build -w ${HC} --disable-tests --disable-benchmarks $(${HCPKG} list --global --simple-output --names-only | sed 's/\([a-zA-Z0-9-]\{1,\}\) */--constraint="\1 installed" /g') all | sh;
100-
else echo "Not building with installed constraints"; fi
101-
102-
# build & run tests, build benchmarks
103-
- cabal new-build -w ${HC} ${TEST} ${BENCH} all
104-
- if [ "x$TEST" = "x--enable-tests" ]; then cabal new-test -w ${HC} ${TEST} all; fi
105-
106-
# haddock
107-
- rm -rf ./dist-newstyle
108-
- if $HADDOCK; then cabal new-haddock -w ${HC} --disable-tests --disable-benchmarks all; else echo "Skipping haddock generation";fi
109-
110-
# REGENDATA ["-o",".travis.yml","text.cabal"]
128+
# test that source-distributions can be generated
129+
- (cd "." && cabal sdist)
130+
- mv "."/dist/text-*.tar.gz ${DISTDIR}/
131+
- cd ${DISTDIR} || false
132+
- find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \;
133+
- "printf 'packages: text-*/*.cabal\\n' > cabal.project"
134+
- touch cabal.project.local
135+
- "if ! $NOINSTALLEDCONSTRAINTS; then for pkg in $($HCPKG list --simple-output); do echo $pkg | grep -vw -- text | sed 's/^/constraints: /' | sed 's/-[^-]*$/ installed/' >> cabal.project.local; done; fi"
136+
- cat cabal.project || true
137+
- cat cabal.project.local || true
138+
# this builds all libraries and executables (without tests/benchmarks)
139+
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks all
140+
141+
# build & run tests, build benchmarks
142+
- cabal new-build -w ${HC} ${TEST} ${BENCH} all
143+
- if [ "x$TEST" = "x--enable-tests" ]; then cabal new-test -w ${HC} ${TEST} ${BENCH} all; fi
144+
145+
# cabal check
146+
- (cd text-* && cabal check)
147+
148+
# haddock
149+
- rm -rf ./dist-newstyle
150+
- if $HADDOCK; then cabal new-haddock -w ${HC} ${TEST} ${BENCH} all; else echo "Skipping haddock generation";fi
151+
152+
# Build without installed constraints for packages in global-db
153+
- if $UNCONSTRAINED; then rm -f cabal.project.local; echo cabal new-build -w ${HC} --disable-tests --disable-benchmarks all; else echo "Not building without installed constraints"; fi
154+
155+
# REGENDATA ["text.cabal"]
111156
# EOF

Data/Text/Internal/Fusion/Common.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ intersperse c (Stream next0 s0 len) = Stream next (I1 s0) (len + unknownSize)
400400
caseConvert :: (forall s. Char -> s -> Step (CC s) Char)
401401
-> Stream Char -> Stream Char
402402
caseConvert remap (Stream next0 s0 len) =
403-
Stream next (CC s0 '\0' '\0') (len `unionSize` 3*len)
403+
Stream next (CC s0 '\0' '\0') (len `unionSize` (3*len))
404404
where
405405
next (CC s '\0' _) =
406406
case next0 s of
@@ -735,8 +735,10 @@ unfoldrNI n f s0 | n < 0 = empty
735735
-- length of the stream.
736736
take :: Integral a => a -> Stream Char -> Stream Char
737737
take n0 (Stream next0 s0 len) =
738-
Stream next (n0 :*: s0) (smaller len (codePointsSize $ fromIntegral n0))
738+
Stream next (n0' :*: s0) (smaller len (codePointsSize $ fromIntegral n0'))
739739
where
740+
n0' = max n0 0
741+
740742
{-# INLINE next #-}
741743
next (n :*: s) | n <= 0 = Done
742744
| otherwise = case next0 s of
@@ -753,8 +755,10 @@ data Drop a s = NS !s
753755
-- is greater than the length of the stream.
754756
drop :: Integral a => a -> Stream Char -> Stream Char
755757
drop n0 (Stream next0 s0 len) =
756-
Stream next (JS n0 s0) (len - codePointsSize (fromIntegral n0))
758+
Stream next (JS n0' s0) (len - codePointsSize (fromIntegral n0'))
757759
where
760+
n0' = max n0 0
761+
758762
{-# INLINE next #-}
759763
next (JS n s)
760764
| n <= 0 = Skip (NS s)

Data/Text/Internal/Fusion/Size.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ charSize c
6161

6262
-- | The 'Size' of @n@ code points.
6363
codePointsSize :: Int -> Size
64-
codePointsSize n = Between n (2*n)
64+
codePointsSize n =
65+
#if defined(ASSERTS)
66+
assert (n >= 0)
67+
#endif
68+
Between n (2*n)
6569
{-# INLINE codePointsSize #-}
6670

6771
exactSize :: Int -> Size

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
-- See http://cabal.readthedocs.io/en/latest/nix-local-build-overview.html
2-
packages: .
2+
packages: ., benchmarks
33
tests: True

tests/Tests/Regressions.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Tests.Regressions
77
) where
88

99
import Control.Exception (SomeException, handle)
10+
import Data.Char (isLetter)
1011
import System.IO
1112
import Test.HUnit (assertBool, assertEqual, assertFailure)
1213
import qualified Data.ByteString as B
@@ -82,6 +83,18 @@ t197 =
8283
cond = length fltr
8384
fltr = filter (== ',') x
8485

86+
t221 :: IO ()
87+
t221 =
88+
assertEqual "toLower of large input shouldn't crash"
89+
(T.toLower (T.replicate 200000 "0") `seq` ())
90+
()
91+
92+
t227 :: IO ()
93+
t227 =
94+
assertEqual "take (-3) shouldn't crash with overflow"
95+
(T.length $ T.filter isLetter $ T.take (-3) "Hello! How are you doing today?")
96+
0
97+
8598
tests :: F.Test
8699
tests = F.testGroup "Regressions"
87100
[ F.testCase "hGetContents_crash" hGetContents_crash
@@ -90,4 +103,6 @@ tests = F.testGroup "Regressions"
90103
, F.testCase "replicate_crash" replicate_crash
91104
, F.testCase "utf8_decode_unsafe" utf8_decode_unsafe
92105
, F.testCase "t197" t197
106+
, F.testCase "t221" t221
107+
, F.testCase "t227" t227
93108
]

text.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ copyright: 2009-2011 Bryan O'Sullivan, 2008-2009 Tom Harper
4242
category: Data, Text
4343
build-type: Simple
4444
cabal-version: >= 1.8
45-
tested-with: GHC==8.2.2, GHC==8.0.2, GHC==7.10.3, GHC==7.8.4,
45+
tested-with: GHC==8.6.1, GHC==8.4.3,
46+
GHC==8.2.2, GHC==8.0.2, GHC==7.10.3, GHC==7.8.4,
4647
GHC==7.6.3, GHC==7.4.2, GHC==7.2.2, GHC==7.0.4
4748
extra-source-files:
4849
-- scripts/CaseFolding.txt

0 commit comments

Comments
 (0)