Esempio n. 1
0
    def test_samples(self):
        relativeexpectedexes = {
            'simple/helloworld_c.c',
            'simple/helloworld_cpp.cpp',
            'dottypaths/dottypaths.cpp',
            'library/main.cpp',
            'lotsofmagic/lotsofmagic.cpp',
            'magicsourceinheader/main.cpp',
            'magicinclude/main.cpp',
            'movingheaders/main.cpp'}
        relativeexpectedtests = {
            'cross_platform/test_source.cpp',
            'factory/test_factory.cpp',
            'numbers/test_direct_include.cpp',
            'numbers/test_library.cpp',
            'simple/test_cflags.c'}

        expectedexes = { os.path.realpath(os.path.join(uth.samplesdir(),exe)) for exe in relativeexpectedexes }
        expectedtests = { os.path.realpath(os.path.join(uth.samplesdir(),tt)) for tt in relativeexpectedtests }
        config_files = ct.configutils.config_files_from_variant(exedir=uth.cakedir(), argv=[])
        cap = configargparse.getArgumentParser(
            description='TestFindTargetsModule',
            formatter_class=configargparse.ArgumentDefaultsHelpFormatter,
            default_config_files=config_files,
            args_for_setting_config_path=["-c","--config"],
            ignore_unknown_config_file_keys=True)
        ct.findtargets.add_arguments(cap)
        args = ct.apptools.parseargs(cap, argv=['--shorten'])
        findtargets = ct.findtargets.FindTargets(args,exedir=uth.cakedir())
        executabletargets, testtargets = findtargets(path=uth.cakedir())
        self.assertSetEqual(expectedexes, set(executabletargets))
        self.assertSetEqual(expectedtests, set(testtargets))
Esempio n. 2
0
 def test_implied_source(self):
     relativefilename = "dottypaths/d2/d2.hpp"
     basename = os.path.splitext(relativefilename)[0]
     expected = os.path.join(uth.samplesdir(), basename + ".cpp")
     result = utils.implied_source(
         os.path.join(uth.samplesdir(), relativefilename))
     self.assertEqual(expected, result)
Esempio n. 3
0
    def test_build_and_link_static_library(self):
        # Setup
        origdir = os.getcwd()
        self._tmpdir = tempfile.mkdtemp()

        # Mimic the build.sh and create the library in a 'mylib' subdirectory
        # Copy the sample source files into the test build location
        mylibdir = os.path.join(self._tmpdir, "mylib")
        shutil.copytree(os.path.join(uth.samplesdir(), "library/mylib"),
                        mylibdir)

        # Build the library
        temp_config_name = uth.create_temp_config(self._tmpdir)
        uth.create_temp_ct_conf(self._tmpdir,
                                defaultvariant=temp_config_name[:-5])
        argv = [
            "--exemarkers=main",
            "--testmarkers=unittest.hpp",
            "--config=" + temp_config_name,
            "--CTCACHE=None",
            "--static",
            os.path.join(self._tmpdir, "mylib/get_numbers.cpp"),
        ]
        os.chdir(mylibdir)
        uth.reset()
        ct.cake.main(argv)

        # Copy the main that will link to the library into the test build location
        relativepaths = ["library/main.cpp"]
        realpaths = [
            os.path.join(uth.samplesdir(), filename)
            for filename in relativepaths
        ]
        for ff in realpaths:
            shutil.copy2(ff, self._tmpdir)

        # Build the exe, linking agains the library
        argv = ["--config=" + temp_config_name, "--CTCACHE=None"] + realpaths
        os.chdir(self._tmpdir)
        uth.reset()
        ct.cake.main(argv)

        # Check that an executable got built for each cpp
        actual_exes = set()
        for root, dirs, files in os.walk(self._tmpdir):
            for ff in files:
                if ct.utils.isexecutable(os.path.join(root, ff)):
                    actual_exes.add(ff)

        expected_exes = {
            os.path.splitext(os.path.split(filename)[1])[0]
            for filename in relativepaths
        }
        self.assertSetEqual(expected_exes, actual_exes)

        # Cleanup
        os.chdir(origdir)
        shutil.rmtree(self._tmpdir, ignore_errors=True)
Esempio n. 4
0
 def test_implied_source(self):
     relativefilename = 'dottypaths/d2/d2.hpp'
     basename = os.path.splitext(relativefilename)[0]
     expected = os.path.join(uth.samplesdir(), basename + '.cpp')
     result = utils.implied_source(
         os.path.join(
             uth.samplesdir(),
             relativefilename))
     self.assertEqual(expected, result)
