@@ -4,6 +4,7 @@ import Prelude
4
4
5
5
import Control.Monad.Error.Class (throwError )
6
6
import Data.Foldable (foldMap )
7
+ import Data.Maybe (Maybe (..))
7
8
import Data.String as String
8
9
import Data.String.NonEmpty (NonEmptyString )
9
10
import Data.String.NonEmpty as StringNE
@@ -18,6 +19,7 @@ import Type.Proxy (Proxy(..))
18
19
type Input =
19
20
{ command ∷ NonEmptyString
20
21
, parameters ∷ Array Parameter
22
+ , shouldFail ∷ Boolean
21
23
}
22
24
23
25
type Parameter = NonEmptyString /\ NonEmptyString
@@ -42,24 +44,35 @@ fixtures =
42
44
)
43
45
, leftSchemaFile: StringNE .nes (Proxy ∷ Proxy " any-number.json" )
44
46
, rightSchemaFile: StringNE .nes (Proxy ∷ Proxy " any-string.json" )
47
+ , shouldFail: true
45
48
}
46
49
]
47
50
48
51
diffFixtures ∷ Array (Fixture Input )
49
52
diffFixtures = diffFixture <$>
50
53
[ { 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
51
62
( Proxy
52
63
∷ Proxy " allowed-types-change-from-number-to-string.json"
53
64
)
54
65
, leftSchemaFile: StringNE .nes (Proxy ∷ Proxy " any-number.json" )
55
66
, rightSchemaFile: StringNE .nes (Proxy ∷ Proxy " any-string.json" )
67
+ , shouldFail: true
56
68
}
57
69
]
58
70
59
71
validateFixtures ∷ Array (Fixture Input )
60
72
validateFixtures = validateFixture <$>
61
73
[ { jsonFile: StringNE .nes (Proxy ∷ Proxy " string.json" )
62
74
, schemaFile: StringNE .nes (Proxy ∷ Proxy " any-number.json" )
75
+ , shouldFail: true
63
76
, violationsFile: StringNE .nes
64
77
(Proxy ∷ Proxy " string-is-not-a-number.json" )
65
78
}
@@ -69,15 +82,18 @@ compatFixture
69
82
∷ { compatibilitiesFile ∷ NonEmptyString
70
83
, leftSchemaFile ∷ NonEmptyString
71
84
, rightSchemaFile ∷ NonEmptyString
85
+ , shouldFail ∷ Boolean
72
86
}
73
87
→ Fixture Input
74
- compatFixture { compatibilitiesFile, leftSchemaFile, rightSchemaFile } =
88
+ compatFixture
89
+ { compatibilitiesFile, leftSchemaFile, rightSchemaFile, shouldFail } =
75
90
{ input:
76
91
{ command: StringNE .nes (Proxy ∷ Proxy " compat" )
77
92
, parameters:
78
93
[ StringNE .nes (Proxy ∷ Proxy " left" ) /\ leftSchemaPath
79
94
, StringNE .nes (Proxy ∷ Proxy " right" ) /\ rightSchemaPath
80
95
]
96
+ , shouldFail
81
97
}
82
98
, outputPath
83
99
}
@@ -100,15 +116,18 @@ diffFixture
100
116
∷ { differencesFile ∷ NonEmptyString
101
117
, leftSchemaFile ∷ NonEmptyString
102
118
, rightSchemaFile ∷ NonEmptyString
119
+ , shouldFail ∷ Boolean
103
120
}
104
121
→ Fixture Input
105
- diffFixture { differencesFile, leftSchemaFile, rightSchemaFile } =
122
+ diffFixture
123
+ { differencesFile, leftSchemaFile, rightSchemaFile, shouldFail } =
106
124
{ input:
107
125
{ command: StringNE .nes (Proxy ∷ Proxy " diff" )
108
126
, parameters:
109
127
[ StringNE .nes (Proxy ∷ Proxy " left" ) /\ leftSchemaPath
110
128
, StringNE .nes (Proxy ∷ Proxy " right" ) /\ rightSchemaPath
111
129
]
130
+ , shouldFail
112
131
}
113
132
, outputPath
114
133
}
@@ -130,16 +149,18 @@ diffFixture { differencesFile, leftSchemaFile, rightSchemaFile } =
130
149
validateFixture
131
150
∷ { jsonFile ∷ NonEmptyString
132
151
, schemaFile ∷ NonEmptyString
152
+ , shouldFail ∷ Boolean
133
153
, violationsFile ∷ NonEmptyString
134
154
}
135
155
→ Fixture Input
136
- validateFixture { jsonFile, schemaFile, violationsFile } =
156
+ validateFixture { jsonFile, schemaFile, shouldFail, violationsFile } =
137
157
{ input:
138
158
{ command: StringNE .nes (Proxy ∷ Proxy " validate" )
139
159
, parameters:
140
160
[ StringNE .nes (Proxy ∷ Proxy " json" ) /\ jsonPath
141
161
, StringNE .nes (Proxy ∷ Proxy " schema" ) /\ schemaPath
142
162
]
163
+ , shouldFail
143
164
}
144
165
, outputPath
145
166
}
@@ -167,15 +188,31 @@ describeInput { command, parameters } = "a CLI invocation of '"
167
188
StringNE .toString k <> " =" <> StringNE .toString v
168
189
169
190
executeCommand ∷ Input → Aff String
170
- executeCommand { command, parameters } = do
191
+ executeCommand { command, parameters, shouldFail } = do
171
192
result ← runCliProcess `pipe` runPrettierProcess
172
- case result.exit of
193
+ let
194
+ { escapedCommand, exit, stderr, stdout } = result
195
+ case exit of
173
196
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 }
179
216
where
180
217
runCliProcess ∷ Aff ExecaProcess
181
218
runCliProcess = E .execa
@@ -203,9 +240,11 @@ pipe runProcess1 runProcess2 = do
203
240
process1 ← runProcess1
204
241
result1 ← process1.getResult
205
242
case result1.exit of
206
- Normally 0 → do
243
+ Normally exitCode → do
207
244
process2 ← runProcess2
208
245
process2.stdin.writeUtf8End result1.stdout
209
- process2.getResult
246
+ result2 ← process2.getResult
247
+ pure $ result1
248
+ { exitCode = Just exitCode, stdout = result2.stdout }
210
249
_ →
211
250
pure result1
0 commit comments