Skip to content

Commit

Permalink
ARCH-2011 - Troubleshooting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielle-casella-adams committed Mar 12, 2024
1 parent ff79363 commit e1d9836
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 157 deletions.
260 changes: 180 additions & 80 deletions .github/workflows/build-and-review-pr.yml

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3390,17 +3390,20 @@ async function run() {
if (!areReportTypesValid(reportTypes)) return;
let output = '';
const toolPath = 'reportgeneratortool';
core.info('Detecting .NET Core SDK...');
core.info('\nDetecting .NET Core SDK...');
try {
core.startGroup('dotnet version output');
await exec.exec('dotnet', ['--version'], {
listeners: {
stdout: data => {
output += data.toString();
}
}
});
core.info(`Detected .NET Core SDK version '${output}'`);
core.endGroup();
core.info(`Detected .NET Core SDK version '${output.trim()}'`);
} catch (error) {
core.endGroup();
const shortMsg = 'dotnet not available';
core.setOutput('error-reason', shortMsg);
core.setFailed(shortMsg);
Expand All @@ -3411,13 +3414,14 @@ async function run() {
core.info(" dotnet-version: '8.x' # 5.0 or higher");
return;
}
core.info('Installing ReportGenerator global tool...');
core.info('https://www.nuget.org/packages/dotnet-reportgenerator-globaltool');
core.info('\nChecking for ReportGenerator global tool...');
if (fs.existsSync(toolPath)) {
core.info('ReportGenerator global tool already installed');
} else {
output = '';
try {
core.startGroup('Installing ReportGenerator global tool');
core.info('https://www.nuget.org/packages/dotnet-reportgenerator-globaltool');
await exec.exec(
'dotnet',
[
Expand All @@ -3438,13 +3442,15 @@ async function run() {
}
}
);
core.endGroup();
core.info('Successfully installed ReportGenerator global tool');
} catch (error) {
core.endGroup();
core.setFailed('Failed to install ReportGenerator global tool');
return;
}
}
core.info('Executing ReportGenerator');
core.info('\nExecuting ReportGenerator global tool');
try {
let args = [
`-reports:${core.getInput('reports')}`,
Expand All @@ -3457,15 +3463,18 @@ async function run() {
`-title:${core.getInput('title')}`,
`-tag:${core.getInput('tag')}`
];
core.startGroup('reportgenerator output');
await exec.exec(`${toolPath}/reportgenerator`, args, {
listeners: {
stdout: data => {
output += data.toString();
}
}
});
core.endGroup();
core.info('Successfully executed ReportGenerator');
} catch (error) {
core.endGroup();
if (output.includes('No matching files found.')) {
const shortMsg = 'No matching files found';
core.setOutput('error-reason', shortMsg);
Expand Down
20 changes: 14 additions & 6 deletions src/reportgenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ async function run() {
let output = '';
const toolPath = 'reportgeneratortool';

core.info('Detecting .NET Core SDK...');
core.info('\nDetecting .NET Core SDK...');
try {
core.startGroup('dotnet version output');
await exec.exec('dotnet', ['--version'], {
listeners: {
stdout: data => {
output += data.toString();
}
}
});
core.info(`Detected .NET Core SDK version '${output}'`);
core.endGroup();
core.info(`Detected .NET Core SDK version '${output.trim()}'`);
} catch (error) {
core.endGroup();
const shortMsg = 'dotnet not available';
core.setOutput('error-reason', shortMsg);
core.setFailed(shortMsg);
Expand All @@ -37,14 +40,15 @@ async function run() {
return;
}

core.info('Installing ReportGenerator global tool...');
core.info('https://www.nuget.org/packages/dotnet-reportgenerator-globaltool');
core.info('\nChecking for ReportGenerator global tool...');
if (fs.existsSync(toolPath)) {
core.info('ReportGenerator global tool already installed');
} else {
output = '';

try {
core.startGroup('Installing ReportGenerator global tool');
core.info('https://www.nuget.org/packages/dotnet-reportgenerator-globaltool');
await exec.exec(
'dotnet',
[
Expand All @@ -65,14 +69,16 @@ async function run() {
}
}
);
core.endGroup();
core.info('Successfully installed ReportGenerator global tool');
} catch (error) {
core.endGroup();
core.setFailed('Failed to install ReportGenerator global tool');
return;
}
}

core.info('Executing ReportGenerator');
core.info('\nExecuting ReportGenerator global tool');
try {
let args = [
`-reports:${core.getInput('reports')}`,
Expand All @@ -85,16 +91,18 @@ async function run() {
`-title:${core.getInput('title')}`,
`-tag:${core.getInput('tag')}`
];

core.startGroup('reportgenerator output');
await exec.exec(`${toolPath}/reportgenerator`, args, {
listeners: {
stdout: data => {
output += data.toString();
}
}
});
core.endGroup();
core.info('Successfully executed ReportGenerator');
} catch (error) {
core.endGroup();
if (output.includes('No matching files found.')) {
const shortMsg = 'No matching files found';
core.setOutput('error-reason', shortMsg);
Expand Down
1 change: 1 addition & 0 deletions test/assert-dir-does-not-exist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Asserting '$dir' does not exist"

if [ -d "$dir" ]; then
echo "The target directory exists when it should not."
ls -r $dir
exit 1
else
echo "The target directory does not exist, which is expected."
Expand Down
3 changes: 2 additions & 1 deletion test/assert-dir-exists.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ echo "
Asserting '$dir' exists"

if [ -d "$dir" ]; then
echo "The target directory exists, which is expected."
echo "The target directory exists, which is expected. It contains:"
ls -r $dir
else
echo "The target directory does not exist but it should."
exit 1
Expand Down
32 changes: 32 additions & 0 deletions test/assert-dir-is-empty.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

dir=''

for arg in "$@"; do
case $arg in
--dir)
dir=$2
shift # Remove argument --dir from `$@`
shift # Remove argument value from `$@`
;;
esac
done

echo "
Asserting '$dir' exists and that it is empty"

if [ -d "$dir" ]; then
echo "The target directory exists, which is expected."
else
echo "The target directory does not exist but it should."
exit 1
fi

if [ -z "$(ls -A $dir)" ]; then
echo "The target directory is empty, which is expected."
else
echo "The target directory is not empty but it should be."
echo "These items exist under the directory:"
ls -r $dir
exit 1
fi
59 changes: 0 additions & 59 deletions test/assert-file-contains-expected-content.sh

This file was deleted.

45 changes: 45 additions & 0 deletions test/assert-file-contains-substring.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

substringFile=''
fullFile=''

for arg in "$@"; do
case $arg in
--substringFile)
substringFile=$2
shift # Remove argument --substringFile from `$@`
shift # Remove argument value from `$@`
;;
--fullFile)
fullFile=$2
shift # Remove argument --fullFile from `$@`
shift # Remove argument value from `$@`
;;

esac
done

# Print out the file contents for easy manual comparison
echo "
Asserting full file contains substring:
File with full contents: '$fullFile'
File with substring: '$substringFile'"

fullFileContents=$(cat $fullFile)
echo "::group::Full file contents"
echo "'$fullFileContents'"
echo "::endgroup::"

substringContents=$(cat $substringFile)
echo "::group::Substring"
echo "'$substringContents'"
echo "::endgroup::"


# Now compare the contents
if echo "$fullFileContents" | grep -q "$substringContents"; then
echo "The file contains the substring, which is expected."
else
echo "The file does not contain the substring, which is not expected."
exit 1
fi
6 changes: 2 additions & 4 deletions test/expected-contents/class-filters.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"parser": "OpenCoverParser",
parser": "OpenCoverParser",
"assemblies": 3,
"classes": 4,
"files": 4,
Expand All @@ -20,6 +20,4 @@
{ "name": "MyProj.Core", "classes": 0, "coverage": null, "coveredlines": 0, "coverablelines": 0, "totallines": 0, "branchcoverage": null, "coveredbranches": 0, "totalbranches": 0, "classesinassembly": [
] },
{ "name": "MyProj.Tests.Shared", "classes": 0, "coverage": null, "coveredlines": 0, "coverablelines": 0, "totallines": 0, "branchcoverage": null, "coveredbranches": 0, "totalbranches": 0, "classesinassembly": [
] } ]
}
}
] } ]
2 changes: 1 addition & 1 deletion test/expected-contents/file-filters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ MyProj
MyProj.Core 90.9%
MyProj.Core.EnumExtensions 90.9%

MyProj.Tests.Shared
MyProj.Tests.Shared
2 changes: 1 addition & 1 deletion test/expected-contents/matching-reports.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
|**MyProj.Tests.Shared**|**136**|**0**|**136**|**0**|**100%**|**0**|**0**|****|
|MyProj.Tests.Shared.TestGrades|4|0|4|0|100%|0|0||
|MyProj.Tests.Shared.TestPositions|125|0|125|0|100%|0|0||
|MyProj.Tests.Shared.TestRoles|7|0|7|0|100%|0|0||
|MyProj.Tests.Shared.TestRoles|7|0|7|0|100%|0|0||

0 comments on commit e1d9836

Please sign in to comment.