|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +""" |
| 4 | +$Id$ |
| 5 | +
|
| 6 | +This file is part of the sqlmap project, http://sqlmap.sourceforge.net. |
| 7 | +
|
| 8 | +Copyright (c) 2010 Miroslav Stampar <[email protected]> |
| 9 | +
|
| 10 | +sqlmap is free software; you can redistribute it and/or modify it under |
| 11 | +the terms of the GNU General Public License as published by the Free |
| 12 | +Software Foundation version 2 of the License. |
| 13 | +
|
| 14 | +sqlmap is distributed in the hope that it will be useful, but WITHOUT ANY |
| 15 | +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 16 | +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 17 | +details. |
| 18 | +
|
| 19 | +You should have received a copy of the GNU General Public License along |
| 20 | +with sqlmap; if not, write to the Free Software Foundation, Inc., 51 |
| 21 | +Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | +""" |
| 23 | + |
| 24 | +import os |
| 25 | +import sys |
| 26 | + |
| 27 | +from lib.core.data import conf |
| 28 | +from lib.core.data import logger |
| 29 | +from lib.core.data import paths |
| 30 | + |
| 31 | +def smokeTest(): |
| 32 | + """ |
| 33 | + This will run the basic smoke testing of a program |
| 34 | + """ |
| 35 | + import doctest |
| 36 | + retVal = True |
| 37 | + for root, _, files in os.walk(paths.SQLMAP_ROOT_PATH): |
| 38 | + for file in files: |
| 39 | + if os.path.splitext(file)[1].lower() == '.py' and file != '__init__.py': |
| 40 | + path = os.path.join(root, os.path.splitext(file)[0]) |
| 41 | + path = path.replace(paths.SQLMAP_ROOT_PATH, '.') |
| 42 | + path = path.replace(os.sep, '.').lstrip('.') |
| 43 | + try: |
| 44 | + __import__(path) |
| 45 | + module = sys.modules[path] |
| 46 | + except Exception, msg: |
| 47 | + retVal = False |
| 48 | + errMsg = "smoke test failed at importing module '%s' (%s):\n%s\n" % (path, os.path.join(paths.SQLMAP_ROOT_PATH, file), msg) |
| 49 | + logger.error(errMsg) |
| 50 | + else: |
| 51 | + # Run doc tests |
| 52 | + # Reference: http://docs.python.org/library/doctest.html |
| 53 | + (failure_count, test_count) = doctest.testmod(module) |
| 54 | + if failure_count > 0: |
| 55 | + retVal = False |
| 56 | + |
| 57 | + infoMsg = "smoke test " |
| 58 | + if retVal: |
| 59 | + infoMsg += "PASSED" |
| 60 | + logger.info(infoMsg) |
| 61 | + else: |
| 62 | + infoMsg += "FAILED" |
| 63 | + logger.error(infoMsg) |
| 64 | + return retVal |
0 commit comments