492
Description:
493
494
This routine checks whether translating a path with wslpath matches the
495
- specified result.
495
+ specified result. Pass NULL as ExpectedPath to assert that wslpath fails
496
+ to translate the path.
497
498
Arguments:
499
500
Path - Supplies the path to translate.
501
501
- ExpectedPath - Supplies the expected translated path.
502
+ ExpectedPath - Supplies the expected translated path, or NULL to assert
503
+ that wslpath fails.
504
505
WinPath - Supplies a value that indicates whether the specified path is a
506
Windows path. When true, the expected path must be a Linux path and
517
int Result;
518
char TranslatedPath[4096];
519
518
- LxtCheckResult(LxtExecuteWslPath(Path, WinPath, TranslatedPath, sizeof(TranslatedPath)));
519
- LxtCheckStringEqual(ExpectedPath, TranslatedPath);
520
- LxtLogInfo("%s => %s", Path, TranslatedPath);
520
+ LxtCheckResult(LxtExecuteWslPath(Path, WinPath, TranslatedPath, sizeof(TranslatedPath), ExpectedPath == NULL ? 1 : 0));
521
+ if (ExpectedPath == NULL)
522
+ {
523
+ LxtLogInfo("%s => (failed as expected)", Path);
524
+ }
525
+ else
526
+ {
527
+ LxtCheckStringEqual(ExpectedPath, TranslatedPath);
528
+ LxtLogInfo("%s => %s", Path, TranslatedPath);
529
+ }
530
531
ErrorExit:
532
return Result;
533
}
534
526
-int LxtExecuteAndReadOutput(char** Argv, char* OutputBuffer, size_t OutputBufferSize)
535
+int LxtExecuteAndReadOutput(char** Argv, char* OutputBuffer, size_t OutputBufferSize, int ExpectedExitCode)
536
537
/*++
538
552
553
OutputBufferSize - Supplies the size of the output buffer.
554
555
+ ExpectedExitCode - Supplies the expected exit code of the child process.
556
+
557
Return Value:
558
559
Returns 0 on success, -1 on failure.
596
OutputBuffer[BytesRead] = '\0';
597
598
//
588
- // Make sure the executable exited successfully.
599
+ // Make sure the executable exited with the expected status.
600
//
601
591
- LxtCheckResult(LxtWaitPidPoll(ChildPid, 0));
602
+ LxtCheckResult(LxtWaitPidPoll(ChildPid, ExpectedExitCode << 8));
603
604
ErrorExit:
605
LxtClosePipe(&Pipe);
607
return Result;
608
}
609
599
-int LxtExecuteWslPath(char* Path, bool WinPath, char* OutputBuffer, size_t OutputBufferSize)
610
+int LxtExecuteWslPath(char* Path, bool WinPath, char* OutputBuffer, size_t OutputBufferSize, int ExpectedExitCode)
611
612
/*++
613
629
630
OutputBufferSize - Supplies the size of the output buffer.
631
632
+ ExpectedExitCode - Supplies the expected exit code of wslpath. Pass 1 when
633
+ the translation is expected to fail.
634
+
635
Return Value:
636
637
Returns 0 on success, -1 on failure.
662
// Execute wslpath.
663
//
664
651
- LxtCheckResult(LxtExecuteAndReadOutput(Argv, OutputBuffer, OutputBufferSize));
665
+ LxtCheckResult(LxtExecuteAndReadOutput(Argv, OutputBuffer, OutputBufferSize, ExpectedExitCode));
666
667
//
668
// Wslpath outputs a new line at the end. Strip it to make things easier on