Esempio n. 5
0
    def test_build_and_link_static_library(self):
        # Setup
        origdir = os.getcwd()
        self._tmpdir = tempfile.mkdtemp()

        # Mimic the build.sh and create the library in a 'mylib' subdirectory
        # Copy the sample source files into the test build location
        mylibdir = os.path.join(self._tmpdir,'mylib')
        shutil.copytree( os.path.join(uth.samplesdir(), 'library/mylib')
                       , mylibdir)

        # Build the library
        temp_config_name = uth.create_temp_config(self._tmpdir)
        uth.create_temp_ct_conf(self._tmpdir,defaultvariant=temp_config_name[:-5])
        argv = [ '--exemarkers=main'
               , '--testmarkers=unittest.hpp'
               , '--config='+temp_config_name
               , '--CTCACHE=None'
               , '--static'
               , os.path.join(self._tmpdir,'mylib/get_numbers.cpp')
               ]
        os.chdir(mylibdir)
        uth.reset()
        ct.cake.main(argv)

        # Copy the main that will link to the library into the test build location
        relativepaths = ['library/main.cpp']
        realpaths = [os.path.join(uth.samplesdir(), filename)
                     for filename in relativepaths]
        for ff in realpaths:
            shutil.copy2(ff, self._tmpdir)

        # Build the exe, linking agains the library
        argv = ['--config='+temp_config_name,'--CTCACHE=None'] + realpaths
        os.chdir(self._tmpdir)
        uth.reset()
        ct.cake.main(argv)

        # Check that an executable got built for each cpp
        actual_exes = set()
        for root, dirs, files in os.walk(self._tmpdir):
            for ff in files:
                if ct.utils.isexecutable(os.path.join(root, ff)):
                    actual_exes.add(ff)

        expected_exes = {
            os.path.splitext(
                os.path.split(filename)[1])[0] for filename in relativepaths}
        self.assertSetEqual(expected_exes, actual_exes)

        # Cleanup
        os.chdir(origdir)
        shutil.rmtree(self._tmpdir, ignore_errors=True)
Esempio n. 6
0
 def test_cppdeps(self):
     tempdir = tempfile.mkdtemp()
     _reload_ct(tempdir)
     uth.reset()
     ct.cppdeps.main([os.path.join(uth.samplesdir(),'numbers/test_direct_include.cpp')])
     output = sys.stdout.getvalue().strip().split()
     expected_output = [
         os.path.join(uth.samplesdir(),"numbers/get_double.hpp"),
         os.path.join(uth.samplesdir(),"numbers/get_int.hpp"),
         os.path.join(uth.samplesdir(),"numbers/get_numbers.hpp")]
     self.assertEquals(expected_output.sort(), output.sort())
     shutil.rmtree(tempdir)
Esempio n. 7
0
 def test_cppdeps(self):
     tempdir = tempfile.mkdtemp()
     _reload_ct(tempdir)
     uth.reset()
     ct.cppdeps.main(
         [os.path.join(uth.samplesdir(), "numbers/test_direct_include.cpp")]
     )
     output = sys.stdout.getvalue().strip().split()
     expected_output = [
         os.path.join(uth.samplesdir(), "numbers/get_double.hpp"),
         os.path.join(uth.samplesdir(), "numbers/get_int.hpp"),
         os.path.join(uth.samplesdir(), "numbers/get_numbers.hpp"),
     ]
     self.assertEquals(expected_output.sort(), output.sort())
     shutil.rmtree(tempdir)
Esempio n. 8
0
def _test_library(static_dynamic):
    """ Manually specify what files to turn into the static (or dynamic)
        library and test linkage
    """
    samplesdir = uth.samplesdir()
    origdir = uth.ctdir()
    global _moduletmpdir
    if not _moduletmpdir or not os.path.exists(_moduletmpdir):
        _moduletmpdir = tempfile.mkdtemp()

    tempdir = _moduletmpdir
    os.chdir(tempdir)
    temp_config_name = ct.unittesthelper.create_temp_config(tempdir)

    exerelativepath = "numbers/test_library.cpp"
    librelativepaths = [
        "numbers/get_numbers.cpp",
        "numbers/get_int.cpp",
        "numbers/get_double.cpp",
    ]
    exerealpath = os.path.join(samplesdir, exerelativepath)
    librealpaths = [os.path.join(samplesdir, filename) for filename in librelativepaths]
    argv = ["--config=" + temp_config_name, exerealpath, static_dynamic] + librealpaths
    ct.makefile.main(argv)

    # Figure out the name of the makefile and run make
    filelist = os.listdir(".")
    makefilename = [ff for ff in filelist if ff.startswith("Makefile")]
    cmd = ["make", "-f"] + makefilename
    subprocess.check_output(cmd, universal_newlines=True)

    # Cleanup
    os.chdir(origdir)
    shutil.rmtree(tempdir, ignore_errors=True)
