Ejemplo n.º 1
0
 def setUp(self):
     uth.reset()
     cap = configargparse.getArgumentParser(
         description='Configargparser in test code',
         formatter_class=configargparse.ArgumentDefaultsHelpFormatter,
         args_for_setting_config_path=["-c","--config"],
         ignore_unknown_config_file_keys=False)
Ejemplo n.º 2
0
 def setUp(self):
     uth.reset()
     cap = configargparse.getArgumentParser(
         description="Configargparser in test code",
         formatter_class=configargparse.ArgumentDefaultsHelpFormatter,
         args_for_setting_config_path=["-c", "--config"],
         ignore_unknown_config_file_keys=False,
     )
Ejemplo 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)
Ejemplo n.º 4
0
    def setUp(self):
        uth.reset()
        global _moduletmpdir
        if not _moduletmpdir or not os.path.exists(_moduletmpdir) :
            _moduletmpdir = tempfile.mkdtemp()

        cap = configargparse.getArgumentParser(
            description='Configargparser in test code',
            formatter_class=configargparse.ArgumentDefaultsHelpFormatter,
            args_for_setting_config_path=["-c","--config"],
            ignore_unknown_config_file_keys=False)
Ejemplo 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)
Ejemplo n.º 6
0
    def setUp(self):
        uth.reset()
        global _moduletmpdir
        if not _moduletmpdir or not os.path.exists(_moduletmpdir):
            _moduletmpdir = tempfile.mkdtemp()

        cap = configargparse.getArgumentParser(
            description="Configargparser in test code",
            formatter_class=configargparse.ArgumentDefaultsHelpFormatter,
            args_for_setting_config_path=["-c", "--config"],
            ignore_unknown_config_file_keys=False,
        )
Ejemplo 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)
Ejemplo n.º 8
0
 def setUp(self):
     try: 
         if self._tmpdir is not None:
             shutil.rmtree(self._tmpdir, ignore_errors=True)
     except AttributeError:
         pass
     self._tmpdir = tempfile.mkdtemp()
     uth.reset()
     cap = configargparse.getArgumentParser(
     description='Configargparser in test code',
     formatter_class=configargparse.ArgumentDefaultsHelpFormatter,
     args_for_setting_config_path=["-c","--config"],
     ignore_unknown_config_file_keys=False)
Ejemplo n.º 9
0
 def setUp(self):
     try:
         if self._tmpdir is not None:
             shutil.rmtree(self._tmpdir, ignore_errors=True)
     except AttributeError:
         pass
     self._tmpdir = tempfile.mkdtemp()
     uth.reset()
     cap = configargparse.getArgumentParser(
         description="Configargparser in test code",
         formatter_class=configargparse.ArgumentDefaultsHelpFormatter,
         args_for_setting_config_path=["-c", "--config"],
         ignore_unknown_config_file_keys=False,
     )
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)
Ejemplo n.º 13
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)
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
 def _call_ct_cake(self, extraargv=[], cache_home="None"):
     assert cache_home is not None  # Note object None is not string 'None'
     uth.reset()
     ct.cake.main(self._create_argv(cache_home) + extraargv)
Ejemplo n.º 16
0
 def tearDown(self):
     shutil.rmtree(_moduletmpdir, ignore_errors=True)
     uth.reset()
Ejemplo n.º 17
0
 def tearDown(self):
     shutil.rmtree(_moduletmpdir, ignore_errors=True)
     uth.reset()
Ejemplo n.º 18
0
 def tearDown(self):
     uth.reset()
Ejemplo n.º 19
0
 def setUp(self):
     uth.reset()
     self._tmpdir = None
Ejemplo n.º 20
0
 def _call_ct_cake(self, extraargv=[], cache_home='None'): 
     assert(cache_home is not None)  # Note object None is not string 'None'
     uth.reset()
     ct.cake.main(self._create_argv(cache_home) + extraargv)
Ejemplo n.º 21
0
 def setUp(self):
     uth.reset()
     self._tmpdir = None
Ejemplo n.º 22
0
 def tearDown(self):
     uth.reset()
     if self._tmpdir and os.path.exists(self._tmpdir):
         shutil.rmtree(self._tmpdir, ignore_errors=True)
Ejemplo n.º 23
0
 def setUp(self):
     uth.reset()
Ejemplo n.º 24
0
 def setUp(self):
     uth.reset()
Ejemplo n.º 25
0
 def tearDown(self):
     uth.reset()
Ejemplo n.º 26
0
 def tearDown(self):
     uth.reset()
     if self._tmpdir and os.path.exists(self._tmpdir):
         shutil.rmtree(self._tmpdir, ignore_errors=True)