Skip to content

Commit 205c809

Browse files
committed
updates
1 parent 7970c68 commit 205c809

File tree

6 files changed

+78
-51
lines changed

6 files changed

+78
-51
lines changed

.github/workflows/DEMO-run-codeql-unit-tests-cpp.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,5 @@ jobs:
125125
- name: Validate test results
126126
run: |
127127
qlt test run validate-unit-tests --results-directory .
128+
qlt test run validate-unit-tests --pretty-print --results-directory . >> $GITHUB_STEP_SUMMARY
129+

src/CodeQLToolkit.Core/Main.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ internal class QLT
1717
public static async Task<int> Main(string[] args)
1818
{
1919
Log<QLT>.G().LogInformation("QLT Startup...");
20-
20+
21+
Console.OutputEncoding = System.Text.Encoding.UTF8;
22+
2123
var rootCommand = new RootCommand();
2224

2325
// Add global option for the root directory

src/CodeQLToolkit.Core/ver.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.11
1+
0.0.12

src/CodeQLToolkit.Features.Test/Commands/Targets/ValidateUnitTestsCommand.cs

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ public class ValidateUnitTestsCommand : CommandTarget
2727
{
2828
public string ResultsDirectory { get; set; }
2929

30+
public bool PrettyPrint { get; set; }
3031

3132
public override void Run()
3233
{
3334
Log<ValidateUnitTestsCommand>.G().LogInformation($"Validating unit tests in {ResultsDirectory}");
3435

3536
string[] results = Directory.GetFiles(ResultsDirectory, "test_report_*", SearchOption.AllDirectories);
3637

37-
List<UnitTestResult> failures = new List<UnitTestResult>();
38+
List<UnitTestResult> unitTestResults = new List<UnitTestResult>();
3839

3940
foreach (string result in results)
4041
{
@@ -44,75 +45,92 @@ public override void Run()
4445
List<UnitTestResult> items = JsonConvert.DeserializeObject<List<UnitTestResult>>(json);
4546

4647
foreach(var item in items)
47-
{
48-
if (item.pass == false)
49-
{
50-
failures.Add(item);
51-
}
48+
{
49+
unitTestResults.Add(item);
5250
}
5351
}
5452
}
5553

56-
if(failures.Count > 0 )
57-
{
58-
Log<ValidateUnitTestsCommand>.G().LogError($"One or more unit tests failed. Details below:");
59-
Log<ValidateUnitTestsCommand>.G().LogError($"---------------------------------------------");
6054

61-
int totalCases = failures.Count;
62-
int currentCase = 0;
55+
int totalCases = unitTestResults.Count;
56+
int currentCase = 0;
6357

58+
foreach (var item in unitTestResults)
59+
{
60+
currentCase++;
6461

65-
foreach (var item in failures)
62+
if (item.pass)
6663
{
67-
currentCase++;
68-
69-
if(item.failureStage == "RESULT")
64+
if(PrettyPrint)
65+
{
66+
Console.WriteLine($" ✅ [PASS] ({currentCase} of {totalCases}) {item.test}");
67+
}
68+
else
7069
{
7170
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
7271
Log<ValidateUnitTestsCommand>.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}");
7372
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
74-
Log<ValidateUnitTestsCommand>.G().LogError($"| STATUS : FAILED ");
75-
Log<ValidateUnitTestsCommand>.G().LogError($"| FAILURE TYPE : RESULT");
73+
Log<ValidateUnitTestsCommand>.G().LogError($"| STATUS : PASSED ");
7674
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
77-
Log<ValidateUnitTestsCommand>.G().LogError($"| TEST DIFFERENCES |");
78-
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
79-
Log<ValidateUnitTestsCommand>.G().LogError($"| FULL PATH : {item.test}");
75+
}
76+
}
77+
else
78+
{
79+
if (PrettyPrint)
80+
{
81+
Console.WriteLine($"❌ [FAIL] ({currentCase} of {totalCases}) {item.test}");
82+
}
83+
else
84+
{
85+
if (item.failureStage == "RESULT")
86+
{
87+
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
88+
Log<ValidateUnitTestsCommand>.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}");
89+
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
90+
Log<ValidateUnitTestsCommand>.G().LogError($"| STATUS : FAILED ");
91+
Log<ValidateUnitTestsCommand>.G().LogError($"| FAILURE TYPE : RESULT");
92+
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
93+
Log<ValidateUnitTestsCommand>.G().LogError($"| TEST DIFFERENCES |");
94+
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
95+
Log<ValidateUnitTestsCommand>.G().LogError($"| FULL PATH : {item.test}");
8096

8197

82-
foreach(var diff in item.diff)
83-
{
84-
Log<ValidateUnitTestsCommand>.G().LogError($"| {diff}");
85-
}
86-
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
98+
foreach (var diff in item.diff)
99+
{
100+
Log<ValidateUnitTestsCommand>.G().LogError($"| {diff}");
101+
}
102+
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
87103

88-
Log<ValidateUnitTestsCommand>.G().LogError($"\n\n\n\n");
104+
Log<ValidateUnitTestsCommand>.G().LogError($"\n\n\n\n");
89105

90-
}
91-
else
92-
{
93-
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
94-
Log<ValidateUnitTestsCommand>.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}");
95-
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
96-
Log<ValidateUnitTestsCommand>.G().LogError($"| STATUS : FAILED ");
97-
Log<ValidateUnitTestsCommand>.G().LogError($"| FAILURE TYPE : {item.failureStage}");
98-
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
99-
Log<ValidateUnitTestsCommand>.G().LogError($"| FAILURE DESCRIPTION |");
100-
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
101-
Log<ValidateUnitTestsCommand>.G().LogError($"| FULL PATH : {item.test}");
102-
Log<ValidateUnitTestsCommand>.G().LogError($"| {item.failureDescription}");
106+
}
107+
else
108+
{
109+
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
110+
Log<ValidateUnitTestsCommand>.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}");
111+
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
112+
Log<ValidateUnitTestsCommand>.G().LogError($"| STATUS : FAILED ");
113+
Log<ValidateUnitTestsCommand>.G().LogError($"| FAILURE TYPE : {item.failureStage}");
114+
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
115+
Log<ValidateUnitTestsCommand>.G().LogError($"| FAILURE DESCRIPTION |");
116+
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
117+
Log<ValidateUnitTestsCommand>.G().LogError($"| FULL PATH : {item.test}");
118+
Log<ValidateUnitTestsCommand>.G().LogError($"| {item.failureDescription}");
103119

104120

105-
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
121+
Log<ValidateUnitTestsCommand>.G().LogError($"+----------------------------------------------+");
106122

107-
Log<ValidateUnitTestsCommand>.G().LogError($"\n\n\n\n");
123+
Log<ValidateUnitTestsCommand>.G().LogError($"\n\n\n\n");
108124

125+
}
109126
}
110127
}
111-
Log<ValidateUnitTestsCommand>.G().LogError($"--------------------END OF RESULTS-------------------------");
128+
}
112129