Esempio n. 9
0
    def _hunter_is_not_order_dependent(precall):
        samplesdir = uth.samplesdir()
        relativepaths = [
            'factory/test_factory.cpp',
            'numbers/test_direct_include.cpp',
            'simple/helloworld_c.c',
            'simple/helloworld_cpp.cpp',
            'simple/test_cflags.c']
        bulkpaths = [os.path.join(samplesdir, filename)
                     for filename in relativepaths]
        temp_config = ct.unittesthelper.create_temp_config()
        argv = [
            '--config',
            temp_config,
            '--include',
            uth.ctdir()] + bulkpaths
        cap = configargparse.getArgumentParser()
        ct.hunter.add_arguments(cap)
        args = ct.apptools.parseargs(cap, argv)
        headerdeps = ct.headerdeps.create(args)
        magicparser = ct.magicflags.create(args, headerdeps)
        hntr = ct.hunter.Hunter(args, headerdeps, magicparser)
        os.unlink(temp_config)

        realpath = os.path.join(samplesdir, 'dottypaths/dottypaths.cpp')
        if precall:
            result = hntr.required_source_files(realpath)
            return result
        else:
            for filename in bulkpaths:
                discard = hntr.required_source_files(filename)
            result = hntr.required_source_files(realpath)
            return result
Esempio n. 10
0
    def test_no_git_root(self):
        origdir = self._setup_and_chdir_temp_dir()

        # Copy a known cpp file to a non-git directory and compile using cake
        relativepaths = ["simple/helloworld_cpp.cpp"]
        realpaths = [
            os.path.join(uth.samplesdir(), filename)
            for filename in relativepaths
        ]
        for ff in realpaths:
            shutil.copy2(ff, self._tmpdir)

        self._config_name = uth.create_temp_config(self._tmpdir)
        uth.create_temp_ct_conf(
            tempdir=self._tmpdir,
            defaultvariant=os.path.basename(self._config_name)[:-5],
        )
        self._call_ct_cake()

        # Check that an executable got built for each cpp
        actual_exes = set()
        for root, dirs, files in os.walk(self._tmpdir):
            for ff in files:
                if ct.utils.isexecutable(os.path.join(root, ff)):
                    actual_exes.add(ff)

        expected_exes = {
            os.path.splitext(os.path.split(filename)[1])[0]
            for filename in relativepaths
        }
        self.assertSetEqual(expected_exes, actual_exes)

        # Cleanup
        os.chdir(origdir)
        shutil.rmtree(self._tmpdir, ignore_errors=True)
Esempio n. 11
0
    def test_no_git_root(self):
        origdir = self._setup_and_chdir_temp_dir()

        # Copy a known cpp file to a non-git directory and compile using cake
        relativepaths = ['simple/helloworld_cpp.cpp']
        realpaths = [os.path.join(uth.samplesdir(), filename)
                     for filename in relativepaths]
        for ff in realpaths:
            shutil.copy2(ff, self._tmpdir)

        self._config_name = uth.create_temp_config(self._tmpdir) 
        uth.create_temp_ct_conf(tempdir=self._tmpdir,defaultvariant=os.path.basename(self._config_name)[:-5])
        self._call_ct_cake()
        
        # Check that an executable got built for each cpp
        actual_exes = set()
        for root, dirs, files in os.walk(self._tmpdir):
            for ff in files:
                if ct.utils.isexecutable(os.path.join(root, ff)):
                    actual_exes.add(ff)

        expected_exes = {
            os.path.splitext(
                os.path.split(filename)[1])[0] for filename in relativepaths}
        self.assertSetEqual(expected_exes, actual_exes)

        # Cleanup
        os.chdir(origdir)
        shutil.rmtree(self._tmpdir, ignore_errors=True)
Esempio n. 12
0
    def _hunter_is_not_order_dependent(precall):
        samplesdir = uth.samplesdir()
        relativepaths = [
            "factory/test_factory.cpp",
            "numbers/test_direct_include.cpp",
            "simple/helloworld_c.c",
            "simple/helloworld_cpp.cpp",
            "simple/test_cflags.c",
        ]
        bulkpaths = [
            os.path.join(samplesdir, filename) for filename in relativepaths
        ]
        temp_config = ct.unittesthelper.create_temp_config()
        argv = ["--config", temp_config, "--include", uth.ctdir()]
        cap = configargparse.getArgumentParser()
        ct.hunter.add_arguments(cap)
        args = ct.apptools.parseargs(cap, argv)
        headerdeps = ct.headerdeps.create(args)
        magicparser = ct.magicflags.create(args, headerdeps)
        hntr = ct.hunter.Hunter(args, headerdeps, magicparser)
        os.unlink(temp_config)

        realpath = os.path.join(samplesdir, "dottypaths/dottypaths.cpp")
        if precall:
            result = hntr.required_source_files(realpath)
            return result
        else:
            for filename in bulkpaths:
                discard = hntr.required_source_files(filename)
            result = hntr.required_source_files(realpath)
            return result
