summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
Diffstat (limited to 'libraries')
-rw-r--r--libraries/base/System/Info.hs36
-rw-r--r--libraries/base/tests/SystemInfoTest.hs13
-rw-r--r--libraries/base/tests/SystemInfoTest.stdout1
-rw-r--r--libraries/base/tests/all.T1
4 files changed, 41 insertions, 10 deletions
diff --git a/libraries/base/System/Info.hs b/libraries/base/System/Info.hs
index 840a9b5a25..70284d44ef 100644
--- a/libraries/base/System/Info.hs
+++ b/libraries/base/System/Info.hs
@@ -1,12 +1,12 @@
+{-# LANGUAGE CPP #-}
{-# LANGUAGE Safe #-}
-{-# LANGUAGE CPP #-}
-----------------------------------------------------------------------------
-- |
-- Module : System.Info
-- Copyright : (c) The University of Glasgow 2001
-- License : BSD-style (see the file libraries/base/LICENSE)
---
+--
-- Maintainer : libraries@haskell.org
-- Stability : experimental
-- Portability : portable
@@ -19,18 +19,18 @@
-----------------------------------------------------------------------------
module System.Info
- (
- os,
- arch,
- compilerName,
- compilerVersion
- ) where
+ ( os
+ , arch
+ , compilerName
+ , compilerVersion
+ , fullCompilerVersion
+ ) where
-import Data.Version
+import Data.Version (Version (..))
-- | The version of 'compilerName' with which the program was compiled
-- or is being interpreted.
---
+--
-- ==== __Example__
-- > ghci> compilerVersion
-- > Version {versionBranch = [8,8], versionTags = []}
@@ -38,6 +38,22 @@ compilerVersion :: Version
compilerVersion = Version [major, minor] []
where (major, minor) = compilerVersionRaw `divMod` 100
+-- | The full version of 'compilerName' with which the program was compiled
+-- or is being interpreted. It includes the major, minor, revision and an additional
+-- identifier, generally in the form "<year><month><day>".
+fullCompilerVersion :: Version
+fullCompilerVersion = Version version []
+ where
+ version :: [Int]
+ version = fmap read $ splitVersion __GLASGOW_HASKELL_FULL_VERSION__
+
+splitVersion :: String -> [String]
+splitVersion s =
+ case dropWhile (== '.') s of
+ "" -> []
+ s' -> let (w, s'') = break (== '.') s'
+ in w : splitVersion s''
+
#include "ghcplatform.h"
-- | The operating system on which the program is running.
diff --git a/libraries/base/tests/SystemInfoTest.hs b/libraries/base/tests/SystemInfoTest.hs
new file mode 100644
index 0000000000..ef8c829df4
--- /dev/null
+++ b/libraries/base/tests/SystemInfoTest.hs
@@ -0,0 +1,13 @@
+{-# LANGUAGE CPP #-}
+module Main where
+
+import Data.Version (showVersion)
+import System.Info (fullCompilerVersion)
+
+main :: IO ()
+main = if textualVersion == macroVersion
+ then putStrLn "Match"
+ else putStrLn $ "[!]" <> textualVersion <> "should be equal to " <> macroVersion
+ where
+ macroVersion = __GLASGOW_HASKELL_FULL_VERSION__
+ textualVersion = showVersion fullCompilerVersion
diff --git a/libraries/base/tests/SystemInfoTest.stdout b/libraries/base/tests/SystemInfoTest.stdout
new file mode 100644
index 0000000000..1796dc2720
--- /dev/null
+++ b/libraries/base/tests/SystemInfoTest.stdout
@@ -0,0 +1 @@
+Match
diff --git a/libraries/base/tests/all.T b/libraries/base/tests/all.T
index 4a29e8b571..c29b5b3a63 100644
--- a/libraries/base/tests/all.T
+++ b/libraries/base/tests/all.T
@@ -12,6 +12,7 @@ def normalise_quotes (str):
#--------------------------------------
# Test functions
#--------------------------------------
+test('SystemInfoTest', normal, compile_and_run, [''])
test('readFloat', exit_code(1), compile_and_run, [''])
test('enumDouble', normal, compile_and_run, [''])
test('enumRatio', normal, compile_and_run, [''])