view scripts/test/cut.test @ 1087:b73a61542297 draft

I've finally gotten 'cpio' into a shape where it could be useable. This version can archive and extract directories, sockets, FIFOs, devices, symlinks, and regular files. Supported options are -iot, -H FMT (which is a dummy right now). It only writes newc, and could read newc or newcrc. This does NOT implement -d, which essentially is equivalent to mkdir -p $(dirname $FILE) for every file that needs it. Hard links are not supported, though it would be easy to add them given a hash table or something like that. I also have not implemented the "<n> blocks" output on stderr. If desired, I can add it pretty simply. There is one assumption this makes: that the mode of a file, as mode_t, is bitwise equivalent to the mode as defined for the cpio format. This is true of Linux, but is not mandated by POSIX. If it is compiled for a system where that is false, the archives will not be portable.
author Isaac Dunham <>
date Mon, 14 Oct 2013 11:15:22 -0500
parents 2bfdd63382b4
line wrap: on
line source


# Copyright 2013 Robin Mittal <>
# Copyright 2013 Divya Kothari <>
# Copyright 2013  Kyungwan.Han <>

[ -f ] && .

#testing "name" "command" "result" "infile" "stdin"
#set -x

# Creating test file for testing cut
echo "one:two:three:four:five:six:seven
the quick brown fox jumps over the lazy dog" >abc.txt

testing "cut with -c (a-b)" "cut -c 4-10 abc.txt" ":two:th\nha:beta\n quick \n" "" ""
testing "cut with -f (a-)" "cut -d ':' -f 5- abc.txt" "five:six:seven\nepsilon:zeta:eta:teta:iota:kappa:lambda:mu\nthe quick brown fox jumps over the lazy dog\n" "" ""

testing "cut with -f (a)" "cut -d ' ' -f 3 abc.txt" "one:two:three:four:five:six:seven\nalpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu\nbrown\n" "" ""

testing "cut with echo, -c (a-b)" "echo 'ref_categorie=test' | cut -c 1-15 " "ref_categorie=t\n" "" ""
testing "cut with echo, -c (a)" "echo 'ref_categorie=test' | cut -c 14" "=\n" "" ""

# Modifying abc.txt data as per new testcase
echo "abcdefghijklmnopqrstuvwxyz" >abc.txt

testing "cut with -c (a,b,c)" "cut -c 4,5,20 abc.txt" "det\n" "" ""

testing "cut with -b (a,b,c)" "cut -b 4,5,20 abc.txt" "det\n" "" ""

# Modifying abc.txt data as per testcase
echo "406378:Sales:Itorre:Jan
396082:Sales:Jucacion:Ed" >abc.txt

testing "cut with -d -f(:) -s" "cut -d: -f3 -s abc.txt" "Itorre\nNasium\nAncholie\nJucacion\n" "" ""

testing "cut with -d -f( ) -s" "cut -d' ' -f3 -s abc.txt && echo yes" "yes\n" "" ""

testing "cut with -d -f(a) -s" "cut -da -f3 -s abc.txt" "n\nsium:Jim\n\ncion:Ed\n" "" ""

testing "cut with -d -f(a) -s -n" "cut -da -f3 -s -n abc.txt" "n\nsium:Jim\n\ncion:Ed\n" "" ""

# Removing abc.txt file for cleanup purpose
rm abc.txt