Esempio n. 13
0
    def test_hunter_follows_source_files_from_header(self):
        origcache = ct.dirnamer.user_cache_dir('ct')
        tempdir = tempfile.mkdtemp()
        _reload_ct(tempdir)
        
        temp_config = ct.unittesthelper.create_temp_config()
        argv = [
            '-c',
            temp_config,
            '--include',
            uth.ctdir()]
        cap = configargparse.getArgumentParser()
        ct.hunter.add_arguments(cap)
        args = ct.apptools.parseargs(cap, argv)
        headerdeps = ct.headerdeps.create(args)
        magicparser = ct.magicflags.create(args, headerdeps)
        hntr = ct.hunter.Hunter(args, headerdeps, magicparser)

        relativepath = 'factory/widget_factory.hpp'
        realpath = os.path.join(uth.samplesdir(), relativepath)
        filesfromheader = hntr.required_source_files(realpath)
        filesfromsource = hntr.required_source_files(
            ct.utils.implied_source(realpath))
        self.assertSetEqual(filesfromheader, filesfromsource)

        # Cleanup
        os.unlink(temp_config)
        shutil.rmtree(tempdir)
        _reload_ct(origcache)
Esempio n. 14
0
    def test_hunter_follows_source_files_from_header(self):
        origcache = ct.dirnamer.user_cache_dir("ct")
        tempdir = tempfile.mkdtemp()
        _reload_ct(tempdir)

        temp_config = ct.unittesthelper.create_temp_config()
        argv = ["-c", temp_config, "--include", uth.ctdir()]
        cap = configargparse.getArgumentParser()
        ct.hunter.add_arguments(cap)
        args = ct.apptools.parseargs(cap, argv)
        headerdeps = ct.headerdeps.create(args)
        magicparser = ct.magicflags.create(args, headerdeps)
        hntr = ct.hunter.Hunter(args, headerdeps, magicparser)

        relativepath = "factory/widget_factory.hpp"
        realpath = os.path.join(uth.samplesdir(), relativepath)
        filesfromheader = hntr.required_source_files(realpath)
        filesfromsource = hntr.required_source_files(
            ct.utils.implied_source(realpath))
        self.assertSetEqual(filesfromheader, filesfromsource)

        # Cleanup
        os.unlink(temp_config)
        shutil.rmtree(tempdir)
        _reload_ct(origcache)
Esempio n. 15
0
 def test_direct_and_cpp_generate_same_results(self):
     filenames = [
         "factory/test_factory.cpp",
         "numbers/test_direct_include.cpp",
         "dottypaths/dottypaths.cpp",
     ]
     for filename in filenames:
         self._direct_cpp_tester(os.path.join(uth.samplesdir(), filename))
Esempio n. 16
0
    def test_samples(self):
        relativeexpectedexes = {
            "simple/helloworld_c.c",
            "simple/helloworld_cpp.cpp",
            "dottypaths/dottypaths.cpp",
            "library/main.cpp",
            "lotsofmagic/lotsofmagic.cpp",
            "magicsourceinheader/main.cpp",
            "magicinclude/main.cpp",
            "movingheaders/main.cpp",
        }
        relativeexpectedtests = {
            "cross_platform/test_source.cpp",
            "factory/test_factory.cpp",
            "numbers/test_direct_include.cpp",
            "numbers/test_library.cpp",
            "simple/test_cflags.c",
        }

        expectedexes = {
            os.path.realpath(os.path.join(uth.samplesdir(), exe))
            for exe in relativeexpectedexes
        }
        expectedtests = {
            os.path.realpath(os.path.join(uth.samplesdir(), tt))
            for tt in relativeexpectedtests
        }
        config_files = ct.configutils.config_files_from_variant(
            exedir=uth.cakedir(), argv=[])
        cap = configargparse.getArgumentParser(
            description="TestFindTargetsModule",
            formatter_class=configargparse.ArgumentDefaultsHelpFormatter,
            default_config_files=config_files,
            args_for_setting_config_path=["-c", "--config"],
            ignore_unknown_config_file_keys=True,
        )
        ct.findtargets.add_arguments(cap)
        args = ct.apptools.parseargs(cap, argv=["--shorten"])
        findtargets = ct.findtargets.FindTargets(args, exedir=uth.cakedir())
        executabletargets, testtargets = findtargets(path=uth.cakedir())
        self.assertSetEqual(expectedexes, set(executabletargets))
        self.assertSetEqual(expectedtests, set(testtargets))
