rickeyski / test-unix

bug reproducer
Other
0 stars 0 forks source link

simplify #1

Open juhp opened 1 year ago

juhp commented 1 year ago
diff --git a/package.yaml b/package.yaml
index e9a4811..8e49523 100644
--- a/package.yaml
+++ b/package.yaml
@@ -21,7 +21,6 @@ description:         Please see the README on GitHub at <https://github.com/gith

 dependencies:
 - base >= 4.7 && < 5
-- pretty-simple
 - unix

 ghc-options:
@@ -48,4 +47,3 @@ executables:
     - -with-rtsopts=-N
     dependencies:
     - test-unix
-
diff --git a/src/Lib.hs b/src/Lib.hs
index 2a2541d..2cd9c53 100644
--- a/src/Lib.hs
+++ b/src/Lib.hs
@@ -2,21 +2,13 @@ module Lib
     ( getGroupConfiguration
     ) where

-import Text.Pretty.Simple
 import System.Posix.Types
 import System.Posix.User

-newtype User = User String
-  deriving (Show, Ord, Eq)
-
 getGroupConfiguration :: IO ()
 getGroupConfiguration = do
-  findGroups <- userGIDList <$> getAllGroupEntries
-  pPrint . findGroups $ User "visinski"
-
+  user <- getLoginName
+  getAllGroupEntries >>= print . userGIDList user
   where
-    userGIDList :: [GroupEntry] -> User -> [GroupID]
-    -- Given a set of groups and a username, return the gids of those groups
-    -- containing the user.
-    userGIDList groups (User user) = map groupID $ filter (elem user . groupMembers) groups
-
+    userGIDList :: String -> [GroupEntry] -> [GroupID]
+    userGIDList user groups = map groupID $ filter (elem user . groupMembers) groups
diff --git a/test-unix.cabal b/test-unix.cabal
index 39908b9..5cd4371 100644
--- a/test-unix.cabal
+++ b/test-unix.cabal
@@ -33,7 +33,6 @@ library
   ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints
   build-depends:
       base >=4.7 && <5
-    , pretty-simple
     , unix
   default-language: Haskell2010

@@ -46,7 +45,6 @@ executable test-unix-exe
   ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
   build-depends:
       base >=4.7 && <5
-    , pretty-simple
     , test-unix
     , unix
   default-language: Haskell2010
juhp commented 1 year ago

Also for Stackage nightly and unix-2.8.1.1:

diff --git a/package.yaml b/package.yaml
index e9a4811..8e49523 100644
--- a/package.yaml
+++ b/package.yaml
@@ -21,7 +21,6 @@ description:         Please see the README on GitHub at <https://github.com/gith

 dependencies:
 - base >= 4.7 && < 5
-- pretty-simple
 - unix

 ghc-options:
@@ -48,4 +47,3 @@ executables:
     - -with-rtsopts=-N
     dependencies:
     - test-unix
-
diff --git a/src/Lib.hs b/src/Lib.hs
index 2a2541d..0e1d5dc 100644
--- a/src/Lib.hs
+++ b/src/Lib.hs
@@ -2,21 +2,11 @@ module Lib
     ( getGroupConfiguration
     ) where

-import Text.Pretty.Simple
-import System.Posix.Types
 import System.Posix.User

-newtype User = User String
-  deriving (Show, Ord, Eq)
-
 getGroupConfiguration :: IO ()
 getGroupConfiguration = do
-  findGroups <- userGIDList <$> getAllGroupEntries
-  pPrint . findGroups $ User "visinski"
-
+  user <- getLoginName
+  getAllGroupEntries >>= print . userGIDList user
   where
-    userGIDList :: [GroupEntry] -> User -> [GroupID]
-    -- Given a set of groups and a username, return the gids of those groups
-    -- containing the user.
-    userGIDList groups (User user) = map groupID $ filter (elem user . groupMembers) groups
-
+    userGIDList user groups = map groupID $ filter (elem user . groupMembers) groups
diff --git a/stack.yaml b/stack.yaml
index d4f334c..8e8e372 100644
--- a/stack.yaml
+++ b/stack.yaml
@@ -1,6 +1,4 @@
-resolver:
-  url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/9.yaml
-  #url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/24.yaml
+resolver: nightly-2023-08-29

-packages:
-- .
+extra-deps:
+  - unix-2.8.1.1
diff --git a/stack.yaml.lock b/stack.yaml.lock
index f7b9968..2e7a6cd 100644
--- a/stack.yaml.lock
+++ b/stack.yaml.lock
@@ -3,11 +3,17 @@
 # For more information, please see the documentation at:
 #   https://docs.haskellstack.org/en/stable/lock_files

-packages: []
-snapshots:
+packages:
 - completed:
-    sha256: 2fc12a405ab6f7eac73eb11a0ca5ccca0e956bd2848db780c140b7406ff9ebb5
-    size: 640035
-    url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/9.yaml
+    hackage: unix-2.8.1.1@sha256:ac8543fb9a80e3b9836cea7e71cd3a8fd56d7563dd59389d9731e71a688c19db,7610
+    pantry-tree:
+      sha256: 38451cb8e110edc764f6e58d835031961f0a9dea8ca8ea84e2a434ca1c1a6c46
+      size: 5642
   original:
-    url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/9.yaml
+    hackage: unix-2.8.1.1
+snapshots:
+- completed:
+    sha256: ef64ad2dff8573fe227104852d4d3b3f42f108a33f14c72318d431d3d89d3845
+    size: 659086
+    url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2023/8/29.yaml
+  original: nightly-2023-08-29
diff --git a/test-unix.cabal b/test-unix.cabal
index 39908b9..5cd4371 100644
--- a/test-unix.cabal
+++ b/test-unix.cabal
@@ -33,7 +33,6 @@ library
   ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints
   build-depends:
       base >=4.7 && <5
-    , pretty-simple
     , unix
   default-language: Haskell2010

@@ -46,7 +45,6 @@ executable test-unix-exe
   ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
   build-depends:
       base >=4.7 && <5
-    , pretty-simple
     , test-unix
     , unix
   default-language: Haskell2010

The main change being the stack.yaml file, but also need to drop the type signature of userGIDList.