Skip to content

Commit d6bfa3f

Browse files
committed
fix compare-output tests on windows
the %a format specifier had different behavior so I used %.013a instead to make it the same on all platforms
1 parent 2a08116 commit d6bfa3f

1 file changed

Lines changed: 81 additions & 52 deletions

File tree

test/compare_output.zig

Lines changed: 81 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,23 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
119119
, "Hello, world!\n0012 012 a\n");
120120

121121
cases.addC("number literals",
122-
\\const c = @cImport(@cInclude("stdio.h"));
122+
\\const builtin = @import("builtin");
123+
\\const is_windows = builtin.os == builtin.Os.windows;
124+
\\const c = @cImport({
125+
\\ if (is_windows) {
126+
\\ // See https://github.com/zig-lang/zig/issues/515
127+
\\ @cDefine("_NO_CRT_STDIO_INLINE", "1");
128+
\\ @cInclude("io.h");
129+
\\ @cInclude("fcntl.h");
130+
\\ }
131+
\\ @cInclude("stdio.h");
132+
\\});
123133
\\
124134
\\export fn main(argc: c_int, argv: &&u8) -> c_int {
135+
\\ if (is_windows) {
136+
\\ // we want actual \n, not \r\n
137+
\\ _ = c._setmode(1, c._O_BINARY);
138+
\\ }
125139
\\ _ = c.printf(c"0: %llu\n",
126140
\\ u64(0));
127141
\\ _ = c.printf(c"320402575052271: %llu\n",
@@ -143,61 +157,61 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
143157
\\
144158
\\ _ = c.printf(c"\n");
145159
\\
146-
\\ _ = c.printf(c"0.0: %a\n",
160+
\\ _ = c.printf(c"0.0: %.013a\n",
147161
\\ f64(0.0));
148-
\\ _ = c.printf(c"0e0: %a\n",
162+
\\ _ = c.printf(c"0e0: %.013a\n",
149163
\\ f64(0e0));
150-
\\ _ = c.printf(c"0.0e0: %a\n",
164+
\\ _ = c.printf(c"0.0e0: %.013a\n",
151165
\\ f64(0.0e0));
152-
\\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %a\n",
166+
\\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %.013a\n",
153167
\\ f64(000000000000000000000000000000000000000000000000000000000.0e0));
154-
\\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %a\n",
168+
\\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %.013a\n",
155169
\\ f64(0.000000000000000000000000000000000000000000000000000000000e0));
156-
\\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %a\n",
170+
\\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %.013a\n",
157171
\\ f64(0.0e000000000000000000000000000000000000000000000000000000000));
158-
\\ _ = c.printf(c"1.0: %a\n",
172+
\\ _ = c.printf(c"1.0: %.013a\n",
159173
\\ f64(1.0));
160-
\\ _ = c.printf(c"10.0: %a\n",
174+
\\ _ = c.printf(c"10.0: %.013a\n",
161175
\\ f64(10.0));
162-
\\ _ = c.printf(c"10.5: %a\n",
176+
\\ _ = c.printf(c"10.5: %.013a\n",
163177
\\ f64(10.5));
164-
\\ _ = c.printf(c"10.5e5: %a\n",
178+
\\ _ = c.printf(c"10.5e5: %.013a\n",
165179
\\ f64(10.5e5));
166-
\\ _ = c.printf(c"10.5e+5: %a\n",
180+
\\ _ = c.printf(c"10.5e+5: %.013a\n",
167181
\\ f64(10.5e+5));
168-
\\ _ = c.printf(c"50.0e-2: %a\n",
182+
\\ _ = c.printf(c"50.0e-2: %.013a\n",
169183
\\ f64(50.0e-2));
170-
\\ _ = c.printf(c"50e-2: %a\n",
184+
\\ _ = c.printf(c"50e-2: %.013a\n",
171185
\\ f64(50e-2));
172186
\\
173187
\\ _ = c.printf(c"\n");
174188
\\
175-
\\ _ = c.printf(c"0x1.0: %a\n",
189+
\\ _ = c.printf(c"0x1.0: %.013a\n",
176190
\\ f64(0x1.0));
177-
\\ _ = c.printf(c"0x10.0: %a\n",
191+
\\ _ = c.printf(c"0x10.0: %.013a\n",
178192
\\ f64(0x10.0));
179-
\\ _ = c.printf(c"0x100.0: %a\n",
193+
\\ _ = c.printf(c"0x100.0: %.013a\n",
180194
\\ f64(0x100.0));
181-
\\ _ = c.printf(c"0x103.0: %a\n",
195+
\\ _ = c.printf(c"0x103.0: %.013a\n",
182196
\\ f64(0x103.0));
183-
\\ _ = c.printf(c"0x103.7: %a\n",
197+
\\ _ = c.printf(c"0x103.7: %.013a\n",
184198
\\ f64(0x103.7));
185-
\\ _ = c.printf(c"0x103.70: %a\n",
199+
\\ _ = c.printf(c"0x103.70: %.013a\n",
186200
\\ f64(0x103.70));
187-
\\ _ = c.printf(c"0x103.70p4: %a\n",
201+
\\ _ = c.printf(c"0x103.70p4: %.013a\n",
188202
\\ f64(0x103.70p4));
189-
\\ _ = c.printf(c"0x103.70p5: %a\n",
203+
\\ _ = c.printf(c"0x103.70p5: %.013a\n",
190204
\\ f64(0x103.70p5));
191-
\\ _ = c.printf(c"0x103.70p+5: %a\n",
205+
\\ _ = c.printf(c"0x103.70p+5: %.013a\n",
192206
\\ f64(0x103.70p+5));
193-
\\ _ = c.printf(c"0x103.70p-5: %a\n",
207+
\\ _ = c.printf(c"0x103.70p-5: %.013a\n",
194208
\\ f64(0x103.70p-5));
195209
\\
196210
\\ _ = c.printf(c"\n");
197211
\\
198-
\\ _ = c.printf(c"0b10100.00010e0: %a\n",
212+
\\ _ = c.printf(c"0b10100.00010e0: %.013a\n",
199213
\\ f64(0b10100.00010e0));
200-
\\ _ = c.printf(c"0o10700.00010e0: %a\n",
214+
\\ _ = c.printf(c"0o10700.00010e0: %.013a\n",
201215
\\ f64(0o10700.00010e0));
202216
\\
203217
\\ return 0;
@@ -213,33 +227,33 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
213227
\\0b1111111111111111111111111111111111111111111111111111111111111111: 18446744073709551615
214228
\\0b0000001111111111111111111111111111111111111111111111111111111111111111: 18446744073709551615
215229
\\
216-
\\0.0: 0x0p+0
217-
\\0e0: 0x0p+0
218-
\\0.0e0: 0x0p+0
219-
\\000000000000000000000000000000000000000000000000000000000.0e0: 0x0p+0
220-
\\0.000000000000000000000000000000000000000000000000000000000e0: 0x0p+0
221-
\\0.0e000000000000000000000000000000000000000000000000000000000: 0x0p+0
222-
\\1.0: 0x1p+0
223-
\\10.0: 0x1.4p+3
224-
\\10.5: 0x1.5p+3
225-
\\10.5e5: 0x1.0059p+20
226-
\\10.5e+5: 0x1.0059p+20
227-
\\50.0e-2: 0x1p-1
228-
\\50e-2: 0x1p-1
230+
\\0.0: 0x0.0000000000000p+0
231+
\\0e0: 0x0.0000000000000p+0
232+
\\0.0e0: 0x0.0000000000000p+0
233+
\\000000000000000000000000000000000000000000000000000000000.0e0: 0x0.0000000000000p+0
234+
\\0.000000000000000000000000000000000000000000000000000000000e0: 0x0.0000000000000p+0
235+
\\0.0e000000000000000000000000000000000000000000000000000000000: 0x0.0000000000000p+0
236+
\\1.0: 0x1.0000000000000p+0
237+
\\10.0: 0x1.4000000000000p+3
238+
\\10.5: 0x1.5000000000000p+3
239+
\\10.5e5: 0x1.0059000000000p+20
240+
\\10.5e+5: 0x1.0059000000000p+20
241+
\\50.0e-2: 0x1.0000000000000p-1
242+
\\50e-2: 0x1.0000000000000p-1
229243
\\
230-
\\0x1.0: 0x1p+0
231-
\\0x10.0: 0x1p+4
232-
\\0x100.0: 0x1p+8
233-
\\0x103.0: 0x1.03p+8
234-
\\0x103.7: 0x1.037p+8
235-
\\0x103.70: 0x1.037p+8
236-
\\0x103.70p4: 0x1.037p+12
237-
\\0x103.70p5: 0x1.037p+13
238-
\\0x103.70p+5: 0x1.037p+13
239-
\\0x103.70p-5: 0x1.037p+3
244+
\\0x1.0: 0x1.0000000000000p+0
245+
\\0x10.0: 0x1.0000000000000p+4
246+
\\0x100.0: 0x1.0000000000000p+8
247+
\\0x103.0: 0x1.0300000000000p+8
248+
\\0x103.7: 0x1.0370000000000p+8
249+
\\0x103.70: 0x1.0370000000000p+8
250+
\\0x103.70p4: 0x1.0370000000000p+12
251+
\\0x103.70p5: 0x1.0370000000000p+13
252+
\\0x103.70p+5: 0x1.0370000000000p+13
253+
\\0x103.70p-5: 0x1.0370000000000p+3
240254
\\
241-
\\0b10100.00010e0: 0x1.41p+4
242-
\\0o10700.00010e0: 0x1.1c0001p+12
255+
\\0b10100.00010e0: 0x1.4100000000000p+4
256+
\\0o10700.00010e0: 0x1.1c00010000000p+12
243257
\\
244258
);
245259

@@ -289,8 +303,23 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
289303
, "");
290304

291305
cases.addC("casting between float and integer types",
292-
\\const c = @cImport(@cInclude("stdio.h"));
306+
\\const builtin = @import("builtin");
307+
\\const is_windows = builtin.os == builtin.Os.windows;
308+
\\const c = @cImport({
309+
\\ if (is_windows) {
310+
\\ // See https://github.com/zig-lang/zig/issues/515
311+
\\ @cDefine("_NO_CRT_STDIO_INLINE", "1");
312+
\\ @cInclude("io.h");
313+
\\ @cInclude("fcntl.h");
314+
\\ }
315+
\\ @cInclude("stdio.h");
316+
\\});
317+
\\
293318
\\export fn main(argc: c_int, argv: &&u8) -> c_int {
319+
\\ if (is_windows) {
320+
\\ // we want actual \n, not \r\n
321+
\\ _ = c._setmode(1, c._O_BINARY);
322+
\\ }
294323
\\ const small: f32 = 3.25;
295324
\\ const x: f64 = small;
296325
\\ const y = i32(x);

0 commit comments

Comments
 (0)