• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3[ -f testing.sh ] && . testing.sh
4
5#testing "name" "command" "result" "infile" "stdin"
6
7touch empty
8echo "#!/bin/bash" > bash.script
9echo "#!  /bin/bash" > bash.script2
10echo "#!  /usr/bin/env python" > env.python.script
11echo "Hello, world!" > ascii
12echo "6465780a3033350038ca8f6ce910f94e" | xxd -r -p > android.dex
13ln -s $FILES/java.class symlink
14LINK=$(readlink symlink)
15ln -s $FILES/java.klass dangler
16BROKEN=$(readlink dangler)
17
18testing "directory" "file ." ".: directory\n" "" ""
19testing "empty" "file empty" "empty: empty\n" "" ""
20testing "bash.script" "file bash.script" "bash.script: /bin/bash script\n" "" ""
21testing "bash.script with spaces" "file bash.script2" "bash.script2: /bin/bash script\n" "" ""
22testing "env python script" "file env.python.script" "env.python.script: python script\n" "" ""
23testing "ascii" "file ascii" "ascii: ASCII text\n" "" ""
24testing "utf-8" "file $FILES/utf8/japan.txt | sed 's|$FILES/||'" \
25    "utf8/japan.txt: UTF-8 text\n" "" ""
26testing "java class" "file $FILES/java.class | sed 's|$FILES/||'" \
27    "java.class: Java class file, version 53.0 (Java 1.9)\n" "" ""
28testing "tar file" "file $FILES/tar/tar.tar | sed 's|$FILES/||'" \
29    "tar/tar.tar: POSIX tar archive (GNU)\n" "" ""
30testing "gzip data" "file $FILES/tar/tar.tgz | sed 's|$FILES/||'" \
31    "tar/tar.tgz: gzip compressed data\n" "" ""
32testing "bzip2 data" "file $FILES/tar/tar.tbz2 | sed 's|$FILES/||'" \
33    "tar/tar.tbz2: bzip2 compressed data, block size = 900k\n" "" ""
34testing "zip file" "file $FILES/zip/example.zip | sed 's|$FILES/||'" \
35    "zip/example.zip: Zip archive data, requires at least v1.0 to extract\n" "" ""
36
37# TODO: check in a genuine minimal .dex
38testing "Android .dex" "file android.dex" "android.dex: Android dex file, version 035\n" "" ""
39
40# These actually test a lot of the ELF code: 32-/64-bit, arm/arm64, PT_INTERP,
41# the two kinds of NDK ELF note, BuildID, and stripped/not stripped.
42toyonly testing "Android NDK full ELF note" \
43    "file $FILES/elf/ndk-elf-note-full | sed 's/^.*: //'" \
44    "ELF shared object, 64-bit LSB arm64, dynamic (/system/bin/linker64), for Android 24, built by NDK r19b (5304403), BuildID=0c712b8af424d57041b85326f0000fadad38ee0a, not stripped\n" "" ""
45toyonly testing "Android NDK short ELF note" \
46    "file $FILES/elf/ndk-elf-note-short | sed 's/^.*: //'" \
47    "ELF shared object, 32-bit LSB arm, dynamic (/system/bin/linker), for Android 28, BuildID=da6a5f4ca8da163b9339326e626d8a3c, stripped\n" "" ""
48
49testing "broken symlink" "file dangler" "dangler: broken symbolic link to $BROKEN\n" "" ""
50testing "symlink" "file symlink" "symlink: symbolic link to $LINK\n" "" ""
51testing "symlink -h" "file -h symlink" "symlink: symbolic link to $LINK\n" "" ""
52testing "symlink -L" "file -L symlink" "symlink: Java class file, version 53.0 (Java 1.9)\n" "" ""
53
54testing "- pipe" "cat $FILES/java.class | file -" "-: Java class file, version 53.0 (Java 1.9)\n" "" ""
55testing "- redirect" "file - <$FILES/java.class" "-: Java class file, version 53.0 (Java 1.9)\n" "" ""
56
57zero_dev="1/5"
58[ "$(uname)" == "Darwin" ] && zero_dev="3/3"
59testing "/dev/zero" "file /dev/zero" "/dev/zero: character special ($zero_dev)\n" "" ""
60testing "- </dev/zero" "file - </dev/zero" "-: data\n" "" ""
61
62rm empty bash.script bash.script2 env.python.script ascii android.dex
63