Start creating a test suite, migrate old tests
authorJoachim Breitner <mail@joachim-breitner.de>
Sat, 25 Jan 2014 21:29:21 +0000 (21:29 +0000)
committerJoachim Breitner <mail@joachim-breitner.de>
Sat, 25 Jan 2014 21:29:21 +0000 (21:29 +0000)
32 files changed:
arbtt.cabal
test/arbtt-dump_small.case [deleted file]
test/arbtt-import_small.case [deleted file]
test/arbtt-recover_small_borked.case [deleted file]
test/arbtt-stats_small.case [deleted file]
test/arbtt-stats_unicode.case [deleted file]
test/in/categorize.cfg [deleted file]
test/in/small.cfg [deleted file]
test/in/small.log [deleted file]
test/in/small_borked.log [deleted file]
test/in/small_import.in [deleted file]
test/in/unicode.cfg [deleted file]
test/in/unicode.log [deleted file]
test/out/small_borked_recover.out [deleted file]
test/out/small_dump.out [deleted file]
test/out/small_import.out [deleted file]
test/out/small_stats.out [deleted file]
test/out/unicode_stats.out [deleted file]
test/test.sh [deleted file]
tests/categorize.cfg [new file with mode: 0644]
tests/small.cfg [new file with mode: 0644]
tests/small.log [new file with mode: 0644]
tests/small_borked.log [new file with mode: 0644]
tests/small_borked_recover.out [new file with mode: 0644]
tests/small_dump.out [new file with mode: 0644]
tests/small_import.in [new file with mode: 0644]
tests/small_import.out [new file with mode: 0644]
tests/small_stats.out [new file with mode: 0644]
tests/test.hs [new file with mode: 0644]
tests/unicode.cfg [new file with mode: 0644]
tests/unicode.log [new file with mode: 0644]
tests/unicode_stats.out [new file with mode: 0644]

index f7ec75b..e5e44d8 100644 (file)
@@ -150,6 +150,19 @@ executable arbtt-recover
         other-modules:
             System.Locale.SetLocale
 
+test-suite test
+  Type:
+    exitcode-stdio-1.0
+  Hs-source-dirs:
+    tests
+  Main-is:
+    test.hs
+  Build-depends:
+      base >= 4 && < 5
+      , tasty == 0.7.*
+      , tasty-golden == 2.2.*
+      , process-extras == 0.2.*
+
 source-repository head
     type:     darcs
     location: http://darcs.nomeata.de/arbtt
