Skip to content

Commit c522f90

Browse files
committed
better batch mode error msgs
1 parent 2832bad commit c522f90

File tree

4 files changed

+89
-68
lines changed

4 files changed

+89
-68
lines changed

TODO

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
- try:
2+
3+
main = "...." ++ error "hello";
4+
5+
does not print any "..."
6+
7+
print of main should be lazyier
8+
9+
main_print_main() does strict reduction of main
10+
11+
graph_value() is also strict
12+
113
- try < > in the image titlebar
214

315
seems to get stuck on eg. mp3 files

src/main-batch.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,20 @@ main_log_is_empty(void)
9595
static void
9696
main_error_exit(const char *fmt, ...)
9797
{
98-
va_list args;
98+
if (fmt) {
99+
va_list args;
99100

100-
va_start(args, fmt);
101-
(void) vfprintf(stderr, fmt, args);
102-
va_end(args);
103-
fprintf(stderr, "\n");
101+
va_start(args, fmt);
102+
(void) vfprintf(stderr, fmt, args);
103+
va_end(args);
104+
fprintf(stderr, "\n");
105+
}
104106

105107
if (!g_str_equal(error_get_top(), "")) {
106-
fprintf(stderr, "%s\n", error_get_top());
108+
fprintf(stderr, "%s", error_get_top());
107109
if (!g_str_equal(error_get_sub(), ""))
108-
fprintf(stderr, "%s\n", error_get_sub());
110+
fprintf(stderr, ", %s", error_get_sub());
111+
fprintf(stderr, "\n");
109112
}
110113

111114
if (main_option_verbose) {
@@ -444,7 +447,7 @@ main(int argc, char **argv)
444447
argc > 1) {
445448
// load argv[1] as a set of defs
446449
if (!toolkit_new_from_file(main_toolkitgroup, argv[1]))
447-
main_log_add("%s\n", error_get_sub());
450+
main_error_exit(NULL);
448451

449452
// the rest of argc/argv become nip4 defs
450453
main_build_argv(argc - 1, argv + 1);

src/util.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ error_get_top(void)
186186
const char *
187187
error_get_sub(void)
188188
{
189+
// remove any annoying trailing \n
190+
while (vips_buf_removec(&error_sub_buf, '\n'))
191+
;
192+
189193
return vips_buf_all(&error_sub_buf);
190194
}
191195

test/workspaces/test_snip.def

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,87 +2,89 @@
22
// we can't use uchar as a number format directly since it'll become 'a' or
33
// whatever and arithmetic ops will start failing
44
fmts = [
5-
["uchar", cast_unsigned_char, cast_unsigned_int @ cast_unsigned_char],
6-
["char", cast_signed_char, cast_signed_int @ cast_signed_char],
7-
["ushort", cast_unsigned_short, cast_unsigned_short],
8-
["short", cast_signed_short, cast_signed_short],
9-
["uint", cast_unsigned_int, cast_unsigned_int],
10-
["int", cast_signed_int, cast_signed_int],
11-
["float", cast_float, cast_float],
12-
["double", cast_double, cast_double],
13-
["complex", cast_complex, cast_complex],
14-
["dcomplex", cast_double_complex, cast_double_complex]
5+
["uchar", cast_unsigned_char, cast_unsigned_int @ cast_unsigned_char],
6+
["char", cast_signed_char, cast_signed_int @ cast_signed_char],
7+
["ushort", cast_unsigned_short, cast_unsigned_short],
8+
["short", cast_signed_short, cast_signed_short],
9+
["uint", cast_unsigned_int, cast_unsigned_int],
10+
["int", cast_signed_int, cast_signed_int],
11+
["float", cast_float, cast_float],
12+
["double", cast_double, cast_double],
13+
["complex", cast_complex, cast_complex],
14+
["dcomplex", cast_double_complex, cast_double_complex]
1515
];
1616

1717
// we need a to_real that does images as well
1818
to_real x
19-
= abs x, is_complex x
20-
= mean x, is_Image x
21-
= x;
19+
= abs x, is_complex x
20+
= mean x, is_Image x
21+
= x;
2222

2323
// numbers we test
2424
numbers = [-10, 0, 1, 10, 3.1415927];
2525

2626
test_unary op_name fn
27-
= foldr1 logical_and
28-
[test fname ifmt nfmt x :: [fname, ifmt, nfmt] <- fmts; x <- numbers]
27+
= [test fname ifmt nfmt x :: [fname, ifmt, nfmt] <- fmts; x <- numbers]
2928
{
30-
// image == number can fail due to rounding differences
31-
test fname ifmt nfmt x
32-
= true, abs (image - number) < 0.001
33-
= error (join_sep " " (map print
34-
["unary", fname, op_name, x, "==", image, number]))
35-
{
36-
image = (to_real @ fn @ ifmt @ to_image) x;
37-
number = (to_real @ fn @ nfmt) x;
38-
}
29+
test fname ifmt nfmt x
30+
= [status, message]
31+
{
32+
status = abs (image - number) < 0.001 && abs (matrix - number) < 0.001;
33+
message = join_sep " " (map print [
34+
"unary", fname, op_name, x, "==", image, number, matrix
35+
]);
36+
image = (to_real @ fn @ ifmt @ to_image) x;
37+
number = (to_real @ fn @ nfmt) x;
38+
matrix = (to_real @ fn @ ifmt @ to_matrix) x;
39+
}
3940
}
4041

4142
test_binary op_name fn
42-
= foldr1 logical_and
43-
[test fname ifmt nfmt x y ::
44-
[fname, ifmt, nfmt] <- fmts; x <- numbers; y <- numbers]
43+
= [test fname ifmt nfmt x y ::
44+
[fname, ifmt, nfmt] <- fmts; x <- numbers; y <- numbers]
4545
{
46-
// image == number can fail due to rounding differences
47-
test fname ifmt nfmt x y
48-
= true, abs (image - number) < 0.001
49-
= error (join_sep " " (map print
50-
["binary", fname, x, op_name, y, "==", image, number]))
51-
{
52-
image = to_real (fn ((ifmt @ to_image) x) ((ifmt @ to_image) y));
53-
number = to_real (fn (nfmt x) (nfmt y));
54-
}
46+
// image == number can fail due to rounding differences
47+
test fname ifmt nfmt x y
48+
= [status, message]
49+
{
50+
status = abs (image - number) < 0.001 && abs (matrix - number) < 0.001;
51+
message = join_sep " " (map print [
52+
"binary", fname, x, op_name, y, "==", image, number, matrix
53+
]);
54+
image = to_real (fn ((ifmt @ to_image) x) ((ifmt @ to_image) y));
55+
number = to_real (fn (nfmt x) (nfmt y));
56+
matrix = to_real (fn ((ifmt @ to_matrix) x) ((ifmt @ to_matrix) y));
57+
}
5558
}
5659

5760
tests = [
58-
test_binary "add" add,
59-
test_binary "subtract" subtract,
60-
test_binary "multiply" multiply,
61-
test_binary "divide" test_div,
62-
test_unary "square" square,
63-
test_unary "constant plus" (add 12),
64-
test_unary "plus constant" (converse add 12),
65-
test_unary "divided by constant" (converse test_div 3),
66-
test_unary "multiply constant" (multiply 7),
67-
test_unary "constant multiplied by" (converse multiply 7),
68-
test_unary "constant subtracted from" (subtract 4),
69-
test_unary "subtract constant" (converse subtract 4),
70-
"" ++ "a" == "a",
71-
hd [1, error "nope"] == 1
61+
test_binary "add" add,
62+
test_binary "subtract" subtract,
63+
test_binary "multiply" multiply,
64+
test_binary "divide" test_div,
65+
test_unary "square" square,
66+
test_unary "constant plus" (add 12),
67+
test_unary "plus constant" (converse add 12),
68+
test_unary "divided by constant" (converse test_div 3),
69+
test_unary "multiply constant" (multiply 7),
70+
test_unary "constant multiplied by" (converse multiply 7),
71+
test_unary "constant subtracted from" (subtract 4),
72+
test_unary "subtract constant" (converse subtract 4),
73+
["" ++ "a" == "a", "concat"],
74+
[hd [1, error "nope"] == 1, "lazy hd"]
7275
]
7376
{
74-
// libvips divide returns 0 for divide by zero
75-
test_div a b
76-
= 0, is_real b && b == 0
77-
= 0, is_complex b && re b == 0 && im b == 0
78-
= divide a b;
77+
// libvips divide returns 0 for divide by zero
78+
test_div a b
79+
= 0, is_real b && b == 0
80+
= 0, is_complex b && re b == 0 && im b == 0
81+
= divide a b;
7982
}
8083

8184
main
82-
= "all tests pass", fail == []
83-
= "failed: " ++ join_sep ", " (map print fail_numbers)
85+
= concat (map print_result tests) ++ "\n"
8486
{
85-
numbered = zip2 tests [1..];
86-
fail = filter (not @ extract 0) numbered;
87-
fail_numbers = map (extract 1) fail;
87+
print_result result
88+
= ".", result?0
89+
= error result?1;
8890
}

0 commit comments

Comments
 (0)