Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ddmd/mars.d
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,10 @@ private bool parseCommandLine(const ref Strings arguments, const size_t argc, re
error("-run must be followed by a source file, not '%s'", arguments[i + 1]);
break;
}
files.push(arguments[i + 1]);
if (strcmp(arguments[i + 1], "-") == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is too simplistic, it won't work if there's a command after -run, e.g. dmd -run -m64 -

Copy link
Member Author

@quickfur quickfur Dec 15, 2017

Choose a reason for hiding this comment

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

Actually, -run takes an argument, so your example is invalid. (I'm not sure why whoever originally implemented -run did it this way, but that's how it currently works, and this PR is just following in its steps.)(And yes, the first time I realized -run took an argument I was surprised too. :-P)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh sorry. I just looked over this again from my phone and imagined that doing dmd -run -version=Foo myfile.d is legimate, so yeah that seems like bad design too me too, but that's an opportunity for another PR ;-)

files.push("__stdin.d");
else
files.push(arguments[i + 1]);
params.runargs.setDim(length - 1);
for (size_t j = 0; j < length - 1; ++j)
{
Expand Down
8 changes: 8 additions & 0 deletions test/runnable/test18076.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

dir=${RESULTS_DIR}${SEP}runnable
output_file=${dir}/test18076.sh.out

echo 'import std.stdio; void main() { writeln("Success"); }' | \
$DMD -m${MODEL} -run - > ${output_file} || exit 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you have to check that it actually prints "Success" here?

[[ $(echo "Success") == "Success" ]] || exit 1

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, fixed.

grep -q '^Success$' ${output_file} || exit 1
Copy link
Contributor

@wilzbach wilzbach Dec 14, 2017

Choose a reason for hiding this comment

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

FWIW the || exit is superfluous here.
A bash script will yield the last return value as exit code if not explicitly exited
Convince yourself:

sh -c "grep -q 'foo' afile.d" ; echo $? 

Copy link
Member Author

Choose a reason for hiding this comment

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

True. I'm wary of relying on these implicit behaviours, though. Stating || exit 1 makes it more obvious what's happening. Not that it makes a difference, I just prefer to have things up-front than implicit. Implicit things tend to be fragile and unintentionally break later.

Copy link
Contributor

@wilzbach wilzbach Dec 15, 2017

Choose a reason for hiding this comment

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

That's why one usually does a set -e at the beginning 😉
https://unix.stackexchange.com/questions/15998/what-does-the-e-do-in-a-bash-shebang