diff --git a/.github/workflows/compile-linux.yml b/.github/workflows/compile-linux.yml index bf9a2f9..a283e8f 100644 --- a/.github/workflows/compile-linux.yml +++ b/.github/workflows/compile-linux.yml @@ -27,13 +27,21 @@ jobs: run: | sudo apt-get -y install libjpeg-dev - # Initialize and build + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: "3.11" + - name: Build run: | ./configure make -j make printable.man + - name: Tests + run: | + make test + # Gather documentation and executables to a common directory - name: Prepare files if: matrix.os != 'ubuntu-latest' diff --git a/Makefile.in b/Makefile.in index 83b581d..348cf5c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -103,7 +103,7 @@ spell: codespell -S .git,tools test: all - (cd test && $(PYTHON) test.py) + (cd test && $(PYTHON) test.py -v) .PHONY: test diff --git a/test/test.py b/test/test.py old mode 100644 new mode 100755 index f291d5b..5d143f3 --- a/test/test.py +++ b/test/test.py @@ -31,12 +31,7 @@ class JpeginfoTests(unittest.TestCase): def run_test(self, args, check=True): """execute jpeginfo for a test""" - command = [self.program] - if isinstance(args, list): - command.extend(args) - else: - if len(args) > 0: - command.append(args) + command = [self.program] + args res = subprocess.run(command, encoding="utf-8", check=check, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) output = res.stdout @@ -47,25 +42,69 @@ def run_test(self, args, check=True): def test_version(self): """test version information output""" - output, _ = self.run_test('--version') + output, _ = self.run_test(['--version']) self.assertIn('GNU General Public License', output) self.assertRegex(output, r'jpeginfo v\d+\.\d+\.\d') def test_noarguments(self): """test running withouth arguments""" - output, res = self.run_test('', check=False) + output, res = self.run_test([], check=False) self.assertEqual(1, res) self.assertIn('file arguments missing', output) def test_basic(self): """test basic output""" - output, _ = self.run_test('jpeginfo_test1.jpg') + output, _ = self.run_test(['jpeginfo_test1.jpg']) self.assertRegex(output, r'jpeginfo_test1.jpg\s+2100\s+x\s+1500\s+24bit\s+' r'P\s+Exif,IPTC,XMP,ICC,Adobe,UNKNOWN\s+320159') + def test_check_mode(self): + """test checking image integrity""" + output, res = self.run_test(['-c','jpeginfo_test2.jpg'], check=False) + self.assertEqual(0, res) + output, res = self.run_test(['-c','jpeginfo_test2_broken.jpg'], check=False) + self.assertIn('WARNING Premature end of JPEG file', output) + self.assertNotEqual(0, res) + + def test_progressive(self): + """test progressive mode detection""" + output, _ = self.run_test(['jpeginfo_test1.jpg']) + self.assertRegex(output, r'bit\s+P\s+') + + def test_nonprogressive(self): + """test non-progressive mode detection""" + output, _ = self.run_test(['jpeginfo_test2.jpg']) + self.assertRegex(output, r'bit\s+N\s') + + def test_grayscale(self): + """test grayscale image detection""" + output, _ = self.run_test(['jpeginfo_test3.jpg']) + self.assertRegex(output, r'\s8bit\s') + + def test_md5(self): + """test image MD5 checksum""" + output, _ = self.run_test(['--md5', 'jpeginfo_test1.jpg']) + self.assertIn('536c217b027d44cc2e4a0ad8e6e531fe', output) + + def test_sha256(self): + """test image SHA2-256 checksum""" + output, _ = self.run_test(['--sha256', 'jpeginfo_test1.jpg']) + self.assertIn('9a36209da080e187a2f749ec4ed0db3e73bcebc689ca060d929bdc7d1384edac', output) + + def test_sha512(self): + """test image SHA2-512 checksum""" + output, _ = self.run_test(['--sha512', 'jpeginfo_test1.jpg']) + self.assertIn('4d5dc047caf3cbd84eec91dce3c14e938d8d3f730b152eefb72c8c3ebfa65e91' + '46bd304b15e009df6f74e7397435a10f375c5453a60e32c9aca738051c36e211', output) + + def test_comments(self): + """test image comments""" + output, _ = self.run_test(['-C', 'jpeginfo_test2.jpg']) + self.assertIn('This is a test comment.', output) + + if __name__ == '__main__': unittest.main() - # eof :-)