[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
yesno test on mingw
From: |
Bruno Haible |
Subject: |
yesno test on mingw |
Date: |
Sun, 27 Apr 2008 16:32:07 +0200 |
User-agent: |
KMail/1.5.4 |
The test-yesno.sh test fails on mingw, for two reasons:
1) It compares output produced with CR/LFs to an expected output with just
LFs.
2) The repositioning of the stdin file descriptor at the end of the
program is not correct. The test case has an input file of 5 lines:
======================= t-yesno-in.tmp ====================
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn - entire line consumed
y<BS>n - backspace does not change result
y
does not match either yesexpr or noexpr
n
===========================================================
When you run commands
{ ./test-yesno.exe $n ; cat ; } < t-yesno-in.tmp
with n = 1,2,3,4,... you can observe:
n=1: end of read at pos 57. cat starts at pos 53 = 57-4
n=2: end of read at pos 96. cat starts at pos 93 = 96-3
n=3: end of read at pos 98. cat starts at pos 96 = 98-2
n=4: end of read at pos 138. cat starts at pos 137 = 138-1
This can be explained by behaviour of the Microsoft runtime: It has filled
stdin's buffer with input from the t-yesno-in.tmp file, and when at the program
end the closein module asks to reposition the file descriptor, the runtime
sets the position to the expected one minus the number of Unix-style newlines
that were in the buffer between the expected position and the end of the
buffer. Microsoft is Microsoft.
The workaround here is to set the file descriptor to binary.
2008-04-27 Bruno Haible <address@hidden>
Make test-yesno.sh work on mingw.
* tests/test-yesno.sh: Postprocess the output to convert CR/LF to LF.
* tests/test-yesno.c: Include yesno.h first. Include binary-io.h.
(main): Set stdin to binary mode.
* modules/yesno-tests (Depends-on): Add binary-io.
*** tests/test-yesno.sh.orig 2008-04-27 16:19:56.000000000 +0200
--- tests/test-yesno.sh 2008-04-27 16:08:21.000000000 +0200
***************
*** 4,16 ****
trap 'rm -fr $tmpfiles' 1 2 3 15
p=t-yesno-
! tmpfiles="${p}in.tmp ${p}xout.tmp ${p}out.tmp ${p}err.tmp"
# For now, only test with C locale
LC_ALL=C
export LC_ALL
! # Test with seekable stdin; followon process must see remaining data
cat <<EOF > ${p}in.tmp
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn - entire line consumed
yn - backspace does not change result
--- 4,24 ----
trap 'rm -fr $tmpfiles' 1 2 3 15
p=t-yesno-
! tmpfiles="${p}in.tmp ${p}xout.tmp ${p}out1.tmp ${p}out.tmp ${p}err.tmp"
# For now, only test with C locale
LC_ALL=C
export LC_ALL
! # Find out how to remove carriage returns from output. Solaris /usr/ucb/tr
! # does not understand '\r'.
! if echo solaris | tr -d '\r' | grep solais > /dev/null; then
! cr='\015'
! else
! cr='\r'
! fi
!
! # Test with seekable stdin; the followon process must see remaining data.
cat <<EOF > ${p}in.tmp
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn - entire line consumed
yn - backspace does not change result
***************
*** 18,23 ****
--- 26,32 ----
does not match either yesexpr or noexpr
n
EOF
+
cat <<EOF > ${p}xout.tmp
N
Y
***************
*** 25,36 ****
N
n
EOF
(./test-yesno${EXEEXT}; ./test-yesno${EXEEXT} 3; cat) \
! < ${p}in.tmp > ${p}out.tmp || exit 1
cmp ${p}xout.tmp ${p}out.tmp || exit 1
(./test-yesno${EXEEXT} 3; ./test-yesno${EXEEXT}; cat) \
! < ${p}in.tmp > ${p}out.tmp || exit 1
cmp ${p}xout.tmp ${p}out.tmp || exit 1
# Test for behavior on pipe
--- 34,48 ----
N
n
EOF
+
(./test-yesno${EXEEXT}; ./test-yesno${EXEEXT} 3; cat) \
! < ${p}in.tmp > ${p}out1.tmp || exit 1
! LC_ALL=C tr -d "$cr" < ${p}out1.tmp > ${p}out.tmp || exit 1
cmp ${p}xout.tmp ${p}out.tmp || exit 1
(./test-yesno${EXEEXT} 3; ./test-yesno${EXEEXT}; cat) \
! < ${p}in.tmp > ${p}out1.tmp || exit 1
! LC_ALL=C tr -d "$cr" < ${p}out1.tmp > ${p}out.tmp || exit 1
cmp ${p}xout.tmp ${p}out.tmp || exit 1
# Test for behavior on pipe
***************
*** 38,55 ****
Y
N
EOF
! echo yes | ./test-yesno${EXEEXT} 2 > ${p}out.tmp || exit 1
cmp ${p}xout.tmp ${p}out.tmp || exit 1
# Test for behavior on EOF
cat <<EOF > ${p}xout.tmp
N
EOF
! ./test-yesno${EXEEXT} </dev/null > ${p}out.tmp || exit 1
cmp ${p}xout.tmp ${p}out.tmp || exit 1
# Test for behavior when stdin is closed
! ./test-yesno${EXEEXT} 0 <&- > ${p}out.tmp 2> ${p}err.tmp && exit 1
cmp ${p}xout.tmp ${p}out.tmp || exit 1
test -s ${p}err.tmp || exit 1
--- 50,70 ----
Y
N
EOF
! echo yes | ./test-yesno${EXEEXT} 2 > ${p}out1.tmp || exit 1
! LC_ALL=C tr -d "$cr" < ${p}out1.tmp > ${p}out.tmp || exit 1
cmp ${p}xout.tmp ${p}out.tmp || exit 1
# Test for behavior on EOF
cat <<EOF > ${p}xout.tmp
N
EOF
! ./test-yesno${EXEEXT} </dev/null > ${p}out1.tmp || exit 1
! LC_ALL=C tr -d "$cr" < ${p}out1.tmp > ${p}out.tmp || exit 1
cmp ${p}xout.tmp ${p}out.tmp || exit 1
# Test for behavior when stdin is closed
! ./test-yesno${EXEEXT} 0 <&- > ${p}out1.tmp 2> ${p}err.tmp && exit 1
! LC_ALL=C tr -d "$cr" < ${p}out1.tmp > ${p}out.tmp || exit 1
cmp ${p}xout.tmp ${p}out.tmp || exit 1
test -s ${p}err.tmp || exit 1
*** tests/test-yesno.c.orig 2008-04-27 16:19:56.000000000 +0200
--- tests/test-yesno.c 2008-04-27 16:18:37.000000000 +0200
***************
*** 1,5 ****
/* Test of yesno module.
! Copyright (C) 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
--- 1,5 ----
/* Test of yesno module.
! Copyright (C) 2007-2008 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
***************
*** 17,28 ****
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "closein.h"
! #include "yesno.h"
char *program_name;
--- 17,31 ----
#include <config.h>
+ /* Specification. */
+ #include "yesno.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "closein.h"
! #include "binary-io.h"
char *program_name;
***************
*** 35,42 ****
--- 38,56 ----
{
int i = 1;
program_name = argv[0];
+
/* yesno recommends that all clients use close_stdin in main. */
atexit (close_stdin);
+ /* But on mingw, close_stdin leaves stdin's file descriptor at the expected
+ position (i.e. where this program left off reading) only if its mode has
+ been set to O_BINARY. If it has been set to O_TEXT, and the file
+ descriptor is seekable, and stdin is buffered, the MSVCRT runtime ends up
+ setting the file descriptor's position to the expected position _minus_
+ the number of LFs not preceded by CR that were read between the expected
+ position and the last filled buffer end position. (I.e. the
repositioning
+ from the end-of-buffer to the expected position does not work if the
input
+ file contains end-of-line markers in Unix convention.) */
+ SET_BINARY (0);
if (1 < argc)
i = atoi (argv[1]);
*** modules/yesno-tests.orig 2008-04-27 16:19:56.000000000 +0200
--- modules/yesno-tests 2008-04-27 16:19:35.000000000 +0200
***************
*** 4,9 ****
--- 4,10 ----
Depends-on:
closein
+ binary-io
configure.ac:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- yesno test on mingw,
Bruno Haible <=