Skip to content

Commit 26db68e

Browse files
committed
Further code cleanup.
1 parent 9acf3b0 commit 26db68e

File tree

12 files changed

+359
-308
lines changed

12 files changed

+359
-308
lines changed

ServerCodeExciser/PreprocessorParser.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using Antlr4.Runtime;
@@ -8,7 +8,7 @@ namespace ServerCodeExciser
88
{
99
public class PreprocessorParser
1010
{
11-
public static List<PreprocessorNode> Parse(BufferedTokenStream tokenStream)
11+
public static List<PreprocessorScope> Parse(BufferedTokenStream tokenStream)
1212
{
1313
var directives = tokenStream
1414
.GetTokens()
@@ -17,8 +17,8 @@ public static List<PreprocessorNode> Parse(BufferedTokenStream tokenStream)
1717
.OrderBy(t => t.StartIndex)
1818
.ToList();
1919

20-
var rootNodes = new List<PreprocessorNode>();
21-
var ifStack = new Stack<PreprocessorNode>();
20+
var rootScopes = new List<PreprocessorScope>();
21+
var ifStack = new Stack<PreprocessorScope>();
2222

2323
foreach (var token in directives)
2424
{
@@ -33,7 +33,7 @@ public static List<PreprocessorNode> Parse(BufferedTokenStream tokenStream)
3333
}
3434
else
3535
{
36-
rootNodes.Add(scope);
36+
rootScopes.Add(scope);
3737
}
3838
ifStack.Push(scope);
3939
}
@@ -75,12 +75,12 @@ public static List<PreprocessorNode> Parse(BufferedTokenStream tokenStream)
7575
}
7676
}
7777

78-
return rootNodes;
78+
return rootScopes;
7979
}
8080

