diff options
Diffstat (limited to 'tests/common.lua')
-rw-r--r-- | tests/common.lua | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/tests/common.lua b/tests/common.lua index e08b6c2..0b231bd 100644 --- a/tests/common.lua +++ b/tests/common.lua | |||
@@ -96,12 +96,21 @@ function dump_value(value) | |||
96 | end | 96 | end |
97 | 97 | ||
98 | function file_load(filename) | 98 | function file_load(filename) |
99 | local file, err = io.open(filename) | 99 | local file |
100 | if file == nil then | 100 | if filename == nil then |
101 | error("Unable to read " .. filename) | 101 | file = io.stdin |
102 | else | ||
103 | local err | ||
104 | file, err = io.open(filename) | ||
105 | if file == nil then | ||
106 | error(string.format("Unable to read '%s': %s", filename, err)) | ||
107 | end | ||
102 | end | 108 | end |
103 | local data = file:read("*a") | 109 | local data = file:read("*a") |
104 | file:close() | 110 | |
111 | if filename ~= nil then | ||
112 | file:close() | ||
113 | end | ||
105 | 114 | ||
106 | if data == nil then | 115 | if data == nil then |
107 | error("Failed to read " .. filename) | 116 | error("Failed to read " .. filename) |
@@ -111,12 +120,20 @@ function file_load(filename) | |||
111 | end | 120 | end |
112 | 121 | ||
113 | function file_save(filename, data) | 122 | function file_save(filename, data) |
114 | local file, err = io.open(filename, "w") | 123 | local file |
115 | if file == nil then | 124 | if filename == nil then |
116 | error("Unable to write " .. filename) | 125 | file = io.stdout |
126 | else | ||
127 | local err | ||
128 | file, err = io.open(filename, "w") | ||
129 | if file == nil then | ||
130 | error(string.format("Unable to write '%s': %s", filename, err)) | ||
131 | end | ||
117 | end | 132 | end |
118 | file:write(data) | 133 | file:write(data) |
119 | file:close() | 134 | if filename ~= nil then |
135 | file:close() | ||
136 | end | ||
120 | end | 137 | end |
121 | 138 | ||
122 | function compare_values(val1, val2) | 139 | function compare_values(val1, val2) |