2017-12-15 00:29:38 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2017-12-19 22:51:03 +01:00
|
|
|
import glob
|
|
|
|
import inspect
|
|
|
|
import logging
|
2017-12-15 00:29:38 +01:00
|
|
|
import optparse
|
2017-12-19 22:51:03 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
localmodule = os.path.realpath(
|
|
|
|
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
|
|
|
|
print('localmodule: ' + localmodule)
|
|
|
|
if localmodule not in sys.path:
|
|
|
|
sys.path.insert(0, localmodule)
|
2017-12-15 00:29:38 +01:00
|
|
|
|
|
|
|
import fdroidserver.common
|
2017-12-19 22:51:03 +01:00
|
|
|
import fdroidserver.metadata
|
|
|
|
import fdroidserver.scanner
|
2017-12-15 00:29:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ScannerTest(unittest.TestCase):
|
2017-12-19 22:51:03 +01:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
self.basedir = os.path.join(localmodule, 'tests')
|
|
|
|
|
2017-12-15 00:29:38 +01:00
|
|
|
def test_scan_source_files(self):
|
2020-05-14 16:08:56 +02:00
|
|
|
fdroidserver.scanner.options = type('', (), {})()
|
|
|
|
fdroidserver.scanner.options.json = False
|
2017-12-19 22:51:03 +01:00
|
|
|
source_files = os.path.join(self.basedir, 'source-files')
|
2017-12-15 00:29:38 +01:00
|
|
|
projects = {
|
2020-01-31 23:49:50 +01:00
|
|
|
'cn.wildfirechat.chat': 4,
|
2020-02-03 21:13:26 +01:00
|
|
|
'com.integreight.onesheeld': 11,
|
2017-12-15 00:29:38 +01:00
|
|
|
'Zillode': 1,
|
2019-10-23 12:23:37 +02:00
|
|
|
'firebase-suspect': 1,
|
2019-11-02 19:54:54 +01:00
|
|
|
'org.mozilla.rocket': 3,
|
2019-10-23 12:23:37 +02:00
|
|
|
'realm': 1,
|
2020-02-13 10:22:24 +01:00
|
|
|
'se.manyver': 2,
|
2017-12-15 00:29:38 +01:00
|
|
|
}
|
2017-12-19 22:51:03 +01:00
|
|
|
for d in glob.glob(os.path.join(source_files, '*')):
|
|
|
|
build = fdroidserver.metadata.Build()
|
|
|
|
fatal_problems = fdroidserver.scanner.scan_source(d, build)
|
2019-10-23 12:23:37 +02:00
|
|
|
should = projects.get(os.path.basename(d), 0)
|
|
|
|
self.assertEqual(should, fatal_problems,
|
|
|
|
"%s should have %d errors!" % (d, should))
|
2017-12-15 00:29:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-08-14 10:34:13 +02:00
|
|
|
os.chdir(os.path.dirname(__file__))
|
|
|
|
|
2017-12-15 00:29:38 +01:00
|
|
|
parser = optparse.OptionParser()
|
|
|
|
parser.add_option("-v", "--verbose", action="store_true", default=False,
|
|
|
|
help="Spew out even more information than normal")
|
|
|
|
(fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
|
|
|
|
|
|
|
|
newSuite = unittest.TestSuite()
|
|
|
|
newSuite.addTest(unittest.makeSuite(ScannerTest))
|
|
|
|
unittest.main(failfast=False)
|