Esempio n. 17
0
    def test_moving_headers(self):
        # The concept of this test is to check that ct-cake copes with header files being changed directory

        # Setup
        origdir = os.getcwd()
        os.mkdir(os.path.join(self._tmpdir, "subdir"))

        # Copy the movingheaders test files to the temp directory and compile using cake
        relativepaths = [
            "movingheaders/main.cpp", "movingheaders/someheader.hpp"
        ]
        realpaths = [
            os.path.join(uth.samplesdir(), filename)
            for filename in relativepaths
        ]
        for ff in realpaths:
            shutil.copy2(ff, self._tmpdir)

        os.chdir(self._tmpdir)
        temp_config_name = ct.unittesthelper.create_temp_config(self._tmpdir)
        argv = [
            "--exemarkers=main",
            "--testmarkers=unittest.hpp",
            "--CTCACHE=" + os.path.join(self._tmpdir, "ctcache"),
            "--quiet",
            "--auto",
            "--include=subdir",
            "--config=" + temp_config_name,
        ]
        uth.reset()
        ct.cake.main(argv)

        self._verify_one_exe_per_main(relativepaths)

        # Now move the header file to "subdir"  since it is already included in the path, all should be well
        os.rename(
            os.path.join(self._tmpdir, "someheader.hpp"),
            os.path.join(self._tmpdir, "subdir/someheader.hpp"),
        )
        shutil.rmtree(os.path.join(self._tmpdir, "bin"), ignore_errors=True)
        uth.reset()
        ct.cake.main(argv)

        self._verify_one_exe_per_main(relativepaths)

        # Cleanup
        os.chdir(origdir)
        shutil.rmtree(self._tmpdir, ignore_errors=True)
Esempio n. 18
0
    def test_SOURCE_cpp(self):
        origdir = os.getcwd()
        tempdir = tempfile.mkdtemp()
        os.chdir(tempdir)

        relativepath = 'cross_platform/cross_platform.cpp'
        samplesdir = uth.samplesdir()
        realpath = os.path.join(samplesdir, relativepath)
        magicparser = self._createmagicparser(['--magic', 'cpp'],tempdir=tempdir)
        # magicparser._headerdeps.process(realpath)
        self.assertSetEqual(
            set(magicparser.parse(realpath).get('SOURCE')),
            {os.path.join(samplesdir,'cross_platform/cross_platform_lin.cpp')})

        os.chdir(origdir)
        shutil.rmtree(tempdir, ignore_errors=True)
Esempio n. 19
0
    def test_parsing_CFLAGS(self):
        origdir = os.getcwd()
        tempdir = tempfile.mkdtemp()
        os.chdir(tempdir)

        relativepath = 'simple/test_cflags.c'
        samplesdir = uth.samplesdir()
        realpath = os.path.join(samplesdir, relativepath)
        magicparser = self._createmagicparser(tempdir=tempdir)
        # magicparser._headerdeps.process(realpath)
        self.assertSetEqual(
            set(magicparser.parse(realpath).get('CFLAGS')),
            set(['-std=gnu99']))

        os.chdir(origdir)
        shutil.rmtree(tempdir, ignore_errors=True)
Esempio n. 20
0
    def test_parsing_CFLAGS(self):
        origdir = os.getcwd()
        tempdir = tempfile.mkdtemp()
        os.chdir(tempdir)

        relativepath = "simple/test_cflags.c"
        samplesdir = uth.samplesdir()
        realpath = os.path.join(samplesdir, relativepath)
        magicparser = self._createmagicparser(tempdir=tempdir)
        # magicparser._headerdeps.process(realpath)
        self.assertSetEqual(
            set(magicparser.parse(realpath).get("CFLAGS")), set(["-std=gnu99"])
        )

        os.chdir(origdir)
        shutil.rmtree(tempdir, ignore_errors=True)
Esempio n. 21
0
    def test_SOURCE_cpp(self):
        origdir = os.getcwd()
        tempdir = tempfile.mkdtemp()
        os.chdir(tempdir)

        relativepath = "cross_platform/cross_platform.cpp"
        samplesdir = uth.samplesdir()
        realpath = os.path.join(samplesdir, relativepath)
        magicparser = self._createmagicparser(["--magic", "cpp"], tempdir=tempdir)
        # magicparser._headerdeps.process(realpath)
        self.assertSetEqual(
            set(magicparser.parse(realpath).get("SOURCE")),
            {os.path.join(samplesdir, "cross_platform/cross_platform_lin.cpp")},
        )

        os.chdir(origdir)
        shutil.rmtree(tempdir, ignore_errors=True)
Esempio n. 22
0
    def test_SOURCE_in_header(self):
        origdir = os.getcwd()
        tempdir = tempfile.mkdtemp()
        os.chdir(tempdir)

        relativepath = 'magicsourceinheader/main.cpp'
        samplesdir = uth.samplesdir()
        realpath = os.path.join(samplesdir, relativepath)
        magicparser = self._createmagicparser(['--magic', 'cpp'],tempdir=tempdir)
        expected = {
            'LDFLAGS': OrderedSet(
                ['-lm']),
            'SOURCE': OrderedSet(
                [os.path.join(samplesdir,'magicsourceinheader/include_dir/sub_dir/the_code_lin.cpp')])}
        self.assertEqual(magicparser.parse(realpath), expected)

        os.chdir(origdir)
        shutil.rmtree(tempdir, ignore_errors=True)
