Skip to content

Commit

Permalink
Merge pull request #113 from CyberShadow/rdmd-20140202
Browse files Browse the repository at this point in the history
rdmd: Fix `--dry-run`, add test for issue 11983
  • Loading branch information
MartinNowak committed Feb 2, 2014
2 parents 062e91a + 524a76e commit ef71a52
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
29 changes: 16 additions & 13 deletions rdmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,26 @@ private int rebuild(string root, string fullExe,
}

// Run a program optionally writing the command line first
// If "replace" is true and the OS supports it, replace the current process.

private int run(string[] args, string output = null)
private int run(string[] args, string output = null, bool replace = false)
{
import std.conv;
yap(args.text);
yap(replace ? "exec " : "spawn ", args.text);
if (dryRun) return 0;

if (replace && !output)
{
version (Windows)
{ /* Windows doesn't have exec, fall back to spawnProcess+wait */ }
else
{
import std.c.process;
auto argv = args.map!toStringz.chain(null.only).array;
return execv(argv[0], argv.ptr);
}
}

File outputFile;
if (output)
outputFile = File(output, "wb");
Expand All @@ -496,19 +509,9 @@ private int run(string[] args, string output = null)
return process.wait();
}

// Replace the current process with another, on supported systems.
// Otherwise, run the command, wait for completion, and return its exit code.

private int exec(string[] args)
{
version (Windows)
return run(args);
else
{
import std.c.process;
auto argv = args.map!toStringz.chain(null.only).array;
return execv(argv[0], argv.ptr);
}
return run(args, null, true);
}

// Given module rootModule, returns a mapping of all dependees .d
Expand Down
10 changes: 10 additions & 0 deletions rdmd_test.d
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ void runTests()
res = execute([rdmdApp, compilerSwitch, "-I" ~ packRoot, "--makedepend", depMod]);
assert(res.output.canFind("depMod_.d : ")); // simplistic check

/* Test signal propagation through exit codes */

version (Posix)
{
import core.sys.posix.signal;
string crashSrc = tempDir().buildPath("crash_src_.d");
std.file.write(crashSrc, `void main() { int *p; *p = 0; }`);
res = execute([rdmdApp, compilerSwitch, crashSrc]);
assert(res.status == -SIGSEGV, format("%s", res));
}
}

void runConcurrencyTest()
Expand Down

0 comments on commit ef71a52

Please sign in to comment.