Use a real .class file and add tests for the other formats that file(1)
recognizes and we already have sample input in tests/files/.
---
 tests/file.test        |  27 ++++++++++++++++++++-------
 tests/files/java.class | Bin 0 -> 182 bytes
 2 files changed, 20 insertions(+), 7 deletions(-)
 create mode 100644 tests/files/java.class
From 879d0faae255fac520e509546d84a75daa6529ab Mon Sep 17 00:00:00 2001
From: Elliott Hughes <e...@google.com>
Date: Fri, 26 Apr 2019 09:33:08 -0700
Subject: [PATCH] file: improve test coverage.

Use a real .class file and add tests for the other formats that file(1)
recognizes and we already have sample input in tests/files/.
---
 tests/file.test        |  27 ++++++++++++++++++++-------
 tests/files/java.class | Bin 0 -> 182 bytes
 2 files changed, 20 insertions(+), 7 deletions(-)
 create mode 100644 tests/files/java.class

diff --git a/tests/file.test b/tests/file.test
index 802f32e1..fa8ea45b 100755
--- a/tests/file.test
+++ b/tests/file.test
@@ -9,16 +9,29 @@ echo "#!/bin/bash" > bash.script
 echo "#!  /bin/bash" > bash.script2
 echo "#!  /usr/bin/env python" > env.python.script
 echo "Hello, world!" > ascii
-echo "cafebabe000000310000" | xxd -r -p > java.class
 echo "6465780a3033350038ca8f6ce910f94e" | xxd -r -p > android.dex
-ln -s java.class symlink
+ln -s $FILES/java.class symlink
 
+testing "directory" "file ." ".: directory\n" "" ""
 testing "empty" "file empty" "empty: empty\n" "" ""
 testing "bash.script" "file bash.script" "bash.script: /bin/bash script\n" "" ""
 testing "bash.script with spaces" "file bash.script2" "bash.script2: /bin/bash 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 "java class" "file java.class" "java.class: Java class file, version 49.0 (Java 1.5)\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 "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,
@@ -32,12 +45,12 @@ toyonly testing "Android NDK short ELF note" \
 
 testing "symlink" "file symlink" "symlink: symbolic link\n" "" ""
 testing "symlink -h" "file -h symlink" "symlink: symbolic link\n" "" ""
-testing "symlink -L" "file -L symlink" "symlink: Java class file, version 49.0 (Java 1.5)\n" "" ""
+testing "symlink -L" "file -L symlink" "symlink: Java class file, version 53.0 (Java 1.9)\n" "" ""
 
-testing "- pipe" "cat java.class | file -" "-: Java class file, version 49.0 (Java 1.5)\n" "" ""
-testing "- redirect" "file - <java.class" "-: Java class file, version 49.0 (Java 1.5)\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" "" ""
 
 testing "/dev/zero" "file /dev/zero" "/dev/zero: character special\n" "" ""
 testing "- </dev/zero" "file - </dev/zero" "-: data\n" "" ""
 
-rm empty bash.script bash.script2 env.python.script ascii java.class android.dex
+rm empty bash.script bash.script2 env.python.script ascii android.dex
diff --git a/tests/files/java.class b/tests/files/java.class
new file mode 100644
index 0000000000000000000000000000000000000000..5ddfa5ef1f1ce15464cff6e311407d7e41e7074f
GIT binary patch
literal 182
zcmX^0Z`VEs1_o0GUM>b^1}=66ZgvJ9Mg}&U%)HDJJ4Oa(4b3n{1{UZ1lvG9rexJ;|
zRKL>Pq|~C2#H1Xc2v=}^X;E^jTPBFZnUz?Us0Si=7+4rsf!aW9Mg{>8rJs|Sm#*)h
zl$DxX!l1~&1hfqV7=aL|7D%!Id9q+W0|Tqpb_T|cU}<(B$p#dLDCGdsObna=;fEht

literal 0
HcmV?d00001

-- 
2.21.0.593.g511ec345e18-goog

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to