Esempio n. 23
0
    def test_lotsofmagic(self):
        origdir = os.getcwd()
        tempdir = tempfile.mkdtemp()
        os.chdir(tempdir)

        relativepath = 'lotsofmagic/lotsofmagic.cpp'
        samplesdir = uth.samplesdir()
        realpath = os.path.join(samplesdir, relativepath)
        magicparser = self._createmagicparser(['--magic', 'cpp'],tempdir=tempdir)

        expected = {
            'LDFLAGS': {'-lm'},
            'F1': {'1'},
            'LINKFLAGS': {'-lpcap'},
            'F2': {'2'},
            'F3': {'3'}}
        self.assertEqual(magicparser.parse(realpath), expected)

        os.chdir(origdir)
        shutil.rmtree(tempdir, ignore_errors=True)
Esempio n. 24
0
    def test_lotsofmagic(self):
        origdir = os.getcwd()
        tempdir = tempfile.mkdtemp()
        os.chdir(tempdir)

        relativepath = "lotsofmagic/lotsofmagic.cpp"
        samplesdir = uth.samplesdir()
        realpath = os.path.join(samplesdir, relativepath)
        magicparser = self._createmagicparser(["--magic", "cpp"], tempdir=tempdir)

        expected = {
            "LDFLAGS": {"-lm"},
            "F1": {"1"},
            "LINKFLAGS": {"-lpcap"},
            "F2": {"2"},
            "F3": {"3"},
        }
        self.assertEqual(magicparser.parse(realpath), expected)

        os.chdir(origdir)
        shutil.rmtree(tempdir, ignore_errors=True)
Esempio n. 25
0
    def _direct_and_cpp_generate_same_results_ex(self, extraargs=None):
        """ Test that HeaderTree and HeaderDependencies give the same results.
            Rather than polluting the real ct cache, use temporary cache
            directories.
        """
        if extraargs is None:
            extraargs = []

        origcache = ct.dirnamer.user_cache_dir()
        tempdir = tempfile.mkdtemp()
        samplesdir = uth.samplesdir()
        relativepaths = [
            "factory/test_factory.cpp",
            "numbers/test_direct_include.cpp",
            "simple/helloworld_c.c",
            "simple/helloworld_cpp.cpp",
            "simple/test_cflags.c",
        ]
        realpaths = [
            os.path.join(samplesdir, filename) for filename in relativepaths
        ]

        directcache, config1, directresults = _generatecache(
            tempdir, "direct", realpaths, extraargs)
        cppcache, config2, cppresults = _generatecache(tempdir, "cpp",
                                                       realpaths, extraargs)

        # Check the returned python sets are the same regardless of methodology
        # used to create
        self.assertSetEqual(directresults, cppresults)

        # Check the on-disk caches are the same
        comparator = filecmp.dircmp(directcache, cppcache)
        self.assertEqual(len(comparator.diff_files), 0)

        # Cleanup
        os.unlink(config1)
        os.unlink(config2)
        shutil.rmtree(tempdir)
        _reload_ct(origcache)
Esempio n. 26
0
def _test_library(static_dynamic):
    """ Manually specify what files to turn into the static (or dynamic)
        library and test linkage
    """
    samplesdir = uth.samplesdir()
    origdir = uth.ctdir()
    global _moduletmpdir
    if not _moduletmpdir or not os.path.exists(_moduletmpdir) :
        _moduletmpdir = tempfile.mkdtemp()
    
    tempdir = _moduletmpdir
    os.chdir(tempdir)
    temp_config_name = ct.unittesthelper.create_temp_config(tempdir)

    exerelativepath = 'numbers/test_library.cpp'
    librelativepaths = [
        'numbers/get_numbers.cpp',
        'numbers/get_int.cpp',
        'numbers/get_double.cpp']
    exerealpath = os.path.join(samplesdir, exerelativepath)
    librealpaths = [
        os.path.join(
            samplesdir,
            filename) for filename in librelativepaths]
    argv = [
        '--config='+temp_config_name,
        exerealpath,
        static_dynamic] + librealpaths
    ct.makefile.main(argv)

    # Figure out the name of the makefile and run make
    filelist = os.listdir('.')
    makefilename = [ff for ff in filelist if ff.startswith('Makefile')]
    cmd = ['make', '-f'] + makefilename
    subprocess.check_output(cmd, universal_newlines=True)

    # Cleanup
    os.chdir(origdir)
    shutil.rmtree(tempdir, ignore_errors=True)
