Skip to content

'stack test' not referentially transparent #525

Closed
@pharpend

Description

@pharpend

Edit: By the way, I have the latest git version of stack, as of 8:50 AM MDT, 2015-07-06.

Full tree: https://github.com/pharpend/comarkdown.

Here is my lovely test suite, with some compiler errors:

{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Trustworthy #-}

-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or (at
-- your option) any later version.
-- 
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-- General Public License for more details.
-- 
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.

-- | 
-- Module      : Main
-- Description : The test suite for comarkdown
-- Copyright   : Copyright 2015 Peter Harpending.
-- License     : GPL-3
-- Maintainer  : peter@harpending.org
-- Stability   : experimental
-- Portability : portable

module Main where

import Data.ByteString.Lazy.Char8 (ByteString)
import qualified Data.ByteString.Lazy.Char8 as B
import Text.Comarkdown
import Test.Hspec
import Test.QuickCheck

main :: IO ()
main = hspec $ context "Parsing" $ context "Recognizing bare headers" $ header1Tests

header1Tests :: Spec
header1Tests = context "Header1" $ parallel $ do
  runParseTest "'# something' should be an h1" "# something" $
    (Right [Markdown (Header1 "something")])
  runParseTest "'something\\n====' should be an h1" "something\n===="
    (Right [Markdown (Header1 "something")])
  runParseTest "'something\\n====' should be an h1" "something\n===="
    (Right [Markdown (Header1 "something")])
  runParseTest "'something\\n=' should be an H1" "something\n="
    (Right [Markdown (Header1 "something")])
  runParseTest
    "'# something\\n====' should be an h1 with the '='s as part of the header"
    "# something\n===="
    (Right [Markdown (Header1 "something ====")])
  runParseTest "'# something #' should be an h1" "# something #"
    (Right [Markdown (Header1 "something")])
  runParseTest "'# something ####' should be an h1" "# something ####"
    (Right [Markdown (Header1 "something")])
  specify "'# something' with trailing spaces should be an h1" $
    property $
      \(Nat i) -> do
        let s = mappend "# something" (replicate i ' ')
        parseResult <- runIO $ parse "test" (B.pack s)
        parseResult `shouldBe` Right [Markdown (Header1 "something")]
  specify "'# something #' with trailing spaces should be an h1" $
    property $
      \(Nat i) -> do
        let s = mappend "# something #" (replicate i ' ')
        parseResult <- runIO $ parse "test" (B.pack s)
        parseResult `shouldBe` Right [Markdown (Header1 "something")]
  specify "'# something ' with trailing '#'s should be an h1" $
    property $
      \(Nat i) -> do
        let s = mappend "# something " (replicate i '#')
        parseResult <- runIO $ parse "test" (B.pack s)
        parseResult `shouldBe` Right [Markdown (Header1 "something")]
  specify
    "'# something ' with trailing spaces, trailing '#'s, and more trailing spaces should be an h1" $
    property $
      \((Nat i, Nat j, Nat k)) -> do
        let s = mconcat ["# something ", replicate i ' ', replicate j '#', replicate k ' ']
        parseResult <- runIO $ parse "test" (B.pack s)
        parseResult `shouldBe` Right [Markdown (Header1 "something")]

runParseTest :: String -> ByteString -> Either String Document -> Spec
runParseTest spec bs supposedResult = it spec $ do
  res <- runIO $ parse "test input" bs
  res `shouldBe` supposedResult

newtype Nat = Nat {unNat :: Int}

instance Arbitrary Nat where
  arbitrary = Nat <$> (suchThat arbitrary (>= 0))

If I try to pipe the result of stack test to a pastebin, this is what shows up on the pastebin:

comarkdown-0.1.0.0: test (suite: spec)

Parsing
  Recognizing bare headers
    Header1
      '# something' should be an h1 FAILED [1]
      'something\n====' should be an h1 FAILED [2]
      'something\n====' should be an h1 FAILED [3]
      'something\n=' should be an H1 FAILED [4]
      '# something\n====' should be an h1 with the '='s as part of the header FAILED [5]
      '# something #' should be an h1 FAILED [6]
      '# something ####' should be an h1 FAILED [7]
      '# something' with trailing spaces should be an h1 FAILED [8]

Failures:

  1) Parsing, Recognizing bare headers, Header1, '# something' should be an h1
       uncaught exception: ErrorCall (Prelude.undefined)

  2) Parsing, Recognizing bare headers, Header1, 'something\n====' should be an h1
       uncaught exception: ErrorCall (Prelude.undefined)

  3) Parsing, Recognizing bare headers, Header1, 'something\n====' should be an h1
       uncaught exception: ErrorCall (Prelude.undefined)

  4) Parsing, Recognizing bare headers, Header1, 'something\n=' should be an H1
       uncaught exception: ErrorCall (Prelude.undefined)

  5) Parsing, Recognizing bare headers, Header1, '# something\n====' should be an h1 with the '='s as part of the header
       uncaught exception: ErrorCall (Prelude.undefined)

  6) Parsing, Recognizing bare headers, Header1, '# something #' should be an h1
       uncaught exception: ErrorCall (Prelude.undefined)

  7) Parsing, Recognizing bare headers, Header1, '# something ####' should be an h1
       uncaught exception: ErrorCall (Prelude.undefined)

  8) Parsing, Recognizing bare headers, Header1, '# something' with trailing spaces should be an h1
       uncaught exception: ErrorCall (Prelude.undefined)

Randomized with seed 872476737

