Skip to content
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

Add dshell tests for Issue 22816 and Issue 22817 #13713

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions test/dshell/extra-files/issue22816.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module issue22816;
23 changes: 23 additions & 0 deletions test/dshell/issue22816.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import dshell;

int main()
{
auto stderr_file = shellExpand("$OUTPUT_BASE/issue22816.err");
auto stderr = File(stderr_file, "w");

string cmd = "$DMD -m$MODEL -c $EXTRA_FILES/issue22816.c";
string expected = shellExpand("^Error: cannot find input file `$EXTRA_FILES" ~ SEP ~ "issue22816.c`");

version (Windows)
expected = expected.replace(`\`, `\\`); // Replace \ => \\ for regex

const exitCode = tryRun(cmd, std.stdio.stdout, stderr);
assert(exitCode == 1, "DMD should've failed!");

Vars.set("stderr", stderr_file);
Vars.stderr
.grep(expected)
.enforceMatches("Expected 'Error: cannot find input file'");

return 0;
}
23 changes: 23 additions & 0 deletions test/dshell/issue22817.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import dshell;

int main()
{
auto stderr_file = shellExpand("$OUTPUT_BASE/issue22817.err");
auto stderr = File(stderr_file, "w");

string cmd = "$DMD -m$MODEL -c $EXTRA_FILES/issue22817.d";
string expected = shellExpand("^Error: cannot find input file `$EXTRA_FILES" ~ SEP ~ "issue22817.d`");

version (Windows)
expected = expected.replace(`\`, `\\`); // Replace \ => \\ for regex

const exitCode = tryRun(cmd, std.stdio.stdout, stderr);
assert(exitCode == 1, "DMD should've failed!");

Vars.set("stderr", stderr_file);
Vars.stderr
.grep(expected)
.enforceMatches("Expected 'Error: cannot find input file'");

return 0;
}
8 changes: 8 additions & 0 deletions test/tools/dshell_prebuilt/dshell_prebuilt.d
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ auto tryRun(scope const(char[])[] args, File stdout = std.stdio.stdout,
auto proc = spawnProcess(args, stdin, stdout, stderr, env);
return wait(proc);
}

/// ditto
auto tryRun(string cmd, File stdout = std.stdio.stdout,
File stderr = std.stdio.stderr, string[string] env = null)
{
return tryRun(parseCommand(cmd), stdout, stderr, env);
}

/// ditto
void run(scope const(char[])[] args, File stdout = std.stdio.stdout,
File stderr = std.stdio.stderr, string[string] env = null)
Expand Down