diff --git a/test/arbtt-dump_small.case b/test/arbtt-dump_small.case
deleted file mode 100644 (file)
index 415bb2e..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-name = "arbtt-dump_small"
-call = "../dist/build/arbtt-dump/arbtt-dump -f in/small.log"
-stdin = "/dev/null"
-test = {{ type = "stdout", right = "out/small_dump.out" }}
diff --git a/test/arbtt-import_small.case b/test/arbtt-import_small.case
deleted file mode 100644 (file)
index dd80f5c..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-tmpRepair = tmp()
-
-name = "arbtt-import_small"
-call = "../dist/build/arbtt-import/arbtt-import -f " .. tmpRepair
-stdin = "in/small_import.in"
-test = {{ type = "file", left = tmpRepair, right = "out/small_import.out" }}
diff --git a/test/arbtt-recover_small_borked.case b/test/arbtt-recover_small_borked.case
deleted file mode 100644 (file)
index 214ecbb..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-tmpRecover = tmp()
-
-name = "arbtt-recover_small_borked"
-call = "../dist/build/arbtt-recover/arbtt-recover -i in/small_borked.log -o " .. tmpRecover
-stdin = "/dev/null"
-test = {{ type = "file", left = tmpRecover, right = "out/small_borked_recover.out" }}
diff --git a/test/arbtt-stats_small.case b/test/arbtt-stats_small.case
deleted file mode 100644 (file)
index a0dd203..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-name = "arbtt-stats_small"
-call = "TZ=Ghana/Accra ../dist/build/arbtt-stats/arbtt-stats --logfile in/small.log --categorize in/small.cfg"
-stdin = "/dev/null"
-test = {{ type = "stdout", right = "out/small_stats.out" }}
diff --git a/test/arbtt-stats_unicode.case b/test/arbtt-stats_unicode.case
deleted file mode 100644 (file)
index 385b698..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-name = "arbtt-stats_unicode"
-call = "../dist/build/arbtt-stats/arbtt-stats --categorizefile in/unicode.cfg --logfile in/unicode.log"
-stdin = "/dev/null"
-test = {{ type = "stdout", right = "out/unicode_stats.out" }}
diff --git a/test/in/categorize.cfg b/test/in/categorize.cfg
deleted file mode 100644 (file)
index 03ca2e3..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
--- This defines some aliases, to make the reports look nicer:
-aliases (
-  "sun-awt-X11-XFramePeer"  -> "java",
-  "sun-awt-X11-XDialogPeer" -> "java",
-  "sun-awt-X11-XWindowPeer" -> "java",
-  )
-
--- A rule that probably everybody wants. Being inactive for over a minute
--- causes this sample to be ignored by default.
-$idle > 60 ==> tag inactive,
-
--- Simple rule that just tags the current program
-tag Program:$current.program,
-
--- To be able to match on the time of day, I introduce tags for that as well
-$time >=  2:00 && $time <  8:00 ==> tag time-of-day:night,
-$time >=  8:00 && $time < 12:00 ==> tag time-of-day:morning,
-$time >= 12:00 && $time < 14:00 ==> tag time-of-day:lunchtime,
-$time >= 14:00 && $time < 18:00 ==> tag time-of-day:afternoon,
-$time >= 18:00 && $time < 22:00 ==> tag time-of-day:evening,
-$time >= 22:00 || $time <  2:00 ==> tag time-of-day:late-evening,
-
--- This tag always refers to the last 24h
-$sampleage <= 24:00 ==> tag last-day,
-
diff --git a/test/in/small.cfg b/test/in/small.cfg
deleted file mode 100644 (file)
index 7467f57..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-current window $title =~ m/arbtt/ ==> tag arbtt,
-
-$time < 14:00 ==> tag before_14
-
diff --git a/test/in/small.log b/test/in/small.log
deleted file mode 100644 (file)
index 58849e8..0000000
Binary files a/test/in/small.log and /dev/null differ
diff --git a/test/in/small_borked.log b/test/in/small_borked.log
deleted file mode 100644 (file)
index 903b854..0000000
Binary files a/test/in/small_borked.log and /dev/null differ
diff --git a/test/in/small_import.in b/test/in/small_import.in
deleted file mode 100644 (file)
index 18d2347..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-TimeLogEntry {tlTime = 2010-03-20 13:59:15.075576 UTC, tlRate = 60000, tlData = CaptureData {cWindows = [(False,"stats-main.hs (~/darcs/arbtt/src) - GVIM","gvim"),(False,"`ghci' mrtrac@curie:~ ","urxvt"),(False,"`irssi' mrtrac@curie:~ ","urxvt"),(True,"mrtrac@curie:~/darcs/arbtt ","urxvt"),(False,"`mutt' mrtrac@curie:~ ","urxvt"),(False,"HackageDB: network-bytestring-0.1.2.1 - Vimperator","Navigator")], cLastActivity = 2909}}
-TimeLogEntry {tlTime = 2010-03-20 14:00:15.157669 UTC, tlRate = 60000, tlData = CaptureData {cWindows = [(False,"stats-main.hs (~/darcs/arbtt/src) - GVIM","gvim"),(False,"`ghci' mrtrac@curie:~ ","urxvt"),(False,"`irssi' mrtrac@curie:~ ","urxvt"),(True,"mrtrac@curie:~/darcs/arbtt ","urxvt"),(False,"`mutt' mrtrac@curie:~ ","urxvt"),(False,"HackageDB: network-bytestring-0.1.2.1 - Vimperator","Navigator")], cLastActivity = 557}}
-TimeLogEntry {tlTime = 2010-03-20 14:01:15.220521 UTC, tlRate = 60000, tlData = CaptureData {cWindows = [(False,"stats-main.hs (~/darcs/arbtt/src) - GVIM","gvim"),(False,"`ghci' mrtrac@curie:~ ","urxvt"),(False,"`irssi' mrtrac@curie:~ ","urxvt"),(True,"mrtrac@curie:~/darcs/arbtt ","urxvt"),(False,"`mutt' mrtrac@curie:~ ","urxvt"),(False,"HackageDB: network-bytestring-0.1.2.1 - Vimperator","Navigator")], cLastActivity = 58004}}
diff --git a/test/in/unicode.cfg b/test/in/unicode.cfg
deleted file mode 100644 (file)
index 85509d0..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-any window $title =~ /aäα/ ==> tag ok,
-any window $title =~ /aäƱ/ ==> tag notok,
-
diff --git a/test/in/unicode.log b/test/in/unicode.log
deleted file mode 100644 (file)
index d39b1c8..0000000
Binary files a/test/in/unicode.log and /dev/null differ
diff --git a/test/out/small_borked_recover.out b/test/out/small_borked_recover.out
deleted file mode 100644 (file)
index 58849e8..0000000
Binary files a/test/out/small_borked_recover.out and /dev/null differ
diff --git a/test/out/small_dump.out b/test/out/small_dump.out
deleted file mode 100644 (file)
index 18d2347..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-TimeLogEntry {tlTime = 2010-03-20 13:59:15.075576 UTC, tlRate = 60000, tlData = CaptureData {cWindows = [(False,"stats-main.hs (~/darcs/arbtt/src) - GVIM","gvim"),(False,"`ghci' mrtrac@curie:~ ","urxvt"),(False,"`irssi' mrtrac@curie:~ ","urxvt"),(True,"mrtrac@curie:~/darcs/arbtt ","urxvt"),(False,"`mutt' mrtrac@curie:~ ","urxvt"),(False,"HackageDB: network-bytestring-0.1.2.1 - Vimperator","Navigator")], cLastActivity = 2909}}
-TimeLogEntry {tlTime = 2010-03-20 14:00:15.157669 UTC, tlRate = 60000, tlData = CaptureData {cWindows = [(False,"stats-main.hs (~/darcs/arbtt/src) - GVIM","gvim"),(False,"`ghci' mrtrac@curie:~ ","urxvt"),(False,"`irssi' mrtrac@curie:~ ","urxvt"),(True,"mrtrac@curie:~/darcs/arbtt ","urxvt"),(False,"`mutt' mrtrac@curie:~ ","urxvt"),(False,"HackageDB: network-bytestring-0.1.2.1 - Vimperator","Navigator")], cLastActivity = 557}}
-TimeLogEntry {tlTime = 2010-03-20 14:01:15.220521 UTC, tlRate = 60000, tlData = CaptureData {cWindows = [(False,"stats-main.hs (~/darcs/arbtt/src) - GVIM","gvim"),(False,"`ghci' mrtrac@curie:~ ","urxvt"),(False,"`irssi' mrtrac@curie:~ ","urxvt"),(True,"mrtrac@curie:~/darcs/arbtt ","urxvt"),(False,"`mutt' mrtrac@curie:~ ","urxvt"),(False,"HackageDB: network-bytestring-0.1.2.1 - Vimperator","Navigator")], cLastActivity = 58004}}
diff --git a/test/out/small_import.out b/test/out/small_import.out
deleted file mode 100644 (file)
index 58849e8..0000000
Binary files a/test/out/small_import.out and /dev/null differ
diff --git a/test/out/small_stats.out b/test/out/small_stats.out
deleted file mode 100644 (file)
index a89be1c..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-Total time per tag
-==================
-______Tag_|___Time_|_Percentage_
-    arbtt |  3m00s |     100.00
-before_14 |  1m00s |      33.33
diff --git a/test/out/unicode_stats.out b/test/out/unicode_stats.out
deleted file mode 100644 (file)
index 1701583..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-Total time per tag
-==================
-Tag_|___Time_|_Percentage_
- ok |  1m00s |     100.00
diff --git a/test/test.sh b/test/test.sh
deleted file mode 100644 (file)
index c6ea830..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/bash
-
-cd `dirname $0`
-
-blackbox-test
diff --git a/tests/categorize.cfg b/tests/categorize.cfg
new file mode 100644 (file)
index 0000000..03ca2e3
--- /dev/null
@@ -0,0 +1,25 @@
+-- This defines some aliases, to make the reports look nicer:
+aliases (
+  "sun-awt-X11-XFramePeer"  -> "java",
+  "sun-awt-X11-XDialogPeer" -> "java",
+  "sun-awt-X11-XWindowPeer" -> "java",
+  )
+
+-- A rule that probably everybody wants. Being inactive for over a minute
+-- causes this sample to be ignored by default.
+$idle > 60 ==> tag inactive,
+
+-- Simple rule that just tags the current program
+tag Program:$current.program,
+
+-- To be able to match on the time of day, I introduce tags for that as well
+$time >=  2:00 && $time <  8:00 ==> tag time-of-day:night,
+$time >=  8:00 && $time < 12:00 ==> tag time-of-day:morning,
+$time >= 12:00 && $time < 14:00 ==> tag time-of-day:lunchtime,
+$time >= 14:00 && $time < 18:00 ==> tag time-of-day:afternoon,
+$time >= 18:00 && $time < 22:00 ==> tag time-of-day:evening,
+$time >= 22:00 || $time <  2:00 ==> tag time-of-day:late-evening,
+
+-- This tag always refers to the last 24h
+$sampleage <= 24:00 ==> tag last-day,
+
diff --git a/tests/small.cfg b/tests/small.cfg
new file mode 100644 (file)
index 0000000..7467f57
--- /dev/null
@@ -0,0 +1,4 @@
+current window $title =~ m/arbtt/ ==> tag arbtt,
+
+$time < 14:00 ==> tag before_14
+
diff --git a/tests/small.log b/tests/small.log
new file mode 100644 (file)
index 0000000..58849e8
Binary files /dev/null and b/tests/small.log differ
diff --git a/tests/small_borked.log b/tests/small_borked.log
new file mode 100644 (file)
index 0000000..903b854
Binary files /dev/null and b/tests/small_borked.log differ
diff --git a/tests/small_borked_recover.out b/tests/small_borked_recover.out
new file mode 100644 (file)
index 0000000..885fa2b
Binary files /dev/null and b/tests/small_borked_recover.out differ
diff --git a/tests/small_dump.out b/tests/small_dump.out
new file mode 100644 (file)
index 0000000..47931b8
--- /dev/null
@@ -0,0 +1,3 @@
+TimeLogEntry {tlTime = 2010-03-20 13:59:15.075576 UTC, tlRate = 60000, tlData = CaptureData {cWindows = [(False,"stats-main.hs (~/darcs/arbtt/src) - GVIM","gvim"),(False,"`ghci' mrtrac@curie:~ ","urxvt"),(False,"`irssi' mrtrac@curie:~ ","urxvt"),(True,"mrtrac@curie:~/darcs/arbtt ","urxvt"),(False,"`mutt' mrtrac@curie:~ ","urxvt"),(False,"HackageDB: network-bytestring-0.1.2.1 - Vimperator","Navigator")], cLastActivity = 2909, cDesktop = ""}}
+TimeLogEntry {tlTime = 2010-03-20 14:00:15.157669 UTC, tlRate = 60000, tlData = CaptureData {cWindows = [(False,"stats-main.hs (~/darcs/arbtt/src) - GVIM","gvim"),(False,"`ghci' mrtrac@curie:~ ","urxvt"),(False,"`irssi' mrtrac@curie:~ ","urxvt"),(True,"mrtrac@curie:~/darcs/arbtt ","urxvt"),(False,"`mutt' mrtrac@curie:~ ","urxvt"),(False,"HackageDB: network-bytestring-0.1.2.1 - Vimperator","Navigator")], cLastActivity = 557, cDesktop = ""}}
+TimeLogEntry {tlTime = 2010-03-20 14:01:15.220521 UTC, tlRate = 60000, tlData = CaptureData {cWindows = [(False,"stats-main.hs (~/darcs/arbtt/src) - GVIM","gvim"),(False,"`ghci' mrtrac@curie:~ ","urxvt"),(False,"`irssi' mrtrac@curie:~ ","urxvt"),(True,"mrtrac@curie:~/darcs/arbtt ","urxvt"),(False,"`mutt' mrtrac@curie:~ ","urxvt"),(False,"HackageDB: network-bytestring-0.1.2.1 - Vimperator","Navigator")], cLastActivity = 58004, cDesktop = ""}}
diff --git a/tests/small_import.in b/tests/small_import.in
new file mode 100644 (file)
index 0000000..47931b8
--- /dev/null
@@ -0,0 +1,3 @@
+TimeLogEntry {tlTime = 2010-03-20 13:59:15.075576 UTC, tlRate = 60000, tlData = CaptureData {cWindows = [(False,"stats-main.hs (~/darcs/arbtt/src) - GVIM","gvim"),(False,"`ghci' mrtrac@curie:~ ","urxvt"),(False,"`irssi' mrtrac@curie:~ ","urxvt"),(True,"mrtrac@curie:~/darcs/arbtt ","urxvt"),(False,"`mutt' mrtrac@curie:~ ","urxvt"),(False,"HackageDB: network-bytestring-0.1.2.1 - Vimperator","Navigator")], cLastActivity = 2909, cDesktop = ""}}
+TimeLogEntry {tlTime = 2010-03-20 14:00:15.157669 UTC, tlRate = 60000, tlData = CaptureData {cWindows = [(False,"stats-main.hs (~/darcs/arbtt/src) - GVIM","gvim"),(False,"`ghci' mrtrac@curie:~ ","urxvt"),(False,"`irssi' mrtrac@curie:~ ","urxvt"),(True,"mrtrac@curie:~/darcs/arbtt ","urxvt"),(False,"`mutt' mrtrac@curie:~ ","urxvt"),(False,"HackageDB: network-bytestring-0.1.2.1 - Vimperator","Navigator")], cLastActivity = 557, cDesktop = ""}}
+TimeLogEntry {tlTime = 2010-03-20 14:01:15.220521 UTC, tlRate = 60000, tlData = CaptureData {cWindows = [(False,"stats-main.hs (~/darcs/arbtt/src) - GVIM","gvim"),(False,"`ghci' mrtrac@curie:~ ","urxvt"),(False,"`irssi' mrtrac@curie:~ ","urxvt"),(True,"mrtrac@curie:~/darcs/arbtt ","urxvt"),(False,"`mutt' mrtrac@curie:~ ","urxvt"),(False,"HackageDB: network-bytestring-0.1.2.1 - Vimperator","Navigator")], cLastActivity = 58004, cDesktop = ""}}
diff --git a/tests/small_import.out b/tests/small_import.out
new file mode 100644 (file)
index 0000000..885fa2b
Binary files /dev/null and b/tests/small_import.out differ
diff --git a/tests/small_stats.out b/tests/small_stats.out
new file mode 100644 (file)
index 0000000..a89be1c
--- /dev/null
@@ -0,0 +1,5 @@
+Total time per tag
+==================
+______Tag_|___Time_|_Percentage_
+    arbtt |  3m00s |     100.00
+before_14 |  1m00s |      33.33
diff --git a/tests/test.hs b/tests/test.hs
new file mode 100644 (file)
index 0000000..2966f15
--- /dev/null
@@ -0,0 +1,53 @@
+{-# LANGUAGE DeriveDataTypeable #-}
+
+import Test.Tasty hiding (defaultMain)
+import Test.Tasty.Golden.Manage
+import Test.Tasty.Golden
+import System.Process.ByteString.Lazy
+import qualified Data.ByteString.Lazy as B
+import Control.Monad
+import Control.Exception
+import Data.Typeable
+import System.Exit
+
+main = defaultMain tests
+
+tests :: TestTree
+tests = testGroup "Tests" [goldenTests]
+
+goldenTests :: TestTree
+goldenTests = testGroup "Golden tests"
+    [ goldenVsString "dump small"
+        "tests/small_dump.out" $
+        run "dist/build/arbtt-dump/arbtt-dump" ["-f","tests/small.log", "-t", "Show"] B.empty
+    , goldenVsFile "import small"
+        "tests/small_import.out" "tests/small_import.out.actual" $ void $
+        B.readFile "tests/small_import.in" >>=
+        run "dist/build/arbtt-import/arbtt-import" ["-f","tests/small_import.out.actual"]
+    , goldenVsFile "recover small"
+        "tests/small_borked_recover.out" "tests/small_borked_recover.out.actual" $ void $
+        run "dist/build/arbtt-recover/arbtt-recover" ["-i","tests/small_borked_recover.out", "-o", "tests/small_borked_recover.out.actual"] B.empty
+    , goldenVsString "stats small"
+        "tests/small_stats.out" $
+        run "dist/build/arbtt-stats/arbtt-stats" ["--logfile", "tests/small.log", "--categorize", "tests/small.cfg"] B.empty
+    , goldenVsString "stats small unicode"
+        "tests/unicode_stats.out" $
+        run "dist/build/arbtt-stats/arbtt-stats" ["--logfile", "tests/unicode.log", "--categorize", "tests/unicode.cfg"] B.empty
+    ]
+
+
+run :: FilePath -> [FilePath] -> B.ByteString -> IO B.ByteString
+run cmd args stdin = do
+   (ex,stdout,stderr) <- readProcessWithExitCode cmd args stdin
+   unless (B.null stderr) $ throwIO $ StderrException stderr
+   case ex of
+     ExitSuccess   -> return stdout
+     ExitFailure r -> throwIO $ ExitCodeException r
+
+data StderrException = StderrException B.ByteString
+     deriving (Show, Typeable)
+data ExitCodeException = ExitCodeException Int
+     deriving (Show, Typeable)
+
+instance Exception StderrException
+instance Exception ExitCodeException
diff --git a/tests/unicode.cfg b/tests/unicode.cfg
new file mode 100644 (file)
index 0000000..85509d0
--- /dev/null
@@ -0,0 +1,3 @@
+any window $title =~ /aäα/ ==> tag ok,
+any window $title =~ /aäƱ/ ==> tag notok,
+
diff --git a/tests/unicode.log b/tests/unicode.log
new file mode 100644 (file)
index 0000000..d39b1c8
Binary files /dev/null and b/tests/unicode.log differ
diff --git a/tests/unicode_stats.out b/tests/unicode_stats.out
new file mode 100644 (file)
index 0000000..1701583
--- /dev/null
@@ -0,0 +1,4 @@
+Total time per tag
+==================
+Tag_|___Time_|_Percentage_
+ ok |  1m00s |     100.00