diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index c4e2ea88a..86f625123 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -769,17 +769,24 @@ function setup() settings.set("rules.economy.food", "4") end -local function assert_in_report(f, pattern) +local function find_in_report(f, pattern, extension) + extension = extension or "nr" write_report(f) - local filename = config.basepath .. "/reports/" .. get_turn() .. "-" .. itoa36(f.id) .. ".nr" + local filename = config.basepath .. "/reports/" .. get_turn() .. "-" .. itoa36(f.id) .. "." .. extension local report = io.open(filename, 'rt'); t = report:read("*all") - if string.find(t, pattern) == nil then - print(t, pattern) - end - assert_not_equal(nil, string.find(t, pattern)) report:close() + + local start, _ = string.find(t, pattern) -- posix.unlink(filename) + return start~=nil +end + +local function assert_in_report(f, pattern, extension) + assert_not_equal(nil, find_in_report(f, pattern, extension)) +end +local function assert_not_in_report(f, pattern, extension) + assert_equal(nil, find_in_report(f, pattern, extension)) end function test_coordinates_no_plane() @@ -816,3 +823,46 @@ function test_coordinates_noname_plane() init_reports() assert_in_report(f, r.name .. " %(0,0%), Berg") end + +module( "parser", package.seeall, lunit.testcase ) + +function setup() + free_game() +end + +function test_parser() + local r = region.create(0, 0, "mountain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + local filename = "1814.txt" + + local file = io.open(filename, "w+") + file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n') + file:write('EINHEIT ' .. itoa36(u.id) .. "\n") + file:write("LERNEN Hiebwaffen\n") + file:close() + + read_orders(filename) + process_orders() + assert_not_equal(0, u:get_skill("melee")) +end + +function test_bug_1814() + -- see http://bugs.eressea.de/view.php?id=1814 + local r = region.create(0, 0, "mountain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + local filename = "1814.txt" + + local file = io.open(filename, "w+") + file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n') + file:write('EINHEIT ' .. itoa36(u.id) .. "\n") + file:write("; parse error follows: '\n") + file:write("; ARBEITE\n") + file:close() + + read_orders(filename) + process_orders() + init_reports() + assert_false(find_in_report(f, "Der Befehl wurde nicht erkannt", "cr")) +end diff --git a/src/kernel/save.c b/src/kernel/save.c index 67c268d45..5d43bf6c5 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -443,7 +443,7 @@ readorders(const char *filename) } fclose(F); - puts("\n"); + if (verbosity>=1) puts("\n"); log_printf(" %d Befehlsdateien gelesen\n", nfactions); return 0; } diff --git a/src/util/filereader.c b/src/util/filereader.c index 26c745851..a87427a54 100644 --- a/src/util/filereader.c +++ b/src/util/filereader.c @@ -57,6 +57,7 @@ getbuf_latin1(FILE * F) while (*bp && isxspace(*(unsigned char*)bp)) ++bp; /* eatwhite */ comment = (boolean)(comment && cont); + quote = (boolean)(quote && cont); if (tail[1]==0) { /* we read he maximum number of bytes! */ @@ -189,9 +190,10 @@ getbuf_utf8(FILE * F) bp += white; comment = (boolean)(comment && cont); + quote = (boolean)(quote && cont); if (tail[1]==0) { - /* we read he maximum number of bytes! */ + /* we read the maximum number of bytes! */ if (tail[0]!='\n') { /* it wasn't enough space to finish the line, eat the rest */ for (;;) {