@@ -4,6 +4,7 @@ import Prelude
44
55import Control.Monad.Error.Class (throwError )
66import Data.Foldable (foldMap )
7+ import Data.Maybe (Maybe (..))
78import Data.String as String
89import Data.String.NonEmpty (NonEmptyString )
910import Data.String.NonEmpty as StringNE
@@ -18,6 +19,7 @@ import Type.Proxy (Proxy(..))
1819type Input =
1920 { command ∷ NonEmptyString
2021 , parameters ∷ Array Parameter
22+ , shouldFail ∷ Boolean
2123 }
2224
2325type Parameter = NonEmptyString /\ NonEmptyString
@@ -42,24 +44,35 @@ fixtures =
4244 )
4345 , leftSchemaFile: StringNE .nes (Proxy ∷ Proxy " any-number.json" )
4446 , rightSchemaFile: StringNE .nes (Proxy ∷ Proxy " any-string.json" )
47+ , shouldFail: true
4548 }
4649 ]
4750
4851 diffFixtures ∷ Array (Fixture Input )
4952 diffFixtures = diffFixture <$>
5053 [ { differencesFile: StringNE .nes
54+ ( Proxy
55+ ∷ Proxy " no-differences.json"
56+ )
57+ , leftSchemaFile: StringNE .nes (Proxy ∷ Proxy " any-number.json" )
58+ , rightSchemaFile: StringNE .nes (Proxy ∷ Proxy " any-number.json" )
59+ , shouldFail: false
60+ }
61+ , { differencesFile: StringNE .nes
5162 ( Proxy
5263 ∷ Proxy " allowed-types-change-from-number-to-string.json"
5364 )
5465 , leftSchemaFile: StringNE .nes (Proxy ∷ Proxy " any-number.json" )
5566 , rightSchemaFile: StringNE .nes (Proxy ∷ Proxy " any-string.json" )
67+ , shouldFail: true
5668 }
5769 ]
5870
5971 validateFixtures ∷ Array (Fixture Input )
6072 validateFixtures = validateFixture <$>
6173 [ { jsonFile: StringNE .nes (Proxy ∷ Proxy " string.json" )
6274 , schemaFile: StringNE .nes (Proxy ∷ Proxy " any-number.json" )
75+ , shouldFail: true
6376 , violationsFile: StringNE .nes
6477 (Proxy ∷ Proxy " string-is-not-a-number.json" )
6578 }
@@ -69,15 +82,18 @@ compatFixture
6982 ∷ { compatibilitiesFile ∷ NonEmptyString
7083 , leftSchemaFile ∷ NonEmptyString
7184 , rightSchemaFile ∷ NonEmptyString
85+ , shouldFail ∷ Boolean
7286 }
7387 → Fixture Input
74- compatFixture { compatibilitiesFile, leftSchemaFile, rightSchemaFile } =
88+ compatFixture
89+ { compatibilitiesFile, leftSchemaFile, rightSchemaFile, shouldFail } =
7590 { input:
7691 { command: StringNE .nes (Proxy ∷ Proxy " compat" )
7792 , parameters:
7893 [ StringNE .nes (Proxy ∷ Proxy " left" ) /\ leftSchemaPath
7994 , StringNE .nes (Proxy ∷ Proxy " right" ) /\ rightSchemaPath
8095 ]
96+ , shouldFail
8197 }
8298 , outputPath
8399 }
@@ -100,15 +116,18 @@ diffFixture
100116 ∷ { differencesFile ∷ NonEmptyString
101117 , leftSchemaFile ∷ NonEmptyString
102118 , rightSchemaFile ∷ NonEmptyString
119+ , shouldFail ∷ Boolean
103120 }
104121 → Fixture Input
105- diffFixture { differencesFile, leftSchemaFile, rightSchemaFile } =
122+ diffFixture
123+ { differencesFile, leftSchemaFile, rightSchemaFile, shouldFail } =
106124 { input:
107125 { command: StringNE .nes (Proxy ∷ Proxy " diff" )
108126 , parameters:
109127 [ StringNE .nes (Proxy ∷ Proxy " left" ) /\ leftSchemaPath
110128 , StringNE .nes (Proxy ∷ Proxy " right" ) /\ rightSchemaPath
111129 ]
130+ , shouldFail
112131 }
113132 , outputPath
114133 }
@@ -130,16 +149,18 @@ diffFixture { differencesFile, leftSchemaFile, rightSchemaFile } =
130149validateFixture
131150 ∷ { jsonFile ∷ NonEmptyString
132151 , schemaFile ∷ NonEmptyString
152+ , shouldFail ∷ Boolean
133153 , violationsFile ∷ NonEmptyString
134154 }
135155 → Fixture Input
136- validateFixture { jsonFile, schemaFile, violationsFile } =
156+ validateFixture { jsonFile, schemaFile, shouldFail, violationsFile } =
137157 { input:
138158 { command: StringNE .nes (Proxy ∷ Proxy " validate" )
139159 , parameters:
140160 [ StringNE .nes (Proxy ∷ Proxy " json" ) /\ jsonPath
141161 , StringNE .nes (Proxy ∷ Proxy " schema" ) /\ schemaPath
142162 ]
163+ , shouldFail
143164 }
144165 , outputPath
145166 }
@@ -167,15 +188,31 @@ describeInput { command, parameters } = "a CLI invocation of '"
167188 StringNE .toString k <> " =" <> StringNE .toString v
168189
169190executeCommand ∷ Input → Aff String
170- executeCommand { command, parameters } = do
191+ executeCommand { command, parameters, shouldFail } = do
171192 result ← runCliProcess `pipe` runPrettierProcess
172- case result.exit of
193+ let
194+ { escapedCommand, exit, stderr, stdout } = result
195+ case exit of
173196 BySignal _ →
174- throwError $ error $ " process killed: " <> result.escapedCommand
175- Normally 0 → do
176- pure $ result.stdout <> " \n "
177- Normally _ →
178- pure $ result.stderr <> " \n "
197+ throwError $ error $ " process killed: " <> escapedCommand
198+ Normally 0 →
199+ if shouldFail then throwError
200+ $ error
201+ $ " command should fail but it did not: "
202+ <> show { stderr, stdout }
203+ else pure $ stdout <> " \n "
204+ Normally 1 →
205+ if shouldFail then pure $ stdout <> " \n "
206+ else throwError
207+ $ error
208+ $ " command should not fail but it did: "
209+ <> show { exitCode: 1 , stderr, stdout }
210+ Normally exitCode →
211+ if shouldFail then pure $ stderr <> " \n "
212+ else throwError
213+ $ error
214+ $ " command should not fail but it did: "
215+ <> show { exitCode, stderr, stdout }
179216 where
180217 runCliProcess ∷ Aff ExecaProcess
181218 runCliProcess = E .execa
@@ -203,9 +240,11 @@ pipe runProcess1 runProcess2 = do
203240 process1 ← runProcess1
204241 result1 ← process1.getResult
205242 case result1.exit of
206- Normally 0 → do
243+ Normally exitCode → do
207244 process2 ← runProcess2
208245 process2.stdin.writeUtf8End result1.stdout
209- process2.getResult
246+ result2 ← process2.getResult
247+ pure $ result1
248+ { exitCode = Just exitCode, stdout = result2.stdout }
210249 _ →
211250 pure result1
0 commit comments