yyang42 / moulitest

This repository contains tests for several projects done at 42.
127 stars 37 forks source link

[FAIL] test_num1 -> ft_isprint('a') == ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _I... #15

Closed thomas-touhey closed 9 years ago

thomas-touhey commented 9 years ago

Hi, I have a strange error for ft_isprint testing, I don't understand it...

thomas@skater :: Bureau/moulitest » make libft_part1 PATTERN=ft_isprint
(blah blah blah)
[ -------STARTING ALL UNIT TESTS------- ]
>>>> 00_part1_ft_isprint.spec.c -- [FAIL] F.................. [FAIL] test_num1 -> ft_isprint('a') == ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _I...
[ ----------END OF UNIT TESTS---------- ]

>>>> Result: 0/1 test suites passed. 18/19 tests passed (dots).

My ft_isprint function is defined like this :

int ft_isprint(int c)
{
    return (c >= 32);
}

And I tested it personally for 'a', it returned 1. So why is it considered as a fail ?

yyang42 commented 9 years ago

Hi, I'm not sure why this is happening.

Try to add some debug in this file : moulitest/libft_tests/tests/00_part1_ft_isprint.spec.c and examine the result.

printf("ft_isprint(%c) : %d\n", tested_char, ft_isprint(tested_char));
printf("isprint(%c) : %d\n", tested_char, isprint(tested_char));
mt_assert(ft_isprint(tested_char) == isprint(tested_char));
thomas-touhey commented 9 years ago

I obtain this result... O_O

ft_isprint(a) : 1
isprint(a) : 16384
ft_isprint(a) : 1
isprint(a) : 0
ft_isprint(2) : 1
isprint(2) : 16384
ft_isprint(Z) : 1
isprint(Z) : 16384
ft_isprint(t) : 1
isprint(t) : 16384

I'll edit this message as soon as I find why.

JulienBalestra commented 9 years ago

Hello, may you work only on Darwin kernel (MacOS) with yyang moulitest because of varying returning libc fonctions under linux kernel. On 11 Nov 2015 6:49 am, "Thomas Touhey" notifications@github.com wrote:

I obtain this result... O_O

ft_isprint(a) : 1 isprint(a) : 16384 ft_isprint(a) : 1 isprint(a) : 0 ft_isprint(2) : 1 isprint(2) : 16384 ft_isprint(Z) : 1 isprint(Z) : 16384 ft_isprint(t) : 1 isprint(t) : 16384

I'll edit this message as soon as I find why.

— Reply to this email directly or view it on GitHub https://github.com/yyang42/moulitest/issues/15#issuecomment-155673431.

thomas-touhey commented 9 years ago

Oh, that may be the reason then : I'm actually on my own computer, which is on Debian 8.2 Jessie. Anyway, I found a workaround which is correct according to the manual, so everything works all right now ^^

yyang42 commented 9 years ago

@JulienBalestra This PR from @touhey solves the issue: https://github.com/yyang42/moulitest/pull/16

mtassett commented 8 years ago

Il y a le meme probleme avec isalpha, isascii, isdigit et isprint sous linux, j'essaye de faire un PR demain. @touhey http://lxr.free-electrons.com/source/include/linux/ctype.h, linux is using a mask like for the permissions on a file (rwx), that's why you were getting 'strange' values.

yyang42 commented 8 years ago

Thanks @marc3825 your PR https://github.com/yyang42/moulitest/pull/17 has been merged.

I replace the ft_isalnum(tested_char) && 1 with ft_isalnum(tested_char) != 0 to expressed a bit better the what the man says. https://github.com/yyang42/moulitest/commit/3cbc39deba4b4f969bbcccff4a859c777b835ae4

RETURN VALUES The isalpha() function returns zero if the character tests false and returns non-zero if the character tests true.