Finished in 0.0006 seconds
8 examples, 8 failures
Test suite failure for package comarkdown-0.1.0.0
    spec:  exited with: ExitFailure 1
Logs printed to console

That is, the output of the last successfully built test suite.

If I don't change the test suite, and try to run stack test again, I get the same output.

However, before attempting to pipe the output of stack test to a pastebin, the output was this:

comarkdown-0.1.0.0: build (test)
Preprocessing library comarkdown-0.1.0.0...
In-place registering comarkdown-0.1.0.0...
Preprocessing test suite 'spec' for comarkdown-0.1.0.0...
[1 of 1] Compiling Main             ( spec/Spec.hs, .stack-work/dist/x86_64-linux/Cabal-1.22.2.0/build/spec/spec-tmp/Main.o )

spec/Spec.hs:61:9:
    Couldn't match type ‘IO’
                   with ‘hspec-core-2.1.7:Test.Hspec.Core.Spec.Monad.SpecM a1’
    Expected type: hspec-core-2.1.7:Test.Hspec.Core.Spec.Monad.SpecM
                     a1 ()
      Actual type: Expectation
    In a stmt of a 'do' block:
      parseResult `shouldBe` Right [Markdown (Header1 "something")]
    In the expression:
      do { let s = mappend "# something" (replicate i ' ');
           parseResult <- runIO $ parse "test" (B.pack s);
           parseResult `shouldBe` Right [Markdown (Header1 "something")] }
    In the second argument of ‘($)’, namely
      ‘\ (Nat i)
         -> do { let ...;
                 parseResult <- runIO $ parse "test" (B.pack s);
                 .... }’

spec/Spec.hs:67:9:
    Couldn't match type ‘IO’
                   with ‘hspec-core-2.1.7:Test.Hspec.Core.Spec.Monad.SpecM a2’
    Expected type: hspec-core-2.1.7:Test.Hspec.Core.Spec.Monad.SpecM
                     a2 ()
      Actual type: Expectation
    In a stmt of a 'do' block:
      parseResult `shouldBe` Right [Markdown (Header1 "something")]
    In the expression:
      do { let s = mappend "# something #" (replicate i ' ');
           parseResult <- runIO $ parse "test" (B.pack s);
           parseResult `shouldBe` Right [Markdown (Header1 "something")] }
    In the second argument of ‘($)’, namely
      ‘\ (Nat i)
         -> do { let ...;
                 parseResult <- runIO $ parse "test" (B.pack s);
                 .... }’

spec/Spec.hs:73:9:
    Couldn't match type ‘IO’
                   with ‘hspec-core-2.1.7:Test.Hspec.Core.Spec.Monad.SpecM a3’
    Expected type: hspec-core-2.1.7:Test.Hspec.Core.Spec.Monad.SpecM
                     a3 ()
      Actual type: Expectation
    In a stmt of a 'do' block:
      parseResult `shouldBe` Right [Markdown (Header1 "something")]
    In the expression:
      do { let s = mappend "# something " (replicate i '#');
           parseResult <- runIO $ parse "test" (B.pack s);
           parseResult `shouldBe` Right [Markdown (Header1 "something")] }
    In the second argument of ‘($)’, namely
      ‘\ (Nat i)
         -> do { let ...;
                 parseResult <- runIO $ parse "test" (B.pack s);
                 .... }’

spec/Spec.hs:80:9:
    Couldn't match type ‘IO’
                   with ‘hspec-core-2.1.7:Test.Hspec.Core.Spec.Monad.SpecM a4’
    Expected type: hspec-core-2.1.7:Test.Hspec.Core.Spec.Monad.SpecM
                     a4 ()
      Actual type: Expectation
    In a stmt of a 'do' block:
      parseResult `shouldBe` Right [Markdown (Header1 "something")]
    In the expression:
      do { let s = mconcat ...;
           parseResult <- runIO $ parse "test" (B.pack s);
           parseResult `shouldBe` Right [Markdown (Header1 "something")] }
    In the second argument of ‘($)’, namely
      ‘\ ((Nat i, Nat j, Nat k))
         -> do { let ...;
                 parseResult <- runIO $ parse "test" (B.pack s);
                 .... }’

spec/Spec.hs:85:3:
    Couldn't match type ‘IO’
                   with ‘hspec-core-2.1.7:Test.Hspec.Core.Spec.Monad.SpecM a0’
    Expected type: hspec-core-2.1.7:Test.Hspec.Core.Spec.Monad.SpecM
                     a0 ()
      Actual type: Expectation
    In a stmt of a 'do' block: res `shouldBe` supposedResult
    In the second argument of ‘($)’, namely
      ‘do { res <- runIO $ parse "test input" bs;
            res `shouldBe` supposedResult }’
    In the expression:
      it spec
      $ do { res <- runIO $ parse "test input" bs;
             res `shouldBe` supposedResult }

--  While building package comarkdown-0.1.0.0 using:
      /usr/bin/runhaskell -package=Cabal-1.22.2.0 -clear-package-db -global-package-db -package-db=/home/pete/.stack/snapshots/x86_64-linux/nightly-2015-07-03/7.10.1/pkgdb/ /tmp/stack16906/Setup.hs --builddir=.stack-work/dist/x86_64-linux/Cabal-1.22.2.0/ build test:spec
    Process exited with code: ExitFailure 1
stack test  2.44s user 1.63s system 163% cpu 2.492 total

If I make a trivial change to the test suite, and run stack test again, I get the compiler-errors output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions