From c9809b3a5bb44c35f60ebfaa5a58a71d7647dcce Mon Sep 17 00:00:00 2001 From: Spencer Janssen Date: Tue, 5 Mar 2024 15:33:20 -0600 Subject: [PATCH 1/2] Run tests with and without no-double-conversion --- .github/workflows/haskell-ci.yml | 63 ++++++++++++++++++++++---------- cabal.haskell-ci | 9 +++++ 2 files changed, 53 insertions(+), 19 deletions(-) create mode 100644 cabal.haskell-ci diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index b8ba3cd..ea9c272 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -8,9 +8,9 @@ # # For more information, see https://github.com/haskell-CI/haskell-ci # -# version: 0.14.3 +# version: 0.18.1 # -# REGENDATA ("0.14.3",["github","formatting.cabal"]) +# REGENDATA ("0.18.1",["github","formatting.cabal"]) # name: Haskell-CI on: @@ -19,7 +19,7 @@ on: jobs: linux: name: Haskell-CI - Linux - ${{ matrix.compiler }} - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 timeout-minutes: 60 container: @@ -66,18 +66,18 @@ jobs: apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5 if [ "${{ matrix.setup-method }}" = ghcup ]; then mkdir -p "$HOME/.ghcup/bin" - curl -sL https://downloads.haskell.org/ghcup/0.1.17.5/x86_64-linux-ghcup-0.1.17.5 > "$HOME/.ghcup/bin/ghcup" + curl -sL https://downloads.haskell.org/ghcup/0.1.20.0/x86_64-linux-ghcup-0.1.20.0 > "$HOME/.ghcup/bin/ghcup" chmod a+x "$HOME/.ghcup/bin/ghcup" - "$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" - "$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0 + "$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false) + "$HOME/.ghcup/bin/ghcup" install cabal 3.10.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false) else apt-add-repository -y 'ppa:hvr/ghc' apt-get update apt-get install -y "$HCNAME" mkdir -p "$HOME/.ghcup/bin" - curl -sL https://downloads.haskell.org/ghcup/0.1.17.5/x86_64-linux-ghcup-0.1.17.5 > "$HOME/.ghcup/bin/ghcup" + curl -sL https://downloads.haskell.org/ghcup/0.1.20.0/x86_64-linux-ghcup-0.1.20.0 > "$HOME/.ghcup/bin/ghcup" chmod a+x "$HOME/.ghcup/bin/ghcup" - "$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0 + "$HOME/.ghcup/bin/ghcup" install cabal 3.10.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false) fi env: HCKIND: ${{ matrix.compilerKind }} @@ -91,17 +91,19 @@ jobs: echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV" HCDIR=/opt/$HCKIND/$HCVER if [ "${{ matrix.setup-method }}" = ghcup ]; then - HC=$HOME/.ghcup/bin/$HCKIND-$HCVER + HC=$("$HOME/.ghcup/bin/ghcup" whereis ghc "$HCVER") + HCPKG=$(echo "$HC" | sed 's#ghc$#ghc-pkg#') + HADDOCK=$(echo "$HC" | sed 's#ghc$#haddock#') echo "HC=$HC" >> "$GITHUB_ENV" - echo "HCPKG=$HOME/.ghcup/bin/$HCKIND-pkg-$HCVER" >> "$GITHUB_ENV" - echo "HADDOCK=$HOME/.ghcup/bin/haddock-$HCVER" >> "$GITHUB_ENV" - echo "CABAL=$HOME/.ghcup/bin/cabal-3.6.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" + echo "HCPKG=$HCPKG" >> "$GITHUB_ENV" + echo "HADDOCK=$HADDOCK" >> "$GITHUB_ENV" + echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" else HC=$HCDIR/bin/$HCKIND echo "HC=$HC" >> "$GITHUB_ENV" echo "HCPKG=$HCDIR/bin/$HCKIND-pkg" >> "$GITHUB_ENV" echo "HADDOCK=$HCDIR/bin/haddock" >> "$GITHUB_ENV" - echo "CABAL=$HOME/.ghcup/bin/cabal-3.6.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" + echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" fi HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))') @@ -153,14 +155,14 @@ jobs: - name: install cabal-plan run: | mkdir -p $HOME/.cabal/bin - curl -sL https://github.com/haskell-hvr/cabal-plan/releases/download/v0.6.2.0/cabal-plan-0.6.2.0-x86_64-linux.xz > cabal-plan.xz - echo 'de73600b1836d3f55e32d80385acc055fd97f60eaa0ab68a755302685f5d81bc cabal-plan.xz' | sha256sum -c - + curl -sL https://github.com/haskell-hvr/cabal-plan/releases/download/v0.7.3.0/cabal-plan-0.7.3.0-x86_64-linux.xz > cabal-plan.xz + echo 'f62ccb2971567a5f638f2005ad3173dba14693a45154c1508645c52289714cb2 cabal-plan.xz' | sha256sum -c - xz -d < cabal-plan.xz > $HOME/.cabal/bin/cabal-plan rm -f cabal-plan.xz chmod a+x $HOME/.cabal/bin/cabal-plan cabal-plan --version - name: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: source - name: initial cabal.project for sdist @@ -195,8 +197,8 @@ jobs: run: | $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dry-run all cabal-plan - - name: cache - uses: actions/cache@v2 + - name: restore cache + uses: actions/cache/restore@v3 with: key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }} path: ~/.cabal/store @@ -220,8 +222,31 @@ jobs: ${CABAL} -vnormal check - name: haddock run: | - $CABAL v2-haddock $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all + $CABAL v2-haddock --disable-documentation --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all - name: unconstrained build run: | rm -f cabal.project.local $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all + - name: prepare for constraint sets + run: | + rm -f cabal.project.local + - name: constraint set no-double-conversion + run: | + $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='formatting +no-double-conversion' all --dry-run + cabal-plan topo | sort + $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='formatting +no-double-conversion' --dependencies-only -j2 all + $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='formatting +no-double-conversion' all + $CABAL v2-test $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='formatting +no-double-conversion' all + - name: constraint set double-conversion + run: | + $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='formatting -no-double-conversion' all --dry-run + cabal-plan topo | sort + $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='formatting -no-double-conversion' --dependencies-only -j2 all + $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='formatting -no-double-conversion' all + $CABAL v2-test $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='formatting -no-double-conversion' all + - name: save cache + uses: actions/cache/save@v3 + if: always() + with: + key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }} + path: ~/.cabal/store diff --git a/cabal.haskell-ci b/cabal.haskell-ci new file mode 100644 index 0000000..757c453 --- /dev/null +++ b/cabal.haskell-ci @@ -0,0 +1,9 @@ +constraint-set double-conversion + constraints: formatting -no-double-conversion + tests: True + run-tests: True + +constraint-set no-double-conversion + constraints: formatting +no-double-conversion + tests: True + run-tests: True From c351d744abcebd1a53a1213b7e6560b0fa2e88ff Mon Sep 17 00:00:00 2001 From: Spencer Janssen Date: Tue, 5 Mar 2024 15:37:03 -0600 Subject: [PATCH 2/2] Fix crash on negative integers Resolves #85 --- src/Data/Text/Format.hs | 7 +++---- test/Spec.hs | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Data/Text/Format.hs b/src/Data/Text/Format.hs index 652fb61..d544131 100644 --- a/src/Data/Text/Format.hs +++ b/src/Data/Text/Format.hs @@ -73,10 +73,9 @@ shortest = fromString . toShortest . realToFrac where toShortest :: Double -> String toShortest dbl = - -- `showFFloat (Just 0) "" 1.0` gives "1.", but we want "1" - let intPart = (floor dbl :: Int) in - if dbl == (fromIntegral intPart) - then showInt intPart "" + let intPart = fromIntegral (floor dbl :: Int) in + if dbl == intPart + then showFFloat (Just 0) intPart "" else showFFloat Nothing dbl "" #endif {-# INLINE shortest #-} diff --git a/test/Spec.hs b/test/Spec.hs index 7d4854c..799438d 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -49,6 +49,7 @@ spec = do it "Fixed" $ format (fixed 4) (12.123456 :: Double) `shouldBe` "12.1235" it "Variable" $ format float (12.123456 :: Double) `shouldBe` "12.123456" it "Shortest" $ format shortest (12.0000 :: Double) `shouldBe` "12" + it "Negative" $ format float (-1.0000 :: Double) `shouldBe` "-1" describe "Scientific" $ do it "sci" $ format sci (scientific 60221409 16) `shouldBe` "6.0221409e23"