view scripts/test/mkdir.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 <ibid.ag@gmail.com>
date Mon, 14 Oct 2013 11:15:22 -0500
parents d90840f337ea
children 2115856395e2
line wrap: on
line source

#!/bin/bash

[ -f testing.sh ] && . testing.sh

#testing "name" "command" "result" "infile" "stdin"

testing "mkdir" "mkdir one && [ -d one ] && echo yes" "yes\n" "" ""
rmdir one

touch existing
testing "mkdir existing" \
	"mkdir existing 2> /dev/null || [ -f existing ] && echo yes" "yes\n" "" ""
rm existing

testing "mkdir one two" \
	"mkdir one two && [ -d one ] && [ -d two ] && echo yes" "yes\n" "" ""
rmdir one two

testing "mkdir missing/one" \
	"mkdir missing/one 2> /dev/null || [ ! -d missing ] && echo yes" "yes\n" "" ""

testing "mkdir -p" \
	"mkdir -p one/two/three && [ -d one/two/three ] && echo yes" "yes\n" "" ""
rm -rf one

mkdir existing
testing "mkdir -p existing" "mkdir -p existing && echo yes" "yes\n" "" ""
rmdir existing

umask 123
testing "mkdir (default permissions)" \
	"mkdir one && stat -c %a one" "654\n" "" ""
rmdir one

testing "mkdir -m 124" \
	"mkdir -m 124 one && stat -c %a one" "124\n" "" ""
rmdir one

umask 000
testing "mkdir -p -m 653" \
	"mkdir -p -m 653 one/two && stat -c %a one && stat -c %a one/two" \
	"777\n653\n" "" ""
rm -rf one

testing "mkdir -p one/two/ (trailing slash)" \
	"mkdir -p one/two/ &&  [ -d one/two ] && echo yes" "yes\n" "" ""
rm -rf one

umask 022
testing "mkdir -p -m 777 (022 umask)" \
	"mkdir -p -m 777 one/two && stat -c %a one && stat -c %a one/two" \
	"755\n777\n" "" ""
rm -rf one

umask 377
testing "mkdir -p -m 777 (377 umask)" \
	"mkdir -p -m 777 one/two && stat -c %a one && stat -c %a one/two" \
	"700\n777\n" "" ""
umask 002
rm -rf one