Skip to content

Use an absolute path in test_process_output_fail_to_start #11784

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

Merged
merged 1 commit into from
Jan 31, 2014
Merged
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 src/libstd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ mod tests {
trapped_io_error = true;
assert_eq!(e.kind, FileNotFound);
}).inside(|| -> Option<run::ProcessOutput> {
run::process_output("no-binary-by-this-name-should-exist", [])
run::process_output("/no-binary-by-this-name-should-exist", [])
Copy link
Member

Choose a reason for hiding this comment

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

Aren't paths in a different format on windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but I don't think that matters in this case. Recall that we don't actually want to run this thing, only to confirm it doesn't exist. I don't have easy access to a Windows machine with Rust, but I do have access to a Windows machine.

The following code snippet gives CreateProcess an absolute path (with a forward slash), and CreateProcess is correctly returning ERROR_FILE_NOT_FOUND. So I believe this will work just fine for this rust test

#include <Windows.h>
#include <stdio.h>

int main() {

    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );

    if( !CreateProcess( NULL,           // No module name (use command line)
                "/does_not_exist",      // Command line
                NULL,                   // Process handle not inheritable
                NULL,                   // Thread handle not inheritable
                FALSE,                  // Set handle inheritance to FALSE
                0,                      // No creation flags
                NULL,                   // Use parent's environment block
                NULL,                   // Use parent's starting directory
                &si,                    // Pointer to STARTUPINFO structure
                &pi )                   // Pointer to PROCESS_INFORMATION structure
      )
    {
        const DWORD err = GetLastError();
        if (err == ERROR_FILE_NOT_FOUND) {
            printf("FileNotFound\n");
        } else {
            printf( "CreateProcess failed (%d).\n", err );
        }
    }
    return;

}
d:\temp\> test.exe
FileNotFound

Also note that if I give a path to something that does exist, but also using unix-style forward slashes, CreateProcess will run the thing. I am not sure, however, where this behavior is documented.

});
assert!(trapped_io_error);
assert!(opt_outp.is_none());
Expand Down