81-
private static PreprocessorNode CreateScope(IToken token)
81+
private static PreprocessorScope CreateScope(IToken token)
8282
{
83-
return new PreprocessorNode(
83+
return new PreprocessorScope(
8484
token.Text,
8585
new SourceSpan(
8686
token.Line,
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using ServerCodeExcisionCommon;
33

44
namespace ServerCodeExciser
55
{
6-
public sealed class PreprocessorNode
6+
public sealed class PreprocessorScope
77
{
8-
public PreprocessorNode(string directive, SourceSpan span)
8+
public PreprocessorScope(string directive, SourceSpan span)
99
{
1010
Directive = directive;
1111
Span = span;
@@ -15,6 +15,6 @@ public PreprocessorNode(string directive, SourceSpan span)
1515

1616
public SourceSpan Span { get; set; }
1717

18-
public List<PreprocessorNode> Children { get; set; } = new();
18+
public List<PreprocessorScope> Children { get; set; } = new();
1919
}
2020
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Runtime.CompilerServices;
2+
using System.Runtime.InteropServices;
3+
4+
// In SDK-style projects such as this one, several assembly attributes that were historically
5+
// defined in this file are now automatically added during build and populated with
6+
// values defined in project properties. For details of which attributes are included
7+
// and how to customise this process see: https://aka.ms/assembly-info-properties
8+
9+
10+
// Setting ComVisible to false makes the types in this assembly not visible to COM
11+
// components. If you need to access a type in this assembly from COM, set the ComVisible
12+
// attribute to true on that type.
13+
14+
[assembly: ComVisible(false)]
15+
16+
// The following GUID is for the ID of the typelib if this project is exposed to COM.
17+
18+
[assembly: Guid("f2a9e88b-71e2-43d8-8627-59199a0ff9ea")]
19+
20+
[assembly: InternalsVisibleTo("ServerCodeExciserTest")]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"ServerCodeExciser": {
4+
"commandName": "Project",
5+
"commandLineArgs": "-s -o D:\\test D:\\p4\\games\\Games\\Discovery\\Script"
6+
}
7+
}
8+
}

ServerCodeExciser/ServerCodeExcisionProcessor.cs

Lines changed: 107 additions & 182 deletions
Large diffs are not rendered by default.

ServerCodeExciserTest/ExcisionIntegrationTests.cs

Lines changed: 91 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -5,110 +5,113 @@
55
using ServerCodeExcisionCommon;
66
using UnrealAngelscriptServerCodeExcision;
77

8-
[TestClass]
9-
public class ExcisionIntegrationTests
8+
namespace ServerCodeExciser.Tests
109
{
11-
private static string DataRootDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "..", "..", ".."));
12-
13-
[TestMethod]
14-
public void ExciseAngelscriptCases()
10+
[TestClass]
11+
public class ExcisionIntegrationTests
1512
{
16-
int numTestFailures = 0;
17-
int numTestCases = 0;
18-
19-
// Run for Angelscript
20-
var actual = RunExciserIntegrationTests(
21-
".as",
22-
Path.Combine(DataRootDir, "Problems", "Angelscript"),
23-
Path.Combine(DataRootDir, "Answers", "Angelscript"),
24-
ref numTestFailures,
25-
ref numTestCases);
26-
27-
Assert.AreEqual(EExciserReturnValues.Success, actual);
28-
Assert.AreEqual(0, numTestFailures);
29-
}
30-
31-
[TestMethod]
32-
public void ExciseCommonCases()
33-
{
34-
int numTestFailures = 0;
35-
int numTestCases = 0;
36-
37-
// Run for "common"
38-
var actual = RunExciserIntegrationTests(
39-
".common",
40-
Path.Combine(DataRootDir, "Problems", "Common"),
41-
Path.Combine(DataRootDir, "Answers", "Common"),
42-
ref numTestFailures,
43-
ref numTestCases);
44-
45-
Assert.AreEqual(EExciserReturnValues.Success, actual);
46-
Assert.AreEqual(0, numTestFailures);
47-
}
13+
private static string DataRootDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "..", "..", ".."));
4814

49-
private static EExciserReturnValues RunExciserIntegrationTests(string fileExtension, string inputPath, string outputPath, ref int numTestFailures, ref int numTestCases)
50-
{
51-
// Clean up earlier answers.
52-
if (Directory.Exists(outputPath))
15+
[TestMethod]
16+
public void ExciseAngelscriptCases()
5317
{
54-
Directory.Delete(outputPath, true);
18+
int numTestFailures = 0;
19+
int numTestCases = 0;
20+
21+
// Run for Angelscript
22+
var actual = RunExciserIntegrationTests(
23+
".as",
24+
Path.Combine(DataRootDir, "Problems", "Angelscript"),
25+
Path.Combine(DataRootDir, "Answers", "Angelscript"),
26+
ref numTestFailures,
27+
ref numTestCases);
28+
29+
Assert.AreEqual(EExciserReturnValues.Success, actual);
30+
Assert.AreEqual(0, numTestFailures);
5531
}
5632

57-
string searchPattern = "*." + fileExtension.TrimStart('.');
58-
Console.WriteLine($"Running integration tests for {searchPattern} files...");
59-
60-
EExciserReturnValues returnCode;
61-
try
62-
{
63-
var excisionParams = new ServerCodeExcisionParameters
64-
{
65-
OutputPath = outputPath,
66-
ShouldOutputUntouchedFiles = true,
67-
FullExcisionRegexString = @"FullExcise1/.*",
68-
ExciseAllFunctionsRegexString = @"AllFunctionExcise1/.*|||AllFunctionExcise2/.*",
69-
StrictMode = true,
70-
DontSkip = true,
71-
};
72-
excisionParams.InputPaths.Add(inputPath);
73-
74-
var angelscriptServerCodeExciser = new ServerCodeExcisionProcessor(excisionParams);
75-
returnCode = angelscriptServerCodeExciser.ExciseServerCode(searchPattern, new UnrealAngelscriptServerCodeExcisionLanguage());
76-
Console.WriteLine($"ExciseServerCode for {searchPattern} files returned: {returnCode}");
77-
}
78-
catch (Exception)
33+
[TestMethod]
34+
public void ExciseCommonCases()
7935
{
80-
throw;
36+
int numTestFailures = 0;
37+
int numTestCases = 0;
38+
39+
// Run for "common"
40+
var actual = RunExciserIntegrationTests(
41+
".common",
42+
Path.Combine(DataRootDir, "Problems", "Common"),
43+
Path.Combine(DataRootDir, "Answers", "Common"),
44+
ref numTestFailures,
45+
ref numTestCases);
46+
47+
Assert.AreEqual(EExciserReturnValues.Success, actual);
48+
Assert.AreEqual(0, numTestFailures);
8149
}
8250

83-
foreach (var answerFilePath in Directory.EnumerateFiles(outputPath, searchPattern, SearchOption.AllDirectories))
51+
private static EExciserReturnValues RunExciserIntegrationTests(string fileExtension, string inputPath, string outputPath, ref int numTestFailures, ref int numTestCases)
8452
{
85-
numTestCases++;
86-
87-
var solutionFilePath = Path.Combine(inputPath, Path.GetRelativePath(outputPath, answerFilePath)) + ".solution";
53+
// Clean up earlier answers.
54+
if (Directory.Exists(outputPath))
55+
{
56+
Directory.Delete(outputPath, true);
57+
}
8858

89-
var fileName = Path.GetFileName(answerFilePath);
90-
var answer = File.ReadAllText(answerFilePath);
91-
var solution = File.ReadAllText(solutionFilePath);
59+
string searchPattern = "*." + fileExtension.TrimStart('.');
60+
Console.WriteLine($"Running integration tests for {searchPattern} files...");
9261

93-
if (answer == solution)
62+
EExciserReturnValues returnCode;
63+
try
9464
{
95-
Console.ForegroundColor = ConsoleColor.Green;
96-
Console.WriteLine(fileName + " passed!");
97-
Console.ForegroundColor = ConsoleColor.Gray;
65+
var excisionParams = new ServerCodeExcisionParameters
66+
{
67+
OutputPath = outputPath,
68+
ShouldOutputUntouchedFiles = true,
69+
FullExcisionRegexString = @"FullExcise1/.*",
70+
ExciseAllFunctionsRegexString = @"AllFunctionExcise1/.*|||AllFunctionExcise2/.*",
71+
StrictMode = true,
72+
DontSkip = true,
73+
};
74+
excisionParams.InputPaths.Add(inputPath);
75+
76+
var angelscriptServerCodeExciser = new ServerCodeExcisionProcessor(excisionParams);
77+
returnCode = angelscriptServerCodeExciser.ExciseServerCode(searchPattern, new UnrealAngelscriptServerCodeExcisionLanguage());
78+
Console.WriteLine($"ExciseServerCode for {searchPattern} files returned: {returnCode}");
9879
}
99-
else
80+
catch (Exception)
10081
{
101-
Console.ForegroundColor = ConsoleColor.Red;
102-
Console.Error.WriteLine(fileName + " failed!");
103-
Console.ForegroundColor = ConsoleColor.Gray;
104-
Console.WriteLine("--- Expected: ---");
105-
Console.WriteLine(solution);
106-
Console.WriteLine("--- Actual: ---");
107-
Console.WriteLine(answer);
108-
numTestFailures++;
82+
throw;
10983
}
110-
}
11184

112-
return returnCode;
85+
foreach (var answerFilePath in Directory.EnumerateFiles(outputPath, searchPattern, SearchOption.AllDirectories))
86+
{
87+
numTestCases++;
88+
89+
var solutionFilePath = Path.Combine(inputPath, Path.GetRelativePath(outputPath, answerFilePath)) + ".solution";
90+
91+
var fileName = Path.GetFileName(answerFilePath);
92+
var answer = File.ReadAllText(answerFilePath);
93+
var solution = File.ReadAllText(solutionFilePath);
94+
95+
if (answer == solution)
96+
{
97+
Console.ForegroundColor = ConsoleColor.Green;
98+
Console.WriteLine(fileName + " passed!");
99+
Console.ForegroundColor = ConsoleColor.Gray;
100+
}
101+
else
102+
{
103+
Console.ForegroundColor = ConsoleColor.Red;
104+
Console.Error.WriteLine(fileName + " failed!");
105+
Console.ForegroundColor = ConsoleColor.Gray;
106+
Console.WriteLine("--- Expected: ---");
107+
Console.WriteLine(solution);
108+
Console.WriteLine("--- Actual: ---");
109+
Console.WriteLine(answer);
110+
numTestFailures++;
111+
}
112+
}
113+
114+
return returnCode;
115+
}
113116
}
114117
}

0 commit comments

Comments
 (0)