|
| 1 | +{-# LANGUAGE OverloadedStrings #-} |
| 2 | + |
| 3 | +module EnumSpec (spec) where |
| 4 | + |
| 5 | +import Test.Hspec (SpecWith, Spec, describe, it, shouldBe) |
| 6 | + |
| 7 | +import Data.ByteString (ByteString) |
| 8 | +import Data.Word (Word64) |
| 9 | +import System.Nix.Build (BuildMode(..), BuildStatus(..)) |
| 10 | +import System.Nix.Store.Remote.Serializer |
| 11 | + ( activity |
| 12 | + , activityResult |
| 13 | + , enum |
| 14 | + , int |
| 15 | + , loggerOpCode |
| 16 | + , runP |
| 17 | + , LoggerSError |
| 18 | + , NixSerializer |
| 19 | + , SError |
| 20 | + ) |
| 21 | +import System.Nix.Store.Remote.Types |
| 22 | + |
| 23 | +spec :: Spec |
| 24 | +spec = do |
| 25 | + let |
| 26 | + itE |
| 27 | + :: ( Enum a |
| 28 | + , Show a |
| 29 | + ) |
| 30 | + => String |
| 31 | + -> a |
| 32 | + -> Word64 |
| 33 | + -> SpecWith () |
| 34 | + itE name constr value = |
| 35 | + it name |
| 36 | + $ ((runP enum () constr) :: Either SError ByteString) |
| 37 | + `shouldBe` |
| 38 | + (runP (int @Word64) () value) |
| 39 | + |
| 40 | + itE' |
| 41 | + :: Show a |
| 42 | + => NixSerializer () LoggerSError a |
| 43 | + -> String |
| 44 | + -> a |
| 45 | + -> Word64 |
| 46 | + -> SpecWith () |
| 47 | + itE' s name constr value = |
| 48 | + it name |
| 49 | + $ ((runP s () constr) :: Either LoggerSError ByteString) |
| 50 | + `shouldBe` |
| 51 | + (runP (int @Word64) () (value)) |
| 52 | + |
| 53 | + describe "Enums" $ do |
| 54 | + describe "BuildMode enum order matches Nix" $ do |
| 55 | + itE "Normal" BuildMode_Normal 0 |
| 56 | + itE "Repair" BuildMode_Repair 1 |
| 57 | + itE "Check" BuildMode_Check 2 |
| 58 | + |
| 59 | + describe "BuildStatus enum order matches Nix" $ do |
| 60 | + itE "Built" BuildStatus_Built 0 |
| 61 | + itE "Substituted" BuildStatus_Substituted 1 |
| 62 | + itE "AlreadyValid" BuildStatus_AlreadyValid 2 |
| 63 | + itE "PermanentFailure" BuildStatus_PermanentFailure 3 |
| 64 | + itE "InputRejected" BuildStatus_InputRejected 4 |
| 65 | + itE "OutputRejected" BuildStatus_OutputRejected 5 |
| 66 | + itE "TransientFailure" BuildStatus_TransientFailure 6 |
| 67 | + itE "CachedFailure" BuildStatus_CachedFailure 7 |
| 68 | + itE "TimedOut" BuildStatus_TimedOut 8 |
| 69 | + itE "MiscFailure" BuildStatus_MiscFailure 9 |
| 70 | + itE "DependencyFailed" BuildStatus_DependencyFailed 10 |
| 71 | + itE "LogLimitExceeded" BuildStatus_LogLimitExceeded 11 |
| 72 | + itE "NotDeterministic" BuildStatus_NotDeterministic 12 |
| 73 | + itE "ResolvesToAlreadyValid" BuildStatus_ResolvesToAlreadyValid 13 |
| 74 | + itE "NoSubstituters" BuildStatus_NoSubstituters 14 |
| 75 | + |
| 76 | + describe "GCAction enum order matches Nix" $ do |
| 77 | + itE "ReturnLive" GCAction_ReturnLive 0 |
| 78 | + itE "ReturnDead" GCAction_ReturnDead 1 |
| 79 | + itE "DeleteDead" GCAction_DeleteDead 2 |
| 80 | + itE "DeleteSpecific" GCAction_DeleteSpecific 3 |
| 81 | + |
| 82 | + describe "Logger" $ do |
| 83 | + let itA = itE' activity |
| 84 | + describe "Activity enum order matches Nix" $ do |
| 85 | + itA "CopyPath" Activity_CopyPath 100 |
| 86 | + itA "FileTransfer" Activity_FileTransfer 101 |
| 87 | + itA "Realise" Activity_Realise 102 |
| 88 | + itA "CopyPaths" Activity_CopyPaths 103 |
| 89 | + itA "Builds" Activity_Builds 104 |
| 90 | + itA "Build" Activity_Build 105 |
| 91 | + itA "OptimiseStore" Activity_OptimiseStore 106 |
| 92 | + itA "VerifyPaths" Activity_VerifyPaths 107 |
| 93 | + itA "Substitute" Activity_Substitute 108 |
| 94 | + itA "QueryPathInfo" Activity_QueryPathInfo 109 |
| 95 | + itA "PostBuildHook" Activity_PostBuildHook 110 |
| 96 | + itA "BuildWaiting" Activity_BuildWaiting 111 |
| 97 | + |
| 98 | + let itR = itE' activityResult |
| 99 | + describe "ActivityResult enum order matches Nix" $ do |
| 100 | + itR "FileLinked" ActivityResult_FileLinked 100 |
| 101 | + itR "BuildLogLine" ActivityResult_BuildLogLine 101 |
| 102 | + itR "UnstrustedPath" ActivityResult_UnstrustedPath 102 |
| 103 | + itR "CorruptedPath" ActivityResult_CorruptedPath 103 |
| 104 | + itR "SetPhase" ActivityResult_SetPhase 104 |
| 105 | + itR "Progress" ActivityResult_Progress 105 |
| 106 | + itR "SetExpected" ActivityResult_SetExpected 106 |
| 107 | + itR "PostBuildLogLine" ActivityResult_PostBuildLogLine 107 |
| 108 | + |
| 109 | + |
| 110 | + let itL = itE' loggerOpCode |
| 111 | + describe "LoggerOpCode matches Nix" $ do |
| 112 | + itL "Next" LoggerOpCode_Next 0x6f6c6d67 |
| 113 | + itL "Read" LoggerOpCode_Read 0x64617461 |
| 114 | + itL "Write" LoggerOpCode_Write 0x64617416 |
| 115 | + itL "Last" LoggerOpCode_Last 0x616c7473 |
| 116 | + itL "Error" LoggerOpCode_Error 0x63787470 |
| 117 | + itL "StartActivity" LoggerOpCode_StartActivity 0x53545254 |
| 118 | + itL "StopActivity" LoggerOpCode_StopActivity 0x53544f50 |
| 119 | + itL "Result" LoggerOpCode_Result 0x52534c54 |
| 120 | + |
| 121 | + describe "Verbosity enum order matches Nix" $ do |
| 122 | + itE "Error" Verbosity_Error 0 |
| 123 | + itE "Warn" Verbosity_Warn 1 |
| 124 | + itE "Notice" Verbosity_Notice 2 |
| 125 | + itE "Info" Verbosity_Info 3 |
| 126 | + itE "Talkative" Verbosity_Talkative 4 |
| 127 | + itE "Chatty" Verbosity_Chatty 5 |
| 128 | + itE "Debug" Verbosity_Debug 6 |
| 129 | + itE "Vomit" Verbosity_Vomit 7 |
| 130 | + |
| 131 | + describe "WorkerOp enum order matches Nix" $ do |
| 132 | + itE "IsValidPath" WorkerOp_IsValidPath 1 |
| 133 | + itE "BuildPathsWithResults" WorkerOp_BuildPathsWithResults 46 |
| 134 | + |
| 135 | + |
| 136 | + |
0 commit comments