130+
if (unitTestResults.Select(x => x.pass == false).Count() > 0)
131+
{
113132
DieWithError("One or more failures during run unit tests.");
114133
}
115-
116-
}
134+
}
117135
}
118136
}

src/CodeQLToolkit.Features.Test/Commands/TestCommandFeature.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ public void Register(Command parentCommand)
6767
var validateUnitTestsCommand = new Command("validate-unit-tests", "Validates a unit test run in a fashion suitable for use in CI/CD systems.");
6868

6969
var resultsDirectoryOption = new Option<string>("--results-directory", "Where to find the intermediate execution output files.") { IsRequired = true };
70+
var prettyPrintOption = new Option<bool>("--pretty-print", () => false, "Pretty print test output in a compact format.") { IsRequired = true };
7071

7172
validateUnitTestsCommand.Add(resultsDirectoryOption);
73+
validateUnitTestsCommand.Add(prettyPrintOption);
7274

7375
runCommand.Add(getMatrixTestCommand);
7476
runCommand.Add(unitTestsCommand);
7577
runCommand.Add(validateUnitTestsCommand);
76-
78+
7779
getMatrixTestCommand.SetHandler((basePath, automationType, osVersions) => {
7880

7981
Log<TestCommandFeature>.G().LogInformation("Executing get-matrix command...");
@@ -136,17 +138,18 @@ public void Register(Command parentCommand)
136138
);
137139

138140

139-
validateUnitTestsCommand.SetHandler((resultsDirectory) =>
141+
validateUnitTestsCommand.SetHandler((resultsDirectory, prettyPrint) =>
140142
{
141143
Log<TestCommandFeature>.G().LogInformation("Executing validate-unit-tests command...");
142144

143145
new ValidateUnitTestsCommand()
144146
{
145-
ResultsDirectory = resultsDirectory
147+
ResultsDirectory = resultsDirectory,
148+
PrettyPrint = prettyPrint
146149
}.Run();
147150

148151

149-
}, resultsDirectoryOption);
152+
}, resultsDirectoryOption, prettyPrintOption);
150153
}
151154

152155
public int Run()

src/CodeQLToolkit.Features.Test/Templates/Test/Actions/run-unit-tests.liquid

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,6 @@ jobs:
124124
- name: Validate test results
125125
run: |
126126
qlt test run validate-unit-tests --results-directory .
127+
qlt test run validate-unit-tests --pretty-print --results-directory . >> $GITHUB_STEP_SUMMARY
128+
127129
{% endraw %}

0 commit comments

Comments
 (0)