Skip to content

Commit 6152a5b

Browse files
nersandreasabel
authored andcommitted
v0.7.1: add System.PosixCompat.Process containing getProcessID
1 parent bdc4673 commit 6152a5b

File tree

6 files changed

+47
-2
lines changed

6 files changed

+47
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
## Version 0.7.1 (2023-11-01)
2+
3+
- Add `System.PosixCompat.Process` module, exporting `getProcessID`
4+
15
## Version 0.7 (2023-03-15)
26

3-
- Remote `System.PosixCompat.User` module
7+
- Remove `System.PosixCompat.User` module
48

59
## Version 0.6 (2022-05-22)
610

src/System/PosixCompat.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package, on other platforms it emulates the operations as far as possible.
77
-}
88
module System.PosixCompat (
99
module System.PosixCompat.Files
10+
, module System.PosixCompat.Process
1011
, module System.PosixCompat.Temp
1112
, module System.PosixCompat.Time
1213
, module System.PosixCompat.Types
@@ -15,6 +16,7 @@ module System.PosixCompat (
1516
) where
1617

1718
import System.PosixCompat.Files
19+
import System.PosixCompat.Process
1820
import System.PosixCompat.Temp
1921
import System.PosixCompat.Time
2022
import System.PosixCompat.Types

src/System/PosixCompat/Process.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{-# LANGUAGE CPP #-}
2+
3+
{-|
4+
This module intends to make the operations of @System.Posix.Process@ available
5+
on all platforms.
6+
-}
7+
module System.PosixCompat.Process (
8+
getProcessID
9+
) where
10+
11+
#ifdef mingw32_HOST_OS
12+
13+
import System.Posix.Types (ProcessID)
14+
import System.Win32.Process (getCurrentProcessId)
15+
16+
getProcessID :: IO ProcessID
17+
getProcessID = fromIntegral <$> getCurrentProcessId
18+
19+
#else
20+
21+
import System.Posix.Process
22+
23+
#endif

tests/ProcessSpec.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module ProcessSpec (processSpec) where
2+
3+
import System.PosixCompat
4+
import Test.HUnit
5+
import Test.Hspec
6+
7+
processSpec :: Spec
8+
processSpec = do
9+
describe "getProcessID" $ do
10+
it "should work on Windows and Unix" $ do
11+
pid <- getProcessID
12+
assert $ pid > 0

tests/main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ module Main where
22

33
import MkstempSpec
44
import LinksSpec
5+
import ProcessSpec
56

67
import Test.Hspec
78

89
main :: IO ()
910
main = hspec $ do
1011
mkstempSpec
1112
linksSpec
13+
processSpec

unix-compat.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: unix-compat
2-
version: 0.7
2+
version: 0.7.1
33
synopsis: Portable POSIX-compatibility layer.
44
description: This package provides portable implementations of parts
55
of the unix package. This package re-exports the unix
@@ -36,6 +36,7 @@ Library
3636
System.PosixCompat
3737
System.PosixCompat.Extensions
3838
System.PosixCompat.Files
39+
System.PosixCompat.Process
3940
System.PosixCompat.Temp
4041
System.PosixCompat.Time
4142
System.PosixCompat.Types
@@ -85,6 +86,7 @@ Test-Suite unix-compat-testsuite
8586
other-modules:
8687
MkstempSpec
8788
LinksSpec
89+
ProcessSpec
8890

8991
-- ghc-options:
9092
-- -Wall

0 commit comments

Comments
 (0)