Add testcase for #14178
authorBen Gamari <bgamari.foss@gmail.com>
Fri, 1 Sep 2017 14:52:47 +0000 (10:52 -0400)
committerBen Gamari <ben@smart-cactus.org>
Fri, 1 Sep 2017 14:58:11 +0000 (10:58 -0400)
Reviewers: austin

Subscribers: rwbarton, thomie

GHC Trac Issues: #14178

Differential Revision: https://phabricator.haskell.org/D3905

testsuite/tests/simplCore/should_run/T14178.hs [new file with mode: 0644]
testsuite/tests/simplCore/should_run/T14178.stdout [new file with mode: 0644]
testsuite/tests/simplCore/should_run/all.T

diff --git a/testsuite/tests/simplCore/should_run/T14178.hs b/testsuite/tests/simplCore/should_run/T14178.hs
new file mode 100644 (file)
index 0000000..ef76324
--- /dev/null
@@ -0,0 +1,33 @@
+import System.Exit
+import Control.Monad.Trans.State.Strict
+
+eval :: Int -> State Int a -> a
+eval p = fst . flip runState p
+
+advance :: Int -> State Int ()
+advance = modify' . (+)
+
+loc :: State Int Int
+loc = get
+
+emit1 :: State Int ()
+emit1 = advance 1
+
+emitN :: Int -> State Int ()
+-- adding in the 0 case, breaks with HEAD. 8.2.1 is fine with it.
+-- emitN 0 = advance 0
+emitN 0 = pure ()
+emitN n = advance n
+
+align8 :: State Int ()
+align8 = do
+  bits <- (`mod` 8) <$> loc
+  emitN (8 - bits)
+
+main :: IO ()
+main = do
+  let p = eval 0 (emit1 >> align8 >> loc)
+  putStrLn $ show p
+  if p == 8
+    then putStrLn "OK" >> exitSuccess
+    else putStrLn "FAIL" >> exitFailure
diff --git a/testsuite/tests/simplCore/should_run/T14178.stdout b/testsuite/tests/simplCore/should_run/T14178.stdout
new file mode 100644 (file)
index 0000000..f91f66e
--- /dev/null
@@ -0,0 +1,2 @@
+8
+OK
index 75ff431..4ba5a71 100644 (file)
@@ -77,3 +77,4 @@ test('T13733', expect_broken(13733), compile_and_run, [''])
 test('T13429', normal, compile_and_run, [''])
 test('T13429_2', normal, compile_and_run, [''])
 test('T13750', normal, compile_and_run, [''])
+test('T14178', normal, compile_and_run, [''])