# Path: tests/system/workspace_factory.py
# class workspace_factory(temporary_directory):
# 
#     def __init__(self, source_space='src', prefix=''):
#         super(workspace_factory, self).__init__(prefix=prefix)
#         self.source_space = source_space
# 
#     def __enter__(self):
#         self.temporary_directory = super(workspace_factory, self).__enter__()
#         self.workspace_factory = WorkspaceFactory(self.temporary_directory, self.source_space)
#         return self.workspace_factory
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         super(workspace_factory, self).__exit__(exc_type, exc_value, traceback)
# 
# Path: tests/utils.py
# def catkin_success(args, env={}):
#     orig_environ = dict(os.environ)
#     try:
#         os.environ.update(env)
#         catkin_main(args)
#     except SystemExit as exc:
#         ret = exc.code
#         if ret != 0:
#             import traceback
#             traceback.print_exc()
#     finally:
#         os.environ = orig_environ
#     return ret == 0
# 
# Path: tests/utils.py
# def catkin_failure(args, env={}):
#     orig_environ = dict(os.environ)
#     try:
#         os.environ.update(env)
#         catkin_main(args)
#     except SystemExit as exc:
#         ret = exc.code
#     finally:
#         os.environ = orig_environ
#     return ret != 0


import os
import shutil
from ...workspace_factory import workspace_factory
from ....utils import catkin_success
from ....utils import catkin_failure


TEST_DIR = os.path.dirname(__file__)
RESOURCES_DIR = os.path.join(os.path.dirname(__file__), '..', '..', 'resources')

BUILD = ['build', '--no-notify', '--no-status']
CLEAN = ['clean', '--all', '--yes']  # , '--no-notify', '--no-color', '--no-status']


def test_cmake_args():
    """Test passing CMake args to packages."""
    with workspace_factory():
        shutil.copytree(os.path.join(RESOURCES_DIR, 'catkin_pkgs', 'cmake_args'), 'src')

        # cmake_args package requires all three vars to be set
        assert catkin_failure(
            BUILD +
            ['cmake_args', '--no-deps'] +
            ['--cmake-args', '-DVAR1=VAL1'])

        assert catkin_failure(
            BUILD +
            ['cmake_args', '--no-deps'] +
            ['--cmake-args', '-DVAR1=VAL1', '-DVAR2=VAL2'])

        assert catkin_success(
            BUILD +
            ['cmake_args', '--no-deps'] +
            ['--cmake-args', '-DVAR1=VAL1', '-DVAR2=VAL2', '-DVAR3=VAL3'])


# Path: tests/system/workspace_factory.py
# class workspace_factory(temporary_directory):
# 
#     def __init__(self, source_space='src', prefix=''):
#         super(workspace_factory, self).__init__(prefix=prefix)
#         self.source_space = source_space
# 
#     def __enter__(self):
#         self.temporary_directory = super(workspace_factory, self).__enter__()
#         self.workspace_factory = WorkspaceFactory(self.temporary_directory, self.source_space)
#         return self.workspace_factory
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         super(workspace_factory, self).__exit__(exc_type, exc_value, traceback)
# 
# Path: tests/utils.py
# def catkin_success(args, env={}):
#     orig_environ = dict(os.environ)
#     try:
#         os.environ.update(env)
#         catkin_main(args)
#     except SystemExit as exc:
#         ret = exc.code
#         if ret != 0:
#             import traceback
#             traceback.print_exc()
#     finally:
#         os.environ = orig_environ
#     return ret == 0
# 
# Path: tests/utils.py
# def catkin_failure(args, env={}):
#     orig_environ = dict(os.environ)
#     try:
#         os.environ.update(env)
#         catkin_main(args)
#     except SystemExit as exc:
#         ret = exc.code
#     finally:
#         os.environ = orig_environ
#     return ret != 0


# Path: tests/system/verbs/catkin_build/test_args.py
import os
import shutil
from ...workspace_factory import workspace_factory
from ....utils import catkin_success
from ....utils import catkin_failure



TEST_DIR = os.path.dirname(__file__)
RESOURCES_DIR = os.path.join(os.path.dirname(__file__), '..', '..', 'resources')

BUILD = ['build', '--no-notify', '--no-status']
CLEAN = ['clean', '--all', '--yes']  # , '--no-notify', '--no-color', '--no-status']


def test_cmake_args():
    """Test passing CMake args to packages."""
    with workspace_factory():
        shutil.copytree(os.path.join(RESOURCES_DIR, 'catkin_pkgs', 'cmake_args'), 'src')

        # cmake_args package requires all three vars to be set
        assert catkin_failure(
            BUILD +
            ['cmake_args', '--no-deps'] +
            ['--cmake-args', '-DVAR1=VAL1'])

        assert catkin_failure(
            BUILD +
            ['cmake_args', '--no-deps'] +
            ['--cmake-args', '-DVAR1=VAL1', '-DVAR2=VAL2'])

        assert catkin_success(
            BUILD +
            ['cmake_args', '--no-deps'] +
            ['--cmake-args', '-DVAR1=VAL1', '-DVAR2=VAL2', '-DVAR3=VAL3'])


        assert catkin_success(