@@ -64,39 +64,39 @@ private void RunWithBoth(Action<string> action)
64
64
public void AnalyzersSimple ( )
65
65
{
66
66
var ( exitCode , output ) = RunCompLogEx ( $ "analyzers { Fixture . SolutionBinaryLogPath } -p console.csproj") ;
67
- Assert . Equal ( 0 , exitCode ) ;
67
+ Assert . Equal ( Constants . ExitSuccess , exitCode ) ;
68
68
Assert . Contains ( "Microsoft.CodeAnalysis.NetAnalyzers.dll" , output ) ;
69
69
}
70
70
71
71
[ Fact ]
72
72
public void AnalyzersHelp ( )
73
73
{
74
74
var ( exitCode , output ) = RunCompLogEx ( $ "analyzers -h") ;
75
- Assert . Equal ( 0 , exitCode ) ;
75
+ Assert . Equal ( Constants . ExitSuccess , exitCode ) ;
76
76
Assert . StartsWith ( "complog analyzers [OPTIONS]" , output ) ;
77
77
}
78
78
79
79
[ Fact ]
80
80
public void AnalyzersError ( )
81
81
{
82
82
var ( exitCode , output ) = RunCompLogEx ( $ "analyzers { Fixture . RemovedBinaryLogPath } ") ;
83
- Assert . NotEqual ( 0 , exitCode ) ;
83
+ Assert . NotEqual ( Constants . ExitSuccess , exitCode ) ;
84
84
Assert . StartsWith ( "Unexpected error" , output ) ;
85
85
}
86
86
87
87
[ Fact ]
88
88
public void AnalyzerBadOption ( )
89
89
{
90
90
var ( exitCode , output ) = RunCompLogEx ( $ "analyzers { Fixture . RemovedBinaryLogPath } --not-an-option") ;
91
- Assert . NotEqual ( 0 , exitCode ) ;
91
+ Assert . NotEqual ( Constants . ExitSuccess , exitCode ) ;
92
92
Assert . StartsWith ( "Extra arguments" , output ) ;
93
93
}
94
94
95
95
[ Fact ]
96
96
public void BadCommand ( )
97
97
{
98
98
var ( exitCode , output ) = RunCompLogEx ( "invalid" ) ;
99
- Assert . NotEqual ( 0 , exitCode ) ;
99
+ Assert . NotEqual ( Constants . ExitSuccess , exitCode ) ;
100
100
Assert . Contains ( @"""invalid"" is not a valid command" , output ) ;
101
101
}
102
102
@@ -106,7 +106,7 @@ public void BadCommand()
106
106
[ InlineData ( "-o custom.complog" , "custom.complog" ) ]
107
107
public void Create ( string extra , string fileName )
108
108
{
109
- Assert . Equal ( 0 , RunCompLog ( $ "create { extra } -p { Fixture . ConsoleProjectName } { Fixture . SolutionBinaryLogPath } ") ) ;
109
+ Assert . Equal ( Constants . ExitSuccess , RunCompLog ( $ "create { extra } -p { Fixture . ConsoleProjectName } { Fixture . SolutionBinaryLogPath } ") ) ;
110
110
var complogPath = Path . Combine ( RootDirectory , fileName ) ;
111
111
Assert . True ( File . Exists ( complogPath ) ) ;
112
112
}
@@ -115,7 +115,7 @@ public void Create(string extra, string fileName)
115
115
public void CreateProjectFile ( )
116
116
{
117
117
RunDotNet ( "new console --name console -o ." ) ;
118
- Assert . Equal ( 0 , RunCompLog ( $ "create console.csproj -o msbuild.complog") ) ;
118
+ Assert . Equal ( Constants . ExitSuccess , RunCompLog ( $ "create console.csproj -o msbuild.complog") ) ;
119
119
var complogPath = Path . Combine ( RootDirectory , "msbuild.complog" ) ;
120
120
using var reader = CompilerLogReader . Create ( complogPath , BasicAnalyzerHostOptions . None ) ;
121
121
Assert . Single ( reader . ReadAllCompilerCalls ( ) ) ;
@@ -129,7 +129,7 @@ public void CreateNoopBuild()
129
129
{
130
130
RunDotNet ( "new console --name console -o ." ) ;
131
131
RunDotNet ( "build" ) ;
132
- Assert . Equal ( 1 , RunCompLog ( $ "create console.csproj -o msbuild.complog -- -t:Build") ) ;
132
+ Assert . Equal ( Constants . ExitFailure , RunCompLog ( $ "create console.csproj -o msbuild.complog -- -t:Build") ) ;
133
133
var complogPath = Path . Combine ( RootDirectory , "msbuild.complog" ) ;
134
134
using var reader = CompilerLogReader . Create ( complogPath , BasicAnalyzerHostOptions . None ) ;
135
135
Assert . Empty ( reader . ReadAllCompilerCalls ( ) ) ;
@@ -142,7 +142,7 @@ public void CreateWithBuild()
142
142
RunCore ( Fixture . ConsoleProjectPath ) ;
143
143
void RunCore ( string filePath )
144
144
{
145
- Assert . Equal ( 0 , RunCompLog ( $ "create { filePath } -o msbuild.complog") ) ;
145
+ Assert . Equal ( Constants . ExitSuccess , RunCompLog ( $ "create { filePath } -o msbuild.complog") ) ;
146
146
var complogPath = Path . Combine ( RootDirectory , "msbuild.complog" ) ;
147
147
using var reader = CompilerLogReader . Create ( complogPath , BasicAnalyzerHostOptions . None ) ;
148
148
Assert . NotEmpty ( reader . ReadAllCompilerCalls ( ) ) ;
@@ -157,51 +157,51 @@ void RunCore(string filePath)
157
157
public void CreateEmpty ( )
158
158
{
159
159
var result = RunCompLog ( $ "create -p does-not-exist.csproj { Fixture . SolutionBinaryLogPath } ") ;
160
- Assert . NotEqual ( 0 , result ) ;
160
+ Assert . NotEqual ( Constants . ExitSuccess , result ) ;
161
161
}
162
162
163
163
[ Fact ]
164
164
public void CreateFullPath ( )
165
165
{
166
166
RunDotNet ( $ "new console --name example --output .") ;
167
167
RunDotNet ( "build -bl -nr:false" ) ;
168
- Assert . Equal ( 0 , RunCompLog ( $ "create { GetBinaryLogFullPath ( ) } ", RootDirectory ) ) ;
168
+ Assert . Equal ( Constants . ExitSuccess , RunCompLog ( $ "create { GetBinaryLogFullPath ( ) } ", RootDirectory ) ) ;
169
169
}
170
170
171
171
[ Fact ]
172
172
public void CreateOverRemovedProject ( )
173
173
{
174
- Assert . Equal ( 1 , RunCompLog ( $ "create { Fixture . RemovedBinaryLogPath } ") ) ;
174
+ Assert . Equal ( Constants . ExitFailure , RunCompLog ( $ "create { Fixture . RemovedBinaryLogPath } ") ) ;
175
175
}
176
176
177
177
[ Theory ]
178
178
[ InlineData ( "-h" ) ]
179
179
[ InlineData ( "-help" ) ]
180
180
public void CreateHelp ( string arg )
181
181
{
182
- Assert . Equal ( 1 , RunCompLog ( $ "create { arg } ") ) ;
182
+ Assert . Equal ( Constants . ExitFailure , RunCompLog ( $ "create { arg } ") ) ;
183
183
}
184
184
185
185
[ Fact ]
186
186
public void CreateExistingComplog ( )
187
187
{
188
188
var complogPath = Path . Combine ( RootDirectory , "file.complog" ) ;
189
189
File . WriteAllText ( complogPath , "" ) ;
190
- Assert . Equal ( 1 , RunCompLog ( $ "create { complogPath } ") ) ;
190
+ Assert . Equal ( Constants . ExitFailure , RunCompLog ( $ "create { complogPath } ") ) ;
191
191
}
192
192
193
193
[ Fact ]
194
194
public void CreateExtraArguments ( )
195
195
{
196
- Assert . Equal ( 1 , RunCompLog ( $ "create { Fixture . SolutionBinaryLogPath } extra") ) ;
196
+ Assert . Equal ( Constants . ExitFailure , RunCompLog ( $ "create { Fixture . SolutionBinaryLogPath } extra") ) ;
197
197
}
198
198
199
199
[ Fact ]
200
200
public void References ( )
201
201
{
202
202
RunWithBoth ( logPath =>
203
203
{
204
- Assert . Equal ( 0 , RunCompLog ( $ "ref -o { RootDirectory } { logPath } ") ) ;
204
+ Assert . Equal ( Constants . ExitSuccess , RunCompLog ( $ "ref -o { RootDirectory } { logPath } ") ) ;
205
205
Assert . NotEmpty ( Directory . EnumerateFiles ( Path . Combine ( RootDirectory , "console" , "refs" ) , "*.dll" ) ) ;
206
206
Assert . NotEmpty ( Directory . EnumerateFiles ( Path . Combine ( RootDirectory , "console" , "analyzers" ) , "*.dll" , SearchOption . AllDirectories ) ) ;
207
207
} ) ;
@@ -211,23 +211,47 @@ public void References()
211
211
public void ReferencesHelp ( )
212
212
{
213
213
var ( exitCode , output ) = RunCompLogEx ( $ "ref -h") ;
214
- Assert . Equal ( 0 , exitCode ) ;
214
+ Assert . Equal ( Constants . ExitSuccess , exitCode ) ;
215
215
Assert . StartsWith ( "complog ref [OPTIONS]" , output ) ;
216
216
}
217
217
218
218
[ Fact ]
219
219
public void ReferencesBadOption ( )
220
220
{
221
221
var ( exitCode , output ) = RunCompLogEx ( $ "ref --not-an-option") ;
222
- Assert . Equal ( 1 , exitCode ) ;
222
+ Assert . Equal ( Constants . ExitFailure , exitCode ) ;
223
223
Assert . Contains ( "complog ref [OPTIONS]" , output ) ;
224
224
}
225
225
226
226
[ Fact ]
227
- public void ResponseSingle ( )
227
+ public void ResponseSingleLine ( )
228
+ {
229
+ var exitCode = RunCompLog ( $ "rsp { Fixture . SolutionBinaryLogPath } -p console.csproj -s") ;
230
+ Assert . Equal ( Constants . ExitSuccess , exitCode ) ;
231
+ var rsp = Path . Combine ( RootDirectory , @".complog" , "console" , "build.rsp" ) ;
232
+ Assert . True ( File . Exists ( rsp ) ) ;
233
+
234
+ var lines = File . ReadAllLines ( rsp ) ;
235
+ Assert . Single ( lines ) ;
236
+ Assert . Contains ( "Program.cs" , lines [ 0 ] ) ;
237
+ }
238
+
239
+ [ Fact ]
240
+ public void ResponseOutputPath ( )
241
+ {
242
+ var dir = Root . NewDirectory ( "output" ) ;
243
+ var exitCode = RunCompLog ( $ "rsp { Fixture . SolutionBinaryLogPath } -p console.csproj -o { dir } ") ;
244
+ Assert . Equal ( Constants . ExitSuccess , exitCode ) ;
245
+ var rsp = Path . Combine ( dir , "console" , "build.rsp" ) ;
246
+ Assert . True ( File . Exists ( rsp ) ) ;
247
+ Assert . Contains ( "Program.cs" , File . ReadAllLines ( rsp ) ) ;
248
+ }
249
+
250
+ [ Fact ]
251
+ public void ResponseProjectFilter ( )
228
252
{
229
253
var exitCode = RunCompLog ( $ "rsp { Fixture . SolutionBinaryLogPath } -p console.csproj") ;
230
- Assert . Equal ( 0 , exitCode ) ;
254
+ Assert . Equal ( Constants . ExitSuccess , exitCode ) ;
231
255
var rsp = Path . Combine ( RootDirectory , @".complog" , "console" , "build.rsp" ) ;
232
256
Assert . True ( File . Exists ( rsp ) ) ;
233
257
Assert . Contains ( "Program.cs" , File . ReadAllLines ( rsp ) ) ;
@@ -237,7 +261,7 @@ public void ResponseSingle()
237
261
public void ResponseAll ( )
238
262
{
239
263
var exitCode = RunCompLog ( $ "rsp { Fixture . SolutionBinaryLogPath } ") ;
240
- Assert . Equal ( 0 , exitCode ) ;
264
+ Assert . Equal ( Constants . ExitSuccess , exitCode ) ;
241
265
var rsp = Path . Combine ( RootDirectory , @".complog" , "console" , "build.rsp" ) ;
242
266
Assert . True ( File . Exists ( rsp ) ) ;
243
267
Assert . Contains ( "Program.cs" , File . ReadAllLines ( rsp ) ) ;
@@ -247,26 +271,28 @@ public void ResponseAll()
247
271
public void ResponseHelp ( )
248
272
{
249
273
var ( exitCode , output ) = RunCompLogEx ( $ "rsp -h") ;
250
- Assert . Equal ( 0 , exitCode ) ;
274
+ Assert . Equal ( Constants . ExitSuccess , exitCode ) ;
251
275
Assert . StartsWith ( "complog rsp [OPTIONS]" , output ) ;
252
276
}
253
277
254
278
[ Fact ]
255
279
public void ResponseBadOption ( )
256
280
{
257
281
var ( exitCode , output ) = RunCompLogEx ( $ "rsp --not-an-option") ;
258
- Assert . Equal ( 1 , exitCode ) ;
282
+ Assert . Equal ( Constants . ExitFailure , exitCode ) ;
259
283
Assert . Contains ( "complog rsp [OPTIONS]" , output ) ;
260
284
}
261
285
262
- [ Fact ]
263
- public void ExportCompilerLog ( )
286
+ [ Theory ]
287
+ [ InlineData ( "" ) ]
288
+ [ InlineData ( "--exclude-analyzers" ) ]
289
+ public void ExportCompilerLog ( string arg )
264
290
{
265
291
RunWithBoth ( logPath =>
266
292
{
267
293
using var exportDir = new TempDir ( ) ;
268
294
269
- Assert . Equal ( 0 , RunCompLog ( $ "export -o { exportDir . DirectoryPath } { logPath } ", RootDirectory ) ) ;
295
+ Assert . Equal ( Constants . ExitSuccess , RunCompLog ( $ "export -o { exportDir . DirectoryPath } { arg } { logPath } ", RootDirectory ) ) ;
270
296
271
297
// Now run the generated build.cmd and see if it succeeds;
272
298
var exportPath = Path . Combine ( exportDir . DirectoryPath , "console" , "export" ) ;
@@ -275,30 +301,59 @@ public void ExportCompilerLog()
275
301
} ) ;
276
302
}
277
303
304
+ [ Fact ]
305
+ public void ExportHelp ( )
306
+ {
307
+ var ( exitCode , output ) = RunCompLogEx ( $ "export -h") ;
308
+ Assert . Equal ( Constants . ExitSuccess , exitCode ) ;
309
+ Assert . StartsWith ( "complog export [OPTIONS]" , output ) ;
310
+ }
311
+
312
+ [ Fact ]
313
+ public void ExportBadOption ( )
314
+ {
315
+ var ( exitCode , output ) = RunCompLogEx ( $ "export --not-an-option") ;
316
+ Assert . Equal ( Constants . ExitFailure , exitCode ) ;
317
+ Assert . Contains ( "complog export [OPTIONS]" , output ) ;
318
+ }
319
+
278
320
[ Fact ]
279
321
public void Help ( )
280
322
{
281
323
var ( exitCode , output ) = RunCompLogEx ( $ "help") ;
282
- Assert . Equal ( 0 , exitCode ) ;
324
+ Assert . Equal ( Constants . ExitSuccess , exitCode ) ;
283
325
Assert . StartsWith ( "complog [command] [args]" , output ) ;
284
326
}
285
327
286
328
[ Fact ]
287
329
public void HelpVerbose ( )
288
330
{
289
331
var ( exitCode , output ) = RunCompLogEx ( $ "help -v") ;
290
- Assert . Equal ( 0 , exitCode ) ;
332
+ Assert . Equal ( Constants . ExitSuccess , exitCode ) ;
291
333
Assert . StartsWith ( "complog [command] [args]" , output ) ;
292
334
Assert . Contains ( "Commands can be passed a .complog, " , output ) ;
293
335
}
294
336
337
+ [ Theory ]
338
+ [ InlineData ( "replay" , "" ) ]
339
+ [ InlineData ( "replay" , "-none" ) ]
340
+ [ InlineData ( "replay" , "-analyzers" ) ]
341
+ [ InlineData ( "replay" , "-severity Error" ) ]
342
+ [ InlineData ( "emit" , "-none" ) ]
343
+ [ InlineData ( "diagnostics" , "-none" ) ]
344
+ public void ReplayWithArgs ( string command , string arg )
345
+ {
346
+ using var emitDir = new TempDir ( ) ;
347
+ Assert . Equal ( Constants . ExitSuccess , RunCompLog ( $ "{ command } { arg } { Fixture . SolutionBinaryLogPath } ") ) ;
348
+ }
349
+
295
350
[ Theory ]
296
351
[ InlineData ( "" ) ]
297
352
[ InlineData ( "-none" ) ]
298
353
public void ReplayConsoleWithEmit ( string arg )
299
354
{
300
355
using var emitDir = new TempDir ( ) ;
301
- RunCompLog ( $ "replay { arg } -emit -o { emitDir . DirectoryPath } { Fixture . SolutionBinaryLogPath } ") ;
356
+ Assert . Equal ( Constants . ExitSuccess , RunCompLog ( $ "replay { arg } -emit -o { emitDir . DirectoryPath } { Fixture . SolutionBinaryLogPath } ") ) ;
302
357
303
358
AssertOutput ( @"console\emit\console.dll" ) ;
304
359
AssertOutput ( @"console\emit\console.pdb" ) ;
@@ -316,11 +371,45 @@ void AssertOutput(string relativePath)
316
371
}
317
372
}
318
373
374
+ [ Fact ]
375
+ public void ReplayHelp ( )
376
+ {
377
+ var ( exitCode , output ) = RunCompLogEx ( $ "replay -h") ;
378
+ Assert . Equal ( Constants . ExitSuccess , exitCode ) ;
379
+ Assert . StartsWith ( "complog replay [OPTIONS]" , output ) ;
380
+ }
381
+
382
+ [ Fact ]
383
+ public void ReplayBadOption ( )
384
+ {
385
+ var ( exitCode , output ) = RunCompLogEx ( $ "replay --not-an-option") ;
386
+ Assert . Equal ( Constants . ExitFailure , exitCode ) ;
387
+ Assert . Contains ( "complog replay [OPTIONS]" , output ) ;
388
+ }
389
+
390
+ [ Fact ]
391
+ public void RelpayBadOptionCombination ( )
392
+ {
393
+ var ( exitCode , output ) = RunCompLogEx ( $ "replay -o example") ;
394
+ Assert . Equal ( Constants . ExitFailure , exitCode ) ;
395
+ Assert . StartsWith ( "Error: Specified a path" , output ) ;
396
+ }
397
+
398
+ [ Fact ]
399
+ public void ReplayWithExport ( )
400
+ {
401
+ var ( exitCode , output ) = RunCompLogEx ( $ "replay { Fixture . ConsoleWithDiagnosticsBinaryLogPath } -export -o { RootDirectory } ") ;
402
+ Assert . Equal ( Constants . ExitFailure , exitCode ) ;
403
+ Assert . Contains ( "Exporting to" , output ) ;
404
+ Assert . True ( File . Exists ( Path . Combine ( RootDirectory , "console-with-diagnostics" , "export" , "build.cmd" ) ) ) ;
405
+ Assert . True ( File . Exists ( Path . Combine ( RootDirectory , "console-with-diagnostics" , "export" , "ref" , "netstandard.dll" ) ) ) ;
406
+ }
407
+
319
408
[ Fact ]
320
409
public void PrintAll ( )
321
410
{
322
411
var ( exitCode , output ) = RunCompLogEx ( $ "print { Fixture . SolutionBinaryLogPath } ") ;
323
- Assert . Equal ( 0 , exitCode ) ;
412
+ Assert . Equal ( Constants . ExitSuccess , exitCode ) ;
324
413
Assert . Contains ( "console.csproj (net7.0)" , output ) ;
325
414
Assert . Contains ( "classlib.csproj (net7.0)" , output ) ;
326
415
}
@@ -329,24 +418,36 @@ public void PrintAll()
329
418
public void PrintOne ( )
330
419
{
331
420
var ( exitCode , output ) = RunCompLogEx ( $ "print { Fixture . SolutionBinaryLogPath } -p classlib.csproj") ;
332
- Assert . Equal ( 0 , exitCode ) ;
421
+ Assert . Equal ( Constants . ExitSuccess , exitCode ) ;
333
422
Assert . DoesNotContain ( "console.csproj (net7.0)" , output ) ;
334
423
Assert . Contains ( "classlib.csproj (net7.0)" , output ) ;
335
424
}
336
425
426
+ /// <summary>
427
+ /// Engage the code to find files in the specidied directory
428
+ /// </summary>
429
+ [ Fact ]
430
+ public void PrintDirectory ( )
431
+ {
432
+ Assert . Equal ( Constants . ExitSuccess , RunCompLog ( $ "print { Path . GetDirectoryName ( Fixture . SolutionBinaryLogPath ) } ") ) ;
433
+
434
+ // Make sure this works on a build that will fail!
435
+ Assert . Equal ( Constants . ExitSuccess , RunCompLog ( $ "print { Path . GetDirectoryName ( Fixture . ConsoleWithDiagnosticsProjectPath ) } ") ) ;
436
+ }
437
+
337
438
[ Fact ]
338
439
public void PrintHelp ( )
339
440
{
340
441
var ( exitCode , output ) = RunCompLogEx ( $ "print -h") ;
341
- Assert . Equal ( 0 , exitCode ) ;
442
+ Assert . Equal ( Constants . ExitSuccess , exitCode ) ;
342
443
Assert . StartsWith ( "complog print [OPTIONS]" , output ) ;
343
444
}
344
445
345
446
[ Fact ]
346
447
public void PrintError ( )
347
448
{
348
449
var ( exitCode , output ) = RunCompLogEx ( $ "print --not-an-option") ;
349
- Assert . Equal ( 1 , exitCode ) ;
450
+ Assert . Equal ( Constants . ExitFailure , exitCode ) ;
350
451
Assert . Contains ( "complog print [OPTIONS]" , output ) ;
351
452
}
352
453
0 commit comments