Skip to content

Commit

Permalink
add System.PosixCompat.Process
Browse files Browse the repository at this point in the history
  • Loading branch information
ners committed Dec 2, 2023
1 parent bdc4673 commit fc20658
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## Version 0.7.1 (2023-11-01)

- Add `System.PosixCompat.Process` module, exporting `getProcessID`

## Version 0.7 (2023-03-15)

- Remote `System.PosixCompat.User` module
- Remove `System.PosixCompat.User` module

## Version 0.6 (2022-05-22)

Expand Down
2 changes: 2 additions & 0 deletions src/System/PosixCompat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package, on other platforms it emulates the operations as far as possible.
-}
module System.PosixCompat (
module System.PosixCompat.Files
, module System.PosixCompat.Process
, module System.PosixCompat.Temp
, module System.PosixCompat.Time
, module System.PosixCompat.Types
Expand All @@ -15,6 +16,7 @@ module System.PosixCompat (
) where

import System.PosixCompat.Files
import System.PosixCompat.Process
import System.PosixCompat.Temp
import System.PosixCompat.Time
import System.PosixCompat.Types
Expand Down
23 changes: 23 additions & 0 deletions src/System/PosixCompat/Process.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{-# LANGUAGE CPP #-}

{-|
This module intends to make the operations of @System.Posix.Process@ available
on all platforms.
-}
module System.PosixCompat.Process (
getProcessID
) where

#ifdef mingw32_HOST_OS

import System.Posix.Types (ProcessID)
import System.Win32.Process (getCurrentProcessId)

getProcessID :: IO ProcessID
getProcessID = fromIntegral <$> getCurrentProcessId

#else

import System.Posix.Process

#endif
12 changes: 12 additions & 0 deletions tests/ProcessSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module ProcessSpec (processSpec) where

import System.PosixCompat
import Test.HUnit
import Test.Hspec

processSpec :: Spec
processSpec = do
describe "getProcessID" $ do
it "should work on Windows and Unix" $ do
id <- getProcessID

Check warning on line 11 in tests/ProcessSpec.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest - GHC 9.8

This binding for ‘id’ shadows the existing binding

Check warning on line 11 in tests/ProcessSpec.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest - GHC 9.6

This binding for ‘id’ shadows the existing binding

Check warning on line 11 in tests/ProcessSpec.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest - GHC 9.4

This binding for ‘id’ shadows the existing binding

Check warning on line 11 in tests/ProcessSpec.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest - GHC 9.2

This binding for ‘id’ shadows the existing binding

Check warning on line 11 in tests/ProcessSpec.hs

View workflow job for this annotation

GitHub Actions / macOS-latest - GHC 9.8

This binding for ‘id’ shadows the existing binding

Check warning on line 11 in tests/ProcessSpec.hs

View workflow job for this annotation

GitHub Actions / macOS-latest - GHC 9.6

This binding for ‘id’ shadows the existing binding

Check warning on line 11 in tests/ProcessSpec.hs

View workflow job for this annotation

GitHub Actions / macOS-latest - GHC 9.4

This binding for ‘id’ shadows the existing binding

Check warning on line 11 in tests/ProcessSpec.hs

View workflow job for this annotation

GitHub Actions / macOS-latest - GHC 9.2

This binding for ‘id’ shadows the existing binding

Check warning on line 11 in tests/ProcessSpec.hs

View workflow job for this annotation

GitHub Actions / windows-latest - GHC 9.8

This binding for ‘id’ shadows the existing binding

Check warning on line 11 in tests/ProcessSpec.hs

View workflow job for this annotation

GitHub Actions / windows-latest - GHC 9.6

This binding for ‘id’ shadows the existing binding

Check warning on line 11 in tests/ProcessSpec.hs

View workflow job for this annotation

GitHub Actions / windows-latest - GHC 9.4

This binding for ‘id’ shadows the existing binding

Check warning on line 11 in tests/ProcessSpec.hs

View workflow job for this annotation

GitHub Actions / windows-latest - GHC 9.2

This binding for ‘id’ shadows the existing binding
assert $ id > 0
2 changes: 2 additions & 0 deletions tests/main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ module Main where

import MkstempSpec
import LinksSpec
import ProcessSpec

import Test.Hspec

main :: IO ()
main = hspec $ do
mkstempSpec
linksSpec
processSpec
4 changes: 3 additions & 1 deletion unix-compat.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: unix-compat
version: 0.7
version: 0.7.1
synopsis: Portable POSIX-compatibility layer.
description: This package provides portable implementations of parts
of the unix package. This package re-exports the unix
Expand Down Expand Up @@ -36,6 +36,7 @@ Library
System.PosixCompat
System.PosixCompat.Extensions
System.PosixCompat.Files
System.PosixCompat.Process
System.PosixCompat.Temp
System.PosixCompat.Time
System.PosixCompat.Types
Expand Down Expand Up @@ -85,6 +86,7 @@ Test-Suite unix-compat-testsuite
other-modules:
MkstempSpec
LinksSpec
ProcessSpec

-- ghc-options:
-- -Wall
Expand Down

0 comments on commit fc20658

Please sign in to comment.