Skip to content

Fix Windows test exit codes not being checked - #1798

Closed
wolfv with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-1792
Closed

Fix Windows test exit codes not being checked#1798
wolfv with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-1792

Conversation

Copilot AI commented Jul 25, 2025

Copy link
Copy Markdown
Contributor

This PR fixes an issue where test scripts with multiple commands on Windows would ignore failures in earlier commands, only checking the exit code of the final command. This behavior was inconsistent with conda-build and could lead to packages passing tests when they should fail.

Problem

When running test scripts on Windows with multiple commands like:

test:
  commands:
    - python --version
    - python -c "import nonexistent_module"  # This fails
    - echo Test completed successfully       # This still runs!

The test phase would succeed even if the import command failed, because only the last command's exit code was checked.

Solution

Added Windows-specific exit code checking to the CmdExeInterpreter that inserts IF %ERRORLEVEL% NEQ 0 EXIT 1 after each command (except the last), mimicking conda-build's proven approach:

python --version
IF %ERRORLEVEL% NEQ 0 EXIT 1
python -c "import nonexistent_module"
IF %ERRORLEVEL% NEQ 0 EXIT 1
echo Test completed successfully

Now if any command fails, the script immediately exits with error code 1.

Changes

  • Core Fix: Added CmdExeInterpreter::add_exit_code_checks() method that intelligently processes Windows batch scripts
  • Applied to both: CmdExeInterpreter::run() and Output::create_build_script() methods
  • Smart filtering: Skips adding checks for comments (@rem, ::, etc.), labels (:label), and empty lines
  • Platform-specific: Only affects Windows cmd.exe interpreter, no impact on bash/other interpreters
  • Comprehensive testing: Added 11 unit tests covering various scenarios and edge cases

Verification

The fix has been thoroughly tested with scenarios including:

  • Multiple commands with potential failures
  • Scripts with comments and labels
  • Empty lines and whitespace handling
  • IF statements and ECHO commands
  • Single command scripts (no regression)

All existing tests continue to pass, ensuring no breaking changes.

Fixes #1792.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits July 25, 2025 08:06
Co-authored-by: wolfv <885054+wolfv@users.noreply.github.com>
Co-authored-by: wolfv <885054+wolfv@users.noreply.github.com>
Copilot AI changed the title [WIP] Test exit codes aren't checked on Windows Fix Windows test exit codes not being checked Jul 25, 2025
Copilot AI requested a review from wolfv July 25, 2025 08:11
Copilot finished work on behalf of wolfv July 25, 2025 08:11
Comment thread src/script/interpreter/cmd_exe.rs Outdated
// - empty lines and whitespace-only lines
// - comment lines (@rem, rem, ::)
// - label lines (starting with :)
let should_add_check = i < lines.len() - 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about line continuation with ^?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line continuation with ^ is already handled! The code detects lines ending with ^ (line 67), tracks continuation state (lines 82-88), and only adds exit code checks after the complete command finishes (lines 95-98). See tests test_add_exit_code_checks_with_line_continuation() and related tests at lines 276-310 for verification.

Co-authored-by: wolfv <885054+wolfv@users.noreply.github.com>
Copilot AI requested a review from wolfv July 25, 2025 08:53
Copilot finished work on behalf of wolfv July 25, 2025 08:53
Copilot finished work on behalf of wolfv July 25, 2025 09:02
@wolfv wolfv closed this Aug 20, 2025
@wolfv
wolfv deleted the copilot/fix-1792 branch October 14, 2025 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test exit codes aren't checked on Windows

2 participants