Esempio n. 27
0
    def test_moving_headers(self):
        # The concept of this test is to check that ct-cake copes with header files being changed directory

        # Setup
        origdir = os.getcwd()
        os.mkdir(os.path.join(self._tmpdir,'subdir'))

        # Copy the movingheaders test files to the temp directory and compile using cake
        relativepaths = ['movingheaders/main.cpp', 'movingheaders/someheader.hpp']
        realpaths = [os.path.join(uth.samplesdir(), filename) for filename in relativepaths]        
        for ff in realpaths:
            shutil.copy2(ff, self._tmpdir)

        os.chdir(self._tmpdir)
        temp_config_name = ct.unittesthelper.create_temp_config(self._tmpdir)
        argv =  ['--exemarkers=main'
                ,'--testmarkers=unittest.hpp'
                , '--CTCACHE='+os.path.join(self._tmpdir,'ctcache')
                , '--quiet'
                , '--auto'
                ,'--include=subdir'
                ,'--config='+temp_config_name ]
        uth.reset()
        ct.cake.main(argv)
        
        self._verify_one_exe_per_main(relativepaths)


        # Now move the header file to "subdir"  since it is already included in the path, all should be well
        os.rename(os.path.join(self._tmpdir, 'someheader.hpp'), os.path.join(self._tmpdir, 'subdir/someheader.hpp'));
        shutil.rmtree(os.path.join(self._tmpdir, 'bin'), ignore_errors=True);
        uth.reset()
        ct.cake.main(argv)
        
        self._verify_one_exe_per_main(relativepaths)

        # Cleanup
        os.chdir(origdir)
        shutil.rmtree(self._tmpdir, ignore_errors=True)
Esempio n. 28
0
    def test_no_git_root(self):
        # Setup
        origdir = os.getcwd()
        self._tmpdir = tempfile.mkdtemp()
        try:
            os.mkdir(self._tmpdir)
        except OSError:
            pass
        print(self._tmpdir)
        os.chdir(self._tmpdir)

        # Copy a known cpp file to a non-git directory and compile using cake
        relativepaths = ['simple/helloworld_cpp.cpp']
        realpaths = [os.path.join(uth.samplesdir(), filename)
                     for filename in relativepaths]
        for ff in realpaths:
            shutil.copy2(ff, self._tmpdir)

        temp_config_name = ct.unittesthelper.create_temp_config(self._tmpdir)
        argv = ['--exemarkers=main','--testmarkers=unittest.hpp','--auto','--config='+temp_config_name ]
        ct.cake.main(argv)
        
        # Check that an executable got built for each cpp
        actual_exes = set()
        for root, dirs, files in os.walk(self._tmpdir):
            for ff in files:
                if ct.utils.isexecutable(os.path.join(root, ff)):
                    actual_exes.add(ff)

        expected_exes = {
            os.path.splitext(
                os.path.split(filename)[1])[0] for filename in relativepaths}
        self.assertSetEqual(expected_exes, actual_exes)

        # Cleanup
        os.chdir(origdir)
        shutil.rmtree(self._tmpdir, ignore_errors=True)
Esempio n. 29
0
    def _create_makefile_and_make(self, tempdir):
        origdir = uth.ctdir()
        print("origdir="+origdir)
        print(tempdir)
        samplesdir = uth.samplesdir()
        print("samplesdir="+samplesdir)
        os.chdir(tempdir)
        temp_config_name = ct.unittesthelper.create_temp_config(tempdir)
        relativepaths = [
            'numbers/test_direct_include.cpp',
            'factory/test_factory.cpp',
            'simple/helloworld_c.c',
            'simple/helloworld_cpp.cpp',
            'dottypaths/dottypaths.cpp']
        realpaths = [os.path.join(samplesdir, filename)
                     for filename in relativepaths]
        ct.makefile.main(
            ['--config='+temp_config_name] + realpaths)

        filelist = os.listdir('.')
        makefilename = [ff for ff in filelist if ff.startswith('Makefile')]
        cmd = ['make', '-f'] + makefilename
        subprocess.check_output(cmd, universal_newlines=True)

        # Check that an executable got built for each cpp
        actual_exes = set()
        for root, dirs, files in os.walk(tempdir):
            for ff in files:
                if ct.utils.isexecutable(os.path.join(root, ff)):
                    actual_exes.add(ff)
                    print(root + " " + ff)

        expected_exes = {
            os.path.splitext(
                os.path.split(filename)[1])[0] for filename in relativepaths}
        self.assertSetEqual(expected_exes, actual_exes)
        os.chdir(origdir)
