"""
 *
 * This file is part of rasdaman community.
 *
 * Rasdaman community is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Rasdaman community is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU  General Public License for more details.
 *
 * You should have received a copy of the GNU  General Public License
 * along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright 2003 - 2016 Peter Baumann / rasdaman GmbH.
 *
 * For more information please see <http://www.rasdaman.org>
 * or contact Peter Baumann via <baumann@rasdaman.com>.
 *
"""

import sys
import getpass
from config_manager import ConfigManager
from util.executor import ExecutionError
from tester.tester import test as TesterTest
from builder.builder import test as BuilderTest
from preparer.preparer import test as PreparerTest
from tpinstaller.tpinstaller import test as TPTest

tests = [(TesterTest, "tester"),
         (BuilderTest, "builder"),
         (PreparerTest, "preparer"),
         (TPTest, "third party installer")]

if __name__== "__main__":
    ConfigManager.default_user = getpass.getuser() # set correct user

    res = True
    total_tests = len(tests)
    curr_test = 1

    for test, test_desc in tests:
        try:
            print("{}/{} executing {} test".format(curr_test, total_tests, test_desc))
            res = res and test()
        except ExecutionError as e:
            print(e)
            res = False
        except Exception as e:
            print(e)
            res = False
        finally:
            curr_test += 1

    if not res:
        sys.exit(1)
    sys.exit(0)

