toybox/tests/file.test
<<
>>
Prefs
   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
  14
  15testing "directory" "file ." ".: directory\n" "" ""
  16testing "empty" "file empty" "empty: empty\n" "" ""
  17testing "bash.script" "file bash.script" "bash.script: /bin/bash script\n" "" ""
  18testing "bash.script with spaces" "file bash.script2" "bash.script2: /bin/bash script\n" "" ""
  19testing "env python script" "file env.python.script" "env.python.script: python script\n" "" ""
  20testing "ascii" "file ascii" "ascii: ASCII text\n" "" ""
  21testing "utf-8" "file $FILES/utf8/japan.txt | sed 's|$FILES/||'" \
  22    "utf8/japan.txt: UTF-8 text\n" "" ""
  23testing "java class" "file $FILES/java.class | sed 's|$FILES/||'" \
  24    "java.class: Java class file, version 53.0 (Java 1.9)\n" "" ""
  25testing "tar file" "file $FILES/tar/tar.tar | sed 's|$FILES/||'" \
  26    "tar/tar.tar: POSIX tar archive (GNU)\n" "" ""
  27testing "gzip data" "file $FILES/tar/tar.tgz | sed 's|$FILES/||'" \
  28    "tar/tar.tgz: gzip compressed data\n" "" ""
  29testing "bzip2 data" "file $FILES/tar/tar.tbz2 | sed 's|$FILES/||'" \
  30    "tar/tar.tbz2: bzip2 compressed data, block size = 900k\n" "" ""
  31testing "zip file" "file $FILES/zip/example.zip | sed 's|$FILES/||'" \
  32    "zip/example.zip: Zip archive data, requires at least v1.0 to extract\n" "" ""
  33
  34# TODO: check in a genuine minimal .dex
  35testing "Android .dex" "file android.dex" "android.dex: Android dex file, version 035\n" "" ""
  36
  37# These actually test a lot of the ELF code: 32-/64-bit, arm/arm64, PT_INTERP,
  38# the two kinds of NDK ELF note, BuildID, and stripped/not stripped.
  39toyonly testing "Android NDK full ELF note" \
  40    "file $FILES/elf/ndk-elf-note-full | sed 's/^.*: //'" \
  41    "ELF shared object, 64-bit LSB arm64, dynamic (/system/bin/linker64), for Android 24, built by NDK r19b (5304403), BuildID=0c712b8af424d57041b85326f0000fadad38ee0a, not stripped\n" "" ""
  42toyonly testing "Android NDK short ELF note" \
  43    "file $FILES/elf/ndk-elf-note-short | sed 's/^.*: //'" \
  44    "ELF shared object, 32-bit LSB arm, dynamic (/system/bin/linker), for Android 28, BuildID=da6a5f4ca8da163b9339326e626d8a3c, stripped\n" "" ""
  45
  46testing "symlink" "file symlink" "symlink: symbolic link\n" "" ""
  47testing "symlink -h" "file -h symlink" "symlink: symbolic link\n" "" ""
  48testing "symlink -L" "file -L symlink" "symlink: Java class file, version 53.0 (Java 1.9)\n" "" ""
  49
  50testing "- pipe" "cat $FILES/java.class | file -" "-: Java class file, version 53.0 (Java 1.9)\n" "" ""
  51testing "- redirect" "file - <$FILES/java.class" "-: Java class file, version 53.0 (Java 1.9)\n" "" ""
  52
  53testing "/dev/zero" "file /dev/zero" "/dev/zero: character special\n" "" ""
  54testing "- </dev/zero" "file - </dev/zero" "-: data\n" "" ""
  55
  56rm empty bash.script bash.script2 env.python.script ascii android.dex
  57