Esempio n. 30
0
    def test_magicinclude(self):
        # This test is to ensure that the //#INCLUDE magic flag
        # works to pick up subdir/important.hpp
        # and that the --include=subdir2 subdir3
        # works to pick up subdir2/important2.hpp and subdir3/important3.hpp

        origdir = os.getcwd()

        # Copy the magicinclude test files to the temp directory and compile
        # using cake
        tmpmagicinclude = os.path.join(self._tmpdir, "magicinclude")
        shutil.copytree(os.path.join(uth.samplesdir(), "magicinclude"),
                        tmpmagicinclude)
        os.chdir(tmpmagicinclude)

        temp_config_name = ct.unittesthelper.create_temp_config(
            tmpmagicinclude)
        argv = [
            "--exemarkers=main",
            "--testmarkers=unittest.hpp",
            "--CTCACHE=None",
            "--quiet",
            "--include=subdir2",
            "--include=subdir3",
            "--auto",
            "--config=" + temp_config_name,
        ]

        uth.reset()
        ct.cake.main(argv)

        relativepaths = ["magicinclude/main.cpp"]
        self._verify_one_exe_per_main(relativepaths)

        # Cleanup
        os.chdir(origdir)
        shutil.rmtree(self._tmpdir, ignore_errors=True)
Esempio n. 31
0
    def _create_makefile_and_make(self, tempdir):
        origdir = uth.ctdir()
        print("origdir=" + origdir)
        print(tempdir)
        samplesdir = uth.samplesdir()
        print("samplesdir=" + samplesdir)
        os.chdir(tempdir)
        temp_config_name = ct.unittesthelper.create_temp_config(tempdir)
        relativepaths = [
            "numbers/test_direct_include.cpp",
            "factory/test_factory.cpp",
            "simple/helloworld_c.c",
            "simple/helloworld_cpp.cpp",
            "dottypaths/dottypaths.cpp",
        ]
        realpaths = [os.path.join(samplesdir, filename) for filename in relativepaths]
        ct.makefile.main(["--config=" + temp_config_name] + realpaths)

        filelist = os.listdir(".")
        makefilename = [ff for ff in filelist if ff.startswith("Makefile")]
        cmd = ["make", "-f"] + makefilename
        subprocess.check_output(cmd, universal_newlines=True)

        # Check that an executable got built for each cpp
        actual_exes = set()
        for root, dirs, files in os.walk(tempdir):
            for ff in files:
                if ct.utils.isexecutable(os.path.join(root, ff)):
                    actual_exes.add(ff)
                    print(root + " " + ff)

        expected_exes = {
            os.path.splitext(os.path.split(filename)[1])[0]
            for filename in relativepaths
        }
        self.assertSetEqual(expected_exes, actual_exes)
        os.chdir(origdir)
Esempio n. 32
0
    def test_SOURCE_in_header(self):
        origdir = os.getcwd()
        tempdir = tempfile.mkdtemp()
        os.chdir(tempdir)

        relativepath = "magicsourceinheader/main.cpp"
        samplesdir = uth.samplesdir()
        realpath = os.path.join(samplesdir, relativepath)
        magicparser = self._createmagicparser(["--magic", "cpp"], tempdir=tempdir)
        expected = {
            "LDFLAGS": OrderedSet(["-lm"]),
            "SOURCE": OrderedSet(
                [
                    os.path.join(
                        samplesdir,
                        "magicsourceinheader/include_dir/sub_dir/the_code_lin.cpp",
                    )
                ]
            ),
        }
        self.assertEqual(magicparser.parse(realpath), expected)

        os.chdir(origdir)
        shutil.rmtree(tempdir, ignore_errors=True)
Esempio n. 33
0
    def test_magicinclude(self):
        # This test is to ensure that the //#INCLUDE magic flag 
        # works to pick up subdir/important.hpp
        # and that the --include=subdir2 subdir3 
        # works to pick up subdir2/important2.hpp and subdir3/important3.hpp

        origdir = os.getcwd()

        # Copy the magicinclude test files to the temp directory and compile
        # using cake
        tmpmagicinclude = os.path.join(self._tmpdir, 'magicinclude')
        shutil.copytree( os.path.join(uth.samplesdir(), 'magicinclude')
                       , tmpmagicinclude)
        os.chdir(tmpmagicinclude)

        temp_config_name = ct.unittesthelper.create_temp_config(tmpmagicinclude)
        argv = [
            '--exemarkers=main',
            '--testmarkers=unittest.hpp',
            '--CTCACHE=None',
            '--quiet',
            '--include=subdir2',
            'subdir3',
            '--auto',
            '--config=' +
            temp_config_name]

        uth.reset()
        ct.cake.main(argv)

        relativepaths = ['magicinclude/main.cpp']
        self._verify_one_exe_per_main(relativepaths)

        # Cleanup
        os.chdir(origdir)
        shutil.rmtree(self._tmpdir, ignore_errors=True)