From a1e9cd6af8b41fa451fd3be806f4aced0040a14c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= <omeragacan@gmail.com>
Date: Thu, 17 Jan 2019 16:57:20 +0300
Subject: [PATCH] Add test for #16197

---
 testsuite/tests/stranal/should_run/Makefile   |  8 ++++++
 testsuite/tests/stranal/should_run/T16197.hs  | 25 +++++++++++++++++++
 .../tests/stranal/should_run/T16197.stdout    |  2 ++
 testsuite/tests/stranal/should_run/all.T      |  5 +++-
 4 files changed, 39 insertions(+), 1 deletion(-)
 create mode 100644 testsuite/tests/stranal/should_run/T16197.hs
 create mode 100644 testsuite/tests/stranal/should_run/T16197.stdout

diff --git a/testsuite/tests/stranal/should_run/Makefile b/testsuite/tests/stranal/should_run/Makefile
index 9101fbd40ada..dae01b4bb58c 100644
--- a/testsuite/tests/stranal/should_run/Makefile
+++ b/testsuite/tests/stranal/should_run/Makefile
@@ -1,3 +1,11 @@
 TOP=../../..
 include $(TOP)/mk/boilerplate.mk
 include $(TOP)/mk/test.mk
+
+.PHONY: T16197
+T16197:
+	'$(TEST_HC)' -O0 -v0 T16197.hs
+	./T16197
+	rm T16197.o T16197.hi T16197
+	'$(TEST_HC)' -O1 -v0 T16197.hs
+	./T16197
diff --git a/testsuite/tests/stranal/should_run/T16197.hs b/testsuite/tests/stranal/should_run/T16197.hs
new file mode 100644
index 000000000000..a1ab333d1016
--- /dev/null
+++ b/testsuite/tests/stranal/should_run/T16197.hs
@@ -0,0 +1,25 @@
+import System.IO.Unsafe (unsafePerformIO)
+
+data T = T !Bool
+data Box a = Box a
+
+f :: Int -> T -> Box Bool
+f n t
+  | n <= 0 = case t of
+      T b -> Box b
+  | otherwise = f (n-2) t
+
+f1 :: Int -> Bool -> Box Bool
+f1 n t
+  | n <= 0 = f (-n) $! T t
+  | otherwise = f1 (n-2) t
+
+g :: Int -> Bool
+g k = if k <= 0
+        then unsafePerformIO (putStrLn "Evaluated True" >> return True)
+        else unsafePerformIO (putStrLn "Evaluated False" >> return False)
+{-# NOINLINE g #-}
+
+main :: IO ()
+main = case f1 4 (g 0) of
+    Box _ -> return ()
diff --git a/testsuite/tests/stranal/should_run/T16197.stdout b/testsuite/tests/stranal/should_run/T16197.stdout
new file mode 100644
index 000000000000..0eb67824f7b3
--- /dev/null
+++ b/testsuite/tests/stranal/should_run/T16197.stdout
@@ -0,0 +1,2 @@
+Evaluated True
+Evaluated True
diff --git a/testsuite/tests/stranal/should_run/all.T b/testsuite/tests/stranal/should_run/all.T
index a9cc3d70711f..51b1e41143a6 100644
--- a/testsuite/tests/stranal/should_run/all.T
+++ b/testsuite/tests/stranal/should_run/all.T
@@ -1,4 +1,7 @@
-# Optimised only, we're testing the strictness analyser here
+# Run this always
+test('T16197', normal, run_command, ['$MAKE -s --no-print-directory T16197'])
+
+# Run the rest only in optasm way, we're testing the strictness analyser here
 setTestOpts( only_ways(['optasm']) )
 
 test('strun001', normal, compile_and_run, [''])
-- 
GitLab