Skip to content

Fix unclear test case failure messages with detailed expected vs actual output comparison #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ This extension contributes the following settings:
- for testing C++ you may need to parse the variables from input files manually depending on the data type inside the run_test_case function (please refer to this page for better understanding - https://stackoverflow.com/questions/9551014/reading-parsing-text-file-input-c)
- Limited support for languages(only python and cpp)
- All test are not checked in one go you need to check for each test case individually
- a clear falied messege might not show if your test case fails
## Release Notes

### 1.0.0
Expand Down Expand Up @@ -108,6 +107,7 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
## Changes Made

- **Error Handling**: Improved error handling in `extension.ts` and `executeCode.ts` to capture actual output even when test cases fail.
- **Clear Failure Messages**: Enhanced test case failure messages to show detailed expected vs actual output comparison for better debugging.
- **Output Normalization**: Added normalization for output comparison.
- **Logging**: Enhanced logging for better debugging.
- **Solution File Management**: Automatically generate and manage solution files.
Expand Down
23 changes: 16 additions & 7 deletions dist/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -281649,10 +281649,11 @@ function compareOutputs(expectedOutputPath, actualOutput, testCaseIndex, resolve
console.log(`\u2705 Test case ${testCaseIndex} passed!`);
resolve6(actualOutput.trim());
} else {
console.error(`\u274C Test case ${testCaseIndex} failed.`);
console.error(`Expected Output: "${expectedOutput}"`);
console.error(`Actual Output: "${actualOutput.trim()}"`);
reject(`Test case ${testCaseIndex} failed.`);
const detailedError = `\u274C Test case ${testCaseIndex} failed.
Expected Output: "${expectedOutput}"
Actual Output: "${actualOutput.trim()}"`;
console.error(detailedError);
reject(detailedError);
}
}
async function main() {
Expand Down Expand Up @@ -281697,6 +281698,10 @@ Actual Output: ${result ? result.trim() : "N/A"}`, { modal: true });
}
} catch (error) {
console.error(error);
if (typeof vscode !== "undefined" && vscode.window) {
const errorMessage = error instanceof Error ? error.message : String(error);
vscode.window.showErrorMessage(`Test Case ${testCaseIndex} Error: ${errorMessage}`);
}
}
}
}
Expand Down Expand Up @@ -297975,10 +297980,14 @@ Actual Output: ${normalizedResult}` : resultMessage);
${results.join("\n\n")}`, { modal: true });
} catch (innerError) {
const errorMessage = innerError instanceof Error ? innerError.message : String(innerError);
const actualOutput = "N/A";
results.push(`\u274C\u{1F62D} Test Case ${testCaseNumber}: Failed! \u{1F62D}
if (errorMessage.includes("Expected Output:") && errorMessage.includes("Actual Output:")) {
results.push(`\u274C\u{1F62D} Test Case ${testCaseNumber}: Failed! \u{1F62D}
${errorMessage}`);
} else {
results.push(`\u274C\u{1F62D} Test Case ${testCaseNumber}: Failed! \u{1F62D}
Error: ${errorMessage}
Actual Output: ${actualOutput}`);
Actual Output: N/A`);
}
console.log(results.join("\n\n"));
vscode4.window.showInformationMessage(`Test Case Summary:

Expand Down
2 changes: 1 addition & 1 deletion dist/extension.js.map

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/executeCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,9 @@ function compareOutputs(
console.log(`βœ… Test case ${testCaseIndex} passed!`);
resolve(actualOutput.trim());
} else {
console.error(`❌ Test case ${testCaseIndex} failed.`);
console.error(`Expected Output: "${expectedOutput}"`);
console.error(`Actual Output: "${actualOutput.trim()}"`);
reject(`Test case ${testCaseIndex} failed.`);
const detailedError = `❌ Test case ${testCaseIndex} failed.\nExpected Output: "${expectedOutput}"\nActual Output: "${actualOutput.trim()}"`;
console.error(detailedError);
reject(detailedError);
}
}

Expand Down Expand Up @@ -180,6 +179,11 @@ async function main() {
}
} catch (error) {
console.error(error);
// Show user-friendly error in VS Code if available
if (typeof vscode !== 'undefined' && vscode.window) {
const errorMessage = error instanceof Error ? error.message : String(error);
vscode.window.showErrorMessage(`Test Case ${testCaseIndex} Error: ${errorMessage}`);
}
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,15 @@ int main() {
vscode.window.showInformationMessage(`Test Case Summary:\n\n${results.join('\n\n')}`, { modal: true });
} catch (innerError) {
const errorMessage = innerError instanceof Error ? innerError.message : String(innerError);
const actualOutput = 'N/A';
results.push(`❌😭 Test Case ${testCaseNumber}: Failed! 😭 \nError: ${errorMessage}\nActual Output: ${actualOutput}`);

// Check if the error message contains detailed comparison info
if (errorMessage.includes('Expected Output:') && errorMessage.includes('Actual Output:')) {
// Use the detailed error message as-is since it already contains expected vs actual
results.push(`❌😭 Test Case ${testCaseNumber}: Failed! 😭\n${errorMessage}`);
} else {
// Fallback for other types of errors (compilation, runtime, etc.)
results.push(`❌😭 Test Case ${testCaseNumber}: Failed! 😭\nError: ${errorMessage}\nActual Output: N/A`);
}
console.log(results.join('\n\n'));
vscode.window.showInformationMessage(`Test Case Summary:\n\n${results.join('\n\n')}`, { modal: true });
}
Expand Down