-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathCommandLineParsingTest.cs
130 lines (116 loc) · 5.68 KB
/
CommandLineParsingTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
namespace Cesium.Compiler.Tests
{
public class CommandLineParsingTest
{
[Fact]
public async Task CompileMainArguments()
{
var args = new[] { "C:\\doom-clr\\doom.c", "-o", "C:\\\\Cesium\\\\Cesium.IntegrationTests/bin/doom.exe" };
var reporter = new MockCompilerReporter();
var errorCode = await CommandLineParser.ParseCommandLineArgs(args, reporter, args =>
{
Assert.Equal(new[] { "C:\\doom-clr\\doom.c" }, args.InputFilePaths);
Assert.Equal("C:\\\\Cesium\\\\Cesium.IntegrationTests/bin/doom.exe", args.OutputFilePath);
Assert.Empty(reporter.Errors);
NoInformationalMessages(reporter);
return Task.FromResult(0);
});
NoInformationalMessages(reporter);
Assert.Empty(reporter.Errors);
Assert.Equal(0, errorCode);
}
[Fact]
public async Task MissingOutputPath()
{
var args = new[] { "C:\\doom-clr\\doom.c" };
var reporter = new MockCompilerReporter();
var errorCode = await CommandLineParser.ParseCommandLineArgs(args, reporter, args =>
{
return Task.FromResult(0);
});
NoInformationalMessages(reporter);
Assert.Equal(new[] { "Required option 'o, out' is missing." }, reporter.Errors);
Assert.Equal(3, errorCode);
}
[Fact]
public async Task MissingSourceFiles()
{
var args = new[] { "-o", "C:\\doom-clr\\doom.exe" };
var reporter = new MockCompilerReporter();
var errorCode = await CommandLineParser.ParseCommandLineArgs(args, reporter, args =>
{
return Task.FromResult(0);
});
NoInformationalMessages(reporter);
Assert.Equal(new[] { "Input file paths should be defined." }, reporter.Errors);
Assert.Equal(2, errorCode);
}
[Fact]
public async Task CompileMultipleCompilationFilesMainArguments()
{
var args = new[] { "C:\\folder\\file1.c", "C:\\folder\\file2.c", "-o", "C:\\\\Cesium\\\\Cesium.IntegrationTests/bin/doom.exe" };
var reporter = new MockCompilerReporter();
var errorCode = await CommandLineParser.ParseCommandLineArgs(args, reporter, args =>
{
Assert.Equal(new[] { "C:\\folder\\file1.c", "C:\\folder\\file2.c" }, args.InputFilePaths);
Assert.Equal("C:\\\\Cesium\\\\Cesium.IntegrationTests/bin/doom.exe", args.OutputFilePath);
return Task.FromResult(0);
});
NoInformationalMessages(reporter);
Assert.Empty(reporter.Errors);
Assert.Equal(0, errorCode);
}
[Fact]
public async Task PreprocessFile()
{
var args = new[] { "C:\\Cesium\\Cesium.Samples\\getopt.c", "-E" };
var reporter = new MockCompilerReporter();
var errorCode = await CommandLineParser.ParseCommandLineArgs(args, reporter, args =>
{
Assert.Equal(new[] { "C:\\Cesium\\Cesium.Samples\\getopt.c" }, args.InputFilePaths);
Assert.True(args.ProducePreprocessedFile);
return Task.FromResult(0);
});
Assert.Empty(reporter.InformationMessages);
Assert.Empty(reporter.Errors);
Assert.Equal(0, errorCode);
}
[Fact]
public async Task MultipleIncludeFiles()
{
var args = new[] { "C:\\Cesium\\Cesium.Samples\\getopt.c", "-o", "C:\\\\Cesium\\\\Cesium.IntegrationTests/bin/doom.exe", "-I", "C:\\\\Cesium\\\\Cesium.Samples\\\\", "-I", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\um\\" };
var reporter = new MockCompilerReporter();
var errorCode = await CommandLineParser.ParseCommandLineArgs(args, reporter, args =>
{
Assert.Equal(new[] { "C:\\Cesium\\Cesium.Samples\\getopt.c" }, args.InputFilePaths);
Assert.Equal("C:\\\\Cesium\\\\Cesium.IntegrationTests/bin/doom.exe", args.OutputFilePath);
Assert.Equal(new[] { "C:\\\\Cesium\\\\Cesium.Samples\\\\", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\um\\" }, args.IncludeDirectories);
return Task.FromResult(0);
});
NoInformationalMessages(reporter);
Assert.Empty(reporter.Errors);
Assert.Equal(0, errorCode);
}
[Fact]
public async Task MultipleDefinesFiles()
{
var args = new[] { "C:\\Cesium\\Cesium.Samples\\getopt.c", "-o", "C:\\\\Cesium\\\\Cesium.IntegrationTests/bin/doom.exe", "-D", "TEST_1", "-D", "TEST_2" };
var reporter = new MockCompilerReporter();
var errorCode = await CommandLineParser.ParseCommandLineArgs(args, reporter, args =>
{
Assert.Equal(new[] { "C:\\Cesium\\Cesium.Samples\\getopt.c" }, args.InputFilePaths);
Assert.Equal("C:\\\\Cesium\\\\Cesium.IntegrationTests/bin/doom.exe", args.OutputFilePath);
Assert.Equal(new[] { "TEST_1", "TEST_2" }, args.DefineConstant);
return Task.FromResult(0);
});
NoInformationalMessages(reporter);
Assert.Empty(reporter.Errors);
Assert.Equal(0, errorCode);
}
private static void NoInformationalMessages(MockCompilerReporter reporter)
{
Assert.NotNull(reporter.InformationMessages.Single(_ => _.StartsWith("Cesium v")));
Assert.Empty(reporter.InformationMessages.Where(_ => !_.StartsWith("Cesium v")));
}
}
}