Skip to content

Commit

Permalink
Added t2083 - error messages for missing newlines.
Browse files Browse the repository at this point in the history
  • Loading branch information
gittup committed Jul 2, 2011
1 parent 25afeba commit dc31323
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/tup/parser.c
Expand Up @@ -295,8 +295,10 @@ static int parse_tupfile(struct tupfile *tf, struct buf *b, tupid_t curdir,

line = p;
newline = strchr(p, '\n');
if(!newline)
if(!newline) {
fprintf(stderr, "tup error: Missing newline character.\n");
goto syntax_error;
}
lno++;
while(newline[-1] == '\\' || (newline[-2] == '\\' && newline[-1] == '\r')) {
if (newline[-1] == '\r') {
Expand All @@ -305,8 +307,10 @@ static int parse_tupfile(struct tupfile *tf, struct buf *b, tupid_t curdir,
newline[-1] = ' ';
newline[0] = ' ';
newline = strchr(p, '\n');
if(!newline)
if(!newline) {
fprintf(stderr, "tup error: Missing newline character.\n");
goto syntax_error;
}
lno++;
}

Expand Down
41 changes: 41 additions & 0 deletions test/t2083-missing-newline.sh
@@ -0,0 +1,41 @@
#! /bin/sh -e

# Tup should parse correctly if the last newline is missing.

. ./tup.sh

cat > ok.c << HERE
#include <stdio.h>
int main(void)
{
printf(": foreach *.c |> gcc -c %%f -o %%o |> %%B.o");
return 0;
}
HERE
gcc ok.c -o ok
./ok > Tupfile

tup touch Tupfile ok.c ok
parse_fail_msg "Missing newline character"

cat > ok.c << HERE
#include <stdio.h>
int main(void)
{
/* The six backslashes here becomes 3 in the C program, 2 of which
* become a backslash in the Tupfile, and 1 of which is used with
* the newline.
*/
printf(": foreach *.c |> \\\\\\ngcc -c %%f -o %%o |> %%B.o");
return 0;
}
HERE
gcc ok.c -o ok
./ok > Tupfile

tup touch Tupfile
parse_fail_msg "Missing newline character"

eotup

0 comments on commit dc31323

Please sign in to comment.