Merge pull request #123 from kljohann/bug.788

change handling of standard input
This commit is contained in:
John Wiegley 2013-01-17 12:36:17 -08:00
commit 83bd3234d3
6 changed files with 36 additions and 5 deletions

View file

@ -84,7 +84,7 @@ string source_context(const path& file,
const string& prefix)
{
const std::streamoff len = end_pos - pos;
if (! len || file == path("/dev/stdin"))
if (! len || file.empty())
return _("<no source context>");
assert(len > 0);

View file

@ -582,8 +582,8 @@ string item_context(const item_t& item, const string& desc)
std::ostringstream out;
if (item.pos->pathname == path("/dev/stdin")) {
out << desc << _(" from standard input:");
if (item.pos->pathname.empty()) {
out << desc << _(" from streamed input:");
return out.str();
}

View file

@ -143,7 +143,7 @@ std::size_t session_t::read_data(const string& master_account)
}
foreach (const path& pathname, HANDLER(file_).data_files) {
if (pathname == "-") {
if (pathname == "-" || pathname == "/dev/stdin") {
// To avoid problems with stdin and pipes, etc., we read the entire
// file in beforehand into a memory buffer, and then parcel it out
// from there.

View file

@ -100,7 +100,7 @@ class RegressFile(object):
use_stdin = False
if test['command'].find("-f ") != -1:
test['command'] = '$ledger ' + test['command']
if test['command'].find("-f - ") != -1:
if re.search("-f (-|/dev/stdin)(\s|$)", test['command']):
use_stdin = True
else:
test['command'] = (('$ledger -f "%s" ' %

View file

@ -0,0 +1,12 @@
; Check that include directives are relative for "-f /dev/stdin"
include non-existent-ledger-file-BF3C1F82
test -f - reg -> 1
__ERROR__
While parsing file "", line 2:
Error: File to include was not found: "./non-existent-ledger-file-BF3C1F82"
end test
test -f /dev/stdin reg -> 1
__ERROR__
While parsing file "", line 2:
Error: File to include was not found: "./non-existent-ledger-file-BF3C1F82"
end test

View file

@ -0,0 +1,19 @@
; Check that error reporting works for "-f -"
2012/02/30 * Test
a 1
b
test -f - reg -> 1
__ERROR__
While parsing file "", line 3:
While parsing transaction:
<no source context>
Error: Day of month is not valid for year
end test
test -f /dev/stdin reg -> 1
__ERROR__
While parsing file "", line 3:
While parsing transaction:
<no source context>
Error: Day of month is not valid for year
end test