Skip to content

Commit

Permalink
test/lib_f_mv: start to test file processing function: f_mv()
Browse files Browse the repository at this point in the history
working on github issue: <#45>
  • Loading branch information
holishing committed Apr 19, 2019
1 parent 3f1bb00 commit 7c081d9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ test/lib_str_pat
test/lib_str_xor
test/lib_xsort
test/testsize
test/lib_f_mv

util/account
util/acl-sort
Expand Down
20 changes: 17 additions & 3 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ SRCROOT = ..

.c.o: ; $(CC) $(MAKEFLAG) $(CFLAGS) -g -c $*.c

EXE = lib_str_decode lib_str_pat lib_str_xor lib_xsort lib_splay testsize
LIBSTR = lib_str_decode lib_str_pat lib_str_xor

LIBFILE = lib_f_mv

LIBOTHER= lib_xsort lib_splay

EXE = $(LIBSTR) $(LIBFILE) $(LIBOTHER)

all: $(EXE)

Expand All @@ -35,11 +41,19 @@ lib_xsort: lib_xsort.o
lib_splay: lib_splay.o
$(CC) $(MAKEFLAG) -o $@ $? $(LDFLAGS)

lib_f_mv: lib_f_mv.o
$(CC) $(MAKEFLAG) -o $@ $? $(LDFLAGS)

testsize: testsize.o
$(CC) $(MAKEFLAG) -o $@ $? $(LDFLAGS)

test:
@printf "\n"; for i in $(EXE); do ./$$i && printf "\033[1;32m$$i test done!\033[0m\n" || ( printf "\033[1;31m$$i test failed!\n\033[0m" && exit 1 ); done
test: noargtest scripttest sizetest

noargtest:
@printf "\n"; for i in $(LIBSTR) $(LIBOTHER); do ./$$i && printf "\033[1;32m$$i test done!\033[0m\n" || ( printf "\033[1;31m$$i test failed!\n\033[0m" && exit 1 ); done

scripttest:
@printf "\n\033[1;33mrunning testing script...\033[0m\n"; sh testscript.sh

sizetest:
@printf "\n"; ./testsize && printf "\033[1;32msize test done!\033[0m\n" || ( printf "\033[1;31msize test failed!\n\033[0m" && exit 1 )
Expand Down
9 changes: 9 additions & 0 deletions test/lib_f_mv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "bbs.h"
#include <string.h>

int main(int argc, char *argv[])
{
printf("\x1b[1;33mCopying %s to %s ....\x1b[0m\n",argv[1],argv[2]);
f_mv(argv[1],argv[2]);
return 0;
}
14 changes: 14 additions & 0 deletions test/testscript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

set -eux

################### test f_mv()
touch before.txt
printf "putsometextin" >> before.txt
test "$(uname -o)" = "GNU/Linux" && sha256_before=$(sha256sum before.txt |awk '{print $1}')
test "$(uname -o)" = "FreeBSD" && sha256_before=$(sha256 before.txt |awk '{print $1}')
./lib_f_mv before.txt after.txt
test "$(uname -o)" = "GNU/Linux" && sha256_after=$(sha256sum after.txt |awk '{print $1}')
test "$(uname -o)" = "FreeBSD" && sha256_after=$(sha256 after.txt |awk '{print $1}')
test "$sha256_before" = "$sha256_after" && printf "\033[1;32mtest f_mv done ok!\033[0m\n"
rm after.txt

0 comments on commit 7c081d9

Please sign in to comment.