|
1 | 1 | using System; |
2 | 2 | using System.IO; |
3 | 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
4 | | -using ServerCodeExciser; |
5 | 4 | using ServerCodeExcisionCommon; |
6 | 5 | using UnrealAngelscriptServerCodeExcision; |
7 | 6 |
|
8 | | -[TestClass] |
9 | | -public class ExcisionIntegrationTests |
| 7 | +namespace ServerCodeExciser.Tests |
10 | 8 | { |
11 | | - private static string DataRootDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "..", "..", "..")); |
12 | | - |
13 | | - [TestMethod] |
14 | | - public void ExciseAngelscriptCases() |
| 9 | + [TestClass] |
| 10 | + public class ExcisionIntegrationTests |
15 | 11 | { |
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 | | - } |
| 12 | + private static string DataRootDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "..", "..", "..")); |
48 | 13 |
|
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)) |
| 14 | + [TestMethod] |
| 15 | + public void ExciseAngelscriptCases() |
53 | 16 | { |
54 | | - Directory.Delete(outputPath, true); |
| 17 | + int numTestFailures = 0; |
| 18 | + int numTestCases = 0; |
| 19 | + |
| 20 | + // Run for Angelscript |
| 21 | + var actual = RunExciserIntegrationTests( |
| 22 | + ".as", |
| 23 | + Path.Combine(DataRootDir, "Problems", "Angelscript"), |
| 24 | + Path.Combine(DataRootDir, "Answers", "Angelscript"), |
| 25 | + ref numTestFailures, |
| 26 | + ref numTestCases); |
| 27 | + |
| 28 | + Assert.AreEqual(EExciserReturnValues.Success, actual); |
| 29 | + Assert.AreEqual(0, numTestFailures); |
55 | 30 | } |
56 | 31 |
|
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) |
| 32 | + [TestMethod] |
| 33 | + public void ExciseCommonCases() |
79 | 34 | { |
80 | | - throw; |
| 35 | + int numTestFailures = 0; |
| 36 | + int numTestCases = 0; |
| 37 | + |
| 38 | + // Run for "common" |
| 39 | + var actual = RunExciserIntegrationTests( |
| 40 | + ".common", |
| 41 | + Path.Combine(DataRootDir, "Problems", "Common"), |
| 42 | + Path.Combine(DataRootDir, "Answers", "Common"), |
| 43 | + ref numTestFailures, |
| 44 | + ref numTestCases); |
| 45 | + |
| 46 | + Assert.AreEqual(EExciserReturnValues.Success, actual); |
| 47 | + Assert.AreEqual(0, numTestFailures); |
81 | 48 | } |
82 | 49 |
|
83 | | - foreach (var answerFilePath in Directory.EnumerateFiles(outputPath, searchPattern, SearchOption.AllDirectories)) |
| 50 | + private static EExciserReturnValues RunExciserIntegrationTests(string fileExtension, string inputPath, string outputPath, ref int numTestFailures, ref int numTestCases) |
84 | 51 | { |
85 | | - numTestCases++; |
86 | | - |
87 | | - var solutionFilePath = Path.Combine(inputPath, Path.GetRelativePath(outputPath, answerFilePath)) + ".solution"; |
| 52 | + // Clean up earlier answers. |
| 53 | + if (Directory.Exists(outputPath)) |
| 54 | + { |
| 55 | + Directory.Delete(outputPath, true); |
| 56 | + } |
88 | 57 |
|
89 | | - var fileName = Path.GetFileName(answerFilePath); |
90 | | - var answer = File.ReadAllText(answerFilePath); |
91 | | - var solution = File.ReadAllText(solutionFilePath); |
| 58 | + string searchPattern = "*." + fileExtension.TrimStart('.'); |
| 59 | + Console.WriteLine($"Running integration tests for {searchPattern} files..."); |
92 | 60 |
|
93 | | - if (answer == solution) |
| 61 | + EExciserReturnValues returnCode; |
| 62 | + try |
94 | 63 | { |
95 | | - Console.ForegroundColor = ConsoleColor.Green; |
96 | | - Console.WriteLine(fileName + " passed!"); |
97 | | - Console.ForegroundColor = ConsoleColor.Gray; |
| 64 | + var excisionParams = new ServerCodeExcisionParameters |
| 65 | + { |
| 66 | + OutputPath = outputPath, |
| 67 | + ShouldOutputUntouchedFiles = true, |
| 68 | + FullExcisionRegexString = @"FullExcise1/.*", |
| 69 | + ExciseAllFunctionsRegexString = @"AllFunctionExcise1/.*|||AllFunctionExcise2/.*", |
| 70 | + StrictMode = true, |
| 71 | + DontSkip = true, |
| 72 | + }; |
| 73 | + excisionParams.InputPaths.Add(inputPath); |
| 74 | + |
| 75 | + var angelscriptServerCodeExciser = new ServerCodeExcisionProcessor(excisionParams); |
| 76 | + returnCode = angelscriptServerCodeExciser.ExciseServerCode(searchPattern, new UnrealAngelscriptServerCodeExcisionLanguage()); |
| 77 | + Console.WriteLine($"ExciseServerCode for {searchPattern} files returned: {returnCode}"); |
98 | 78 | } |
99 | | - else |
| 79 | + catch (Exception) |
100 | 80 | { |
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++; |
| 81 | + throw; |
109 | 82 | } |
110 | | - } |
111 | 83 |
|
112 | | - return returnCode; |
| 84 | + foreach (var answerFilePath in Directory.EnumerateFiles(outputPath, searchPattern, SearchOption.AllDirectories)) |
| 85 | + { |
| 86 | + numTestCases++; |
| 87 | + |
| 88 | + var solutionFilePath = Path.Combine(inputPath, Path.GetRelativePath(outputPath, answerFilePath)) + ".solution"; |
| 89 | + |
| 90 | + var fileName = Path.GetFileName(answerFilePath); |
| 91 | + var answer = File.ReadAllText(answerFilePath); |
| 92 | + var solution = File.ReadAllText(solutionFilePath); |
| 93 | + |
| 94 | + if (answer == solution) |
| 95 | + { |
| 96 | + Console.ForegroundColor = ConsoleColor.Green; |
| 97 | + Console.WriteLine(fileName + " passed!"); |
| 98 | + Console.ForegroundColor = ConsoleColor.Gray; |
| 99 | + } |
| 100 | + else |
| 101 | + { |
| 102 | + Console.ForegroundColor = ConsoleColor.Red; |
| 103 | + Console.Error.WriteLine(fileName + " failed!"); |
| 104 | + Console.ForegroundColor = ConsoleColor.Gray; |
| 105 | + Console.WriteLine("--- Expected: ---"); |
| 106 | + Console.WriteLine(solution); |
| 107 | + Console.WriteLine("--- Actual: ---"); |
| 108 | + Console.WriteLine(answer); |
| 109 | + numTestFailures++; |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + return returnCode; |
| 114 | + } |
113 | 115 | } |
114 | 116 | } |
0 commit comments