aboutsummaryrefslogtreecommitdiff
path: root/tests/file.test
blob: 419da0a6a23a3c72b8429dc9ef97d6492a369481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash

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

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

touch empty
echo "#!/bin/bash" > bash.script
echo "#!  /bin/bash" > bash.script2
echo "#!  /usr/bin/env python" > env.python.script
echo "Hello, world!" > ascii
echo "6465780a3033350038ca8f6ce910f94e" | xxd -r -p > android.dex
ln -s $FILES/java.class symlink
LINK=$(readlink symlink)
ln -s $FILES/java.klass dangler
BROKEN=$(readlink dangler)

testing "directory" "file ." ".: directory\n" "" ""
testing "empty" "file empty" "empty: empty\n" "" ""
testing "bash.script" "file bash.script | grep -o ' script"' " script\n" "" ""
testing "bash.script with spaces" "file bash.script2 | grep -o ' script'" " script\n" "" ""
testing "env python script" "file env.python.script" "env.python.script: python script\n" "" ""
testing "ascii" "file ascii" "ascii: ASCII text\n" "" ""
testing "utf-8" "file $FILES/utf8/japan.txt | sed 's|$FILES/||'" \
    "utf8/japan.txt: UTF-8 text\n" "" ""
testing "java class" "file $FILES/java.class | sed 's|$FILES/||'" \
    "java.class: Java class file, version 53.0 (Java 1.9)\n" "" ""
testing "tar file" "file $FILES/tar/tar.tar | sed 's|$FILES/||'" \
    "tar/tar.tar: POSIX tar archive (GNU)\n" "" ""
testing "gzip data" "file $FILES/tar/tar.tgz | sed 's|$FILES/||'" \
    "tar/tar.tgz: gzip compressed data\n" "" ""
testing "bzip2 data" "file $FILES/tar/tar.tbz2 | sed 's|$FILES/||'" \
    "tar/tar.tbz2: bzip2 compressed data, block size = 900k\n" "" ""
testing "7z file" "file $FILES/tar/tar.7z | sed 's|$FILES/||'" \
    "tar/tar.7z: 7-zip archive data, version 0.4\n" "" ""
testing "zip file" "file $FILES/zip/example.zip | sed 's|$FILES/||'" \
    "zip/example.zip: Zip archive data, requires at least v1.0 to extract\n" "" ""

# TODO: check in a genuine minimal .dex
testing "Android .dex" "file android.dex" "android.dex: Android dex file, version 035\n" "" ""

# These actually test a lot of the ELF code: 32-/64-bit, arm/arm64, PT_INTERP,
# the two kinds of NDK ELF note, BuildID, and stripped/not stripped.
toyonly testing "Android NDK full ELF note" \
    "file $FILES/elf/ndk-elf-note-full | sed 's/^.*: //'" \
    "ELF shared object, 64-bit LSB arm64, dynamic (/system/bin/linker64), for Android 24, built by NDK r19b (5304403), BuildID=0c712b8af424d57041b85326f0000fadad38ee0a, not stripped\n" "" ""
toyonly testing "Android NDK short ELF note" \
    "file $FILES/elf/ndk-elf-note-short | sed 's/^.*: //'" \
    "ELF shared object, 32-bit LSB arm, dynamic (/system/bin/linker), for Android 28, BuildID=da6a5f4ca8da163b9339326e626d8a3c, stripped\n" "" ""

testing "broken symlink" "file dangler" "dangler: broken symbolic link to $BROKEN\n" "" ""
testing "symlink" "file symlink" "symlink: symbolic link to $LINK\n" "" ""
testing "symlink -h" "file -h symlink" "symlink: symbolic link to $LINK\n" "" ""
testing "symlink -L" "file -L symlink" "symlink: Java class file, version 53.0 (Java 1.9)\n" "" ""

testing "- pipe" "cat $FILES/java.class | file -" "-: Java class file, version 53.0 (Java 1.9)\n" "" ""
testing "- redirect" "file - <$FILES/java.class" "-: Java class file, version 53.0 (Java 1.9)\n" "" ""

zero_dev="1/5"
[ "$(uname)" == "Darwin" ] && zero_dev="3/3"
testing "/dev/zero" "file /dev/zero" "/dev/zero: character special ($zero_dev)\n" "" ""
testing "- </dev/zero" "file - </dev/zero" "-: data\n" "" ""

rm empty bash.script bash.script2 env.python.script ascii android.dex