Bladeren bron

ctype: tests and reorganize

Wrote tests for the functions implemented in 40558b2 and maybe made that
test a little more comprehensible.

Also made sure that fmt.sh and test.sh were being executed by bash all
the time (compatibility with other shells).
MggMuggins 7 jaren geleden
bovenliggende
commit
6ced871d9a
7 gewijzigde bestanden met toevoegingen van 30 en 17 verwijderingen
  1. 1 0
      fmt.sh
  2. 8 8
      src/ctype/src/lib.rs
  3. 1 1
      src/platform/src/linux/mod.rs
  4. 1 1
      src/platform/src/redox/mod.rs
  5. 1 1
      src/stdio/src/lib.rs
  6. 1 0
      test.sh
  7. 17 6
      tests/ctype.c

+ 1 - 0
fmt.sh

@@ -1,3 +1,4 @@
+#!/bin/bash
 ARGS=()
 
 for crate in relibc $(find src -name Cargo.toml | cut -d '/' -f2 | grep -v template)

+ 8 - 8
src/ctype/src/lib.rs

@@ -21,6 +21,11 @@ pub extern "C" fn isascii(c: c_int) -> c_int {
     (!(c & !0x7f)) as c_int
 }
 
+#[no_mangle]
+pub extern "C" fn isblank(c: c_int) -> c_int {
+    (c == ' ' as c_int || c == '\t' as c_int) as c_int
+}
+
 #[no_mangle]
 pub extern "C" fn iscntrl(c: c_int) -> c_int {
     ((c as c_uint) < 0x20 || c == 0x7f) as c_int
@@ -48,7 +53,7 @@ pub extern "C" fn isprint(c: c_int) -> c_int {
 
 #[no_mangle]
 pub extern "C" fn ispunct(c: c_int) -> c_int {
-    (isgraph(c) == 0 && !isalnum(c) == 0) as c_int
+    (isgraph(c) != 0 && !isalnum(c) != 0) as c_int
 }
 
 #[no_mangle]
@@ -63,17 +68,12 @@ pub extern "C" fn isupper(c: c_int) -> c_int {
 
 #[no_mangle]
 pub extern "C" fn isxdigit(c: c_int) -> c_int {
-    (isdigit(c) == 0 || ((c as c_int) | 32) - ('a' as c_int) < 6) as c_int
-}
-
-#[no_mangle]
-pub extern "C" fn isblank(c: c_int) -> c_int {
-    (c == ' ' as c_int || c == '\t' as c_int) as c_int
+    (isdigit(c) != 0 || ((c as c_int) | 32) - ('a' as c_int) < 6) as c_int
 }
 
 #[no_mangle]
 /// The comment in musl:
-/// `/* nonsense function that should NEVER be used! */`
+/// "nonsense function that should NEVER be used!"
 pub extern "C" fn toascii(c: c_int) -> c_int {
     c & 0x7f
 }

+ 1 - 1
src/platform/src/linux/mod.rs

@@ -63,7 +63,7 @@ pub fn fchdir(fildes: c_int) -> c_int {
 }
 
 pub fn fork() -> pid_t {
-    e(unsafe {syscall!(FORK) }) as pid_t
+    e(unsafe { syscall!(FORK) }) as pid_t
 }
 
 pub fn fsync(fildes: c_int) -> c_int {

+ 1 - 1
src/platform/src/redox/mod.rs

@@ -64,7 +64,7 @@ pub fn fchdir(fd: c_int) -> c_int {
 }
 
 pub fn fork() -> pid_t {
-   e(unsafe { syscall::clone(0) }) as pid_t
+    e(unsafe { syscall::clone(0) }) as pid_t
 }
 
 pub fn fsync(fd: c_int) -> c_int {

+ 1 - 1
src/stdio/src/lib.rs

@@ -2,9 +2,9 @@
 
 #![no_std]
 
+extern crate errno;
 extern crate platform;
 extern crate va_list as vl;
-extern crate errno;
 
 use core::str;
 use core::fmt::Write;

+ 1 - 0
test.sh

@@ -1,3 +1,4 @@
+#!/bin/bash
 set -ex
 
 cargo build

+ 17 - 6
tests/ctype.c

@@ -6,17 +6,28 @@ struct test_case {
     int isalnum;
     int isalpha;
     int isascii;
+    int isblank;
+    int iscntrl;
     int isdigit;
+    int isgraph;
     int islower;
+    int isprint;
+    int ispunct;
     int isspace;
     int isupper;
+    int isxdigit;
 } test_cases[] = {
-    { 'A', 1, 1, 1, 0, 0, 0, 1},
-    { 'z', 1, 1, 1, 0, 1, 0, 0},
-    { ' ', 0, 0, 1, 0, 0, 1, 0},
-    { '1', 1, 0, 1, 1, 0, 0, 0},
-    { '9', 1, 0, 1, 1, 0, 0, 0},
-    {0x80, 0, 0, 0, 0, 0, 0, 0}
+    //     a  a  a  b  c  d  g  l  p  p  s  u  x
+    //     l  l  s  l  n  i  r  o  r  u  p  p  d
+    //     n  p  c  a  t  g  a  w  i  n  a  p  i
+    //     u  h  i  n  r  i  p  e  n  c  c  e  g
+    //     m  a  i  k  l  t  h  r  t  t  e  r  i
+    { 'A', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1},
+    { 'z', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
+    { ' ', 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0},
+    { '1', 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1},
+    { '9', 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1},
+    {0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
 };
 size_t num_test_cases = sizeof(test_cases)/sizeof(struct test_case);