Exemplo n.º 1
0
    def test_expand_word_jbos(self):
        p = Placeholder('files')
        zero = AttrDict(files=[])
        one = AttrDict(files=[literal('foo')])
        two = AttrDict(files=[literal('foo'), literal('bar')])
        foo = jbos('{', literal('foo'), '}')
        bar = jbos('{', literal('bar'), '}')

        j = '{' + p + '}'
        self.assertEqual(Placeholder.expand_word(j, zero), [])
        self.assertEqual(Placeholder.expand_word(j, one), [foo])
        self.assertEqual(Placeholder.expand_word(j, two), [foo, bar])

        j = '{' + p[0] + '}'
        with self.assertRaises(IndexError):
            Placeholder.expand_word(j, zero)
        self.assertEqual(Placeholder.expand_word(j, one), [foo])
        self.assertEqual(Placeholder.expand_word(j, two), [foo])

        j = '{' + p[0:1] + '}'
        self.assertEqual(Placeholder.expand_word(j, zero), [])
        self.assertEqual(Placeholder.expand_word(j, one), [foo])
        self.assertEqual(Placeholder.expand_word(j, two), [foo])

        j = jbos('foo')
        self.assertEqual(Placeholder.expand_word(j, zero), [j])
        self.assertEqual(Placeholder.expand_word(j, one), [j])
        self.assertEqual(Placeholder.expand_word(j, two), [j])

        with self.assertRaises(ValueError):
            Placeholder.expand_word(p + p, zero)
Exemplo n.º 2
0
 def test_concat_path(self):
     self.assertEqual(
         Variable('foo') + path.Path('bar'),
         safe_str.jbos(safe_str.literal('$(foo)'), path.Path('bar')))
     self.assertEqual(
         path.Path('foo') + Variable('bar'),
         safe_str.jbos(path.Path('foo'), safe_str.literal('$(bar)')))
Exemplo n.º 3
0
 def test_concat_path(self):
     self.assertEqual(
         Pattern('%.c') + path.Path('bar'),
         safe_str.jbos(safe_str.literal('%'), '.c', path.Path('bar')))
     self.assertEqual(
         path.Path('foo') + Pattern('%.h'),
         safe_str.jbos(path.Path('foo'), safe_str.literal('%'), '.h'))
Exemplo n.º 4
0
 def test_concat_str(self):
     self.assertEqual(Variable('foo') + 'bar', safe_str.jbos(
         safe_str.literal('${foo}'), 'bar'
     ))
     self.assertEqual('foo' + Variable('bar'), safe_str.jbos(
         'foo', safe_str.literal('${bar}')
     ))
Exemplo n.º 5
0
 def test_concat_str(self):
     self.assertEqual(Pattern('%.c') + 'bar', safe_str.jbos(
         safe_str.literal('%'), '.cbar'
     ))
     self.assertEqual('foo' + Pattern('%.h'), safe_str.jbos(
         'foo', safe_str.literal('%'), '.h'
     ))
Exemplo n.º 6
0
 def test_concat_var(self):
     self.assertEqual(
         Variable('foo') + Variable('bar'),
         safe_str.jbos(safe_str.literal('$(foo)'),
                       safe_str.literal('$(bar)')))
     self.assertEqual(
         Variable('foo', True) + Variable('bar'),
         safe_str.jbos(safe_str.literal("'$(foo)'"),
                       safe_str.literal('$(bar)')))
Exemplo n.º 7
0
 def test_concat_var(self):
     self.assertEqual(
         Function('foo', '1', '2') + Function('bar', '3', '4'),
         safe_str.jbos(safe_str.literal('$(foo 1,2)'),
                       safe_str.literal('$(bar 3,4)')))
     self.assertEqual(
         Function('foo', '1', '2', quoted=True) + Function('bar', '3', '4'),
         safe_str.jbos(safe_str.literal("'$(foo 1,2)'"),
                       safe_str.literal('$(bar 3,4)')))
Exemplo n.º 8
0
    def test_single(self):
        env = {'NAME': 'VALUE'}
        self.assertEqual(
            posix.local_env(env, 'cmd'),
            shell_list([
                jbos('NAME', shell_literal('='), 'VALUE'),
                shell_literal('cmd')
            ]))

        self.assertEqual(
            posix.local_env(env, ['cmd']),
            shell_list([jbos('NAME', shell_literal('='), 'VALUE'), 'cmd']))
Exemplo n.º 9
0
    def test_concat_str(self):
        self.assertEqual(
            Function('fn', '1', '2') + 'foo',
            safe_str.jbos(safe_str.literal('$(fn 1,2)'), 'foo'))
        self.assertEqual('foo' + Function('fn', '1', '2'),
                         safe_str.jbos('foo', safe_str.literal('$(fn 1,2)')))

        self.assertEqual(
            Function('fn', '1', '2', quoted=True) + 'foo',
            safe_str.jbos(safe_str.literal("'$(fn 1,2)'"), 'foo'))
        self.assertEqual('foo' + Function('fn', '1', '2', quoted=True),
                         safe_str.jbos('foo', safe_str.literal("'$(fn 1,2)'")))
Exemplo n.º 10
0
 def test_env_vars(self):
     self._init_setenv()
     env = {'FOO': 'foo'}
     self.assertEqual(self.setenv(env, ['echo', 'hi']), [
         self.setenv,
         jbos('FOO', shell_literal('='), 'foo'), '--', 'echo', 'hi'
     ])
     self.assertEqual(
         self.setenv(env, 'echo hi'),
         shell_list([
             self.setenv,
             jbos('FOO', shell_literal('='), 'foo'), '--',
             shell_literal('echo hi')
         ]))
Exemplo n.º 11
0
    def test_concat_path(self):
        self.assertEqual(
            Function('fn', '1', '2') + path.Path('foo'),
            safe_str.jbos(safe_str.literal('$(fn 1,2)'), path.Path('foo')))
        self.assertEqual(
            path.Path('foo') + Function('fn', '1', '2'),
            safe_str.jbos(path.Path('foo'), safe_str.literal('$(fn 1,2)')))

        self.assertEqual(
            Function('fn', '1', '2', quoted=True) + path.Path('foo'),
            safe_str.jbos(safe_str.literal("'$(fn 1,2)'"), path.Path('foo')))
        self.assertEqual(
            path.Path('foo') + Function('fn', '1', '2', quoted=True),
            safe_str.jbos(path.Path('foo'), safe_str.literal("'$(fn 1,2)'")))
Exemplo n.º 12
0
    def test_multiple(self):
        env = OrderedDict((('FOO', 'oof'), ('BAR', 'rab')))
        self.assertEqual(
            posix.local_env(env, 'cmd'),
            shell_list([
                jbos('FOO', shell_literal('='), 'oof'),
                jbos('BAR', shell_literal('='), 'rab'),
                shell_literal('cmd')
            ]))

        self.assertEqual(
            posix.local_env(env, ['cmd']),
            shell_list([
                jbos('FOO', shell_literal('='), 'oof'),
                jbos('BAR', shell_literal('='), 'rab'), 'cmd'
            ]))
Exemplo n.º 13
0
 def test_shell(self):
     s = safe_str.jbos('$foo', safe_str.literal('$bar'))
     self.out.write(s, Syntax.shell)
     if platform_info().family == 'windows':
         expected = '$$foo$bar'
     else:
         expected = quoted('$$foo') + '$bar'
     self.assertEqual(self.out.stream.getvalue(), expected)
Exemplo n.º 14
0
    def test_extras(self):
        test_exe = self.make_extras()

        cmd, deps = self._build_commands()
        self.assertEqual(cmd, [[
            jbos('VAR', shell_literal('='), 'value'), test_exe, '--foo'
        ]])
        self.assertEqual(deps, [test_exe])
Exemplo n.º 15
0
 def mock_local_env(env, line):
     if env:
         eq = shell_literal('=')
         env_vars = [jbos(safe_str(name), eq, safe_str(value))
                     for name, value in env.items()]
     else:
         env_vars = []
     return env_vars + wshell.escape_line(line, listify=True)
Exemplo n.º 16
0
 def test_write_jbos_shell(self):
     out = Writer(StringIO())
     s = safe_str.jbos('$foo', safe_str.escaped_str('$bar'))
     out.write(s, Syntax.shell)
     if platform_name() == 'windows':
         expected = '$$foo$bar'
     else:
         expected = quoted('$$foo') + '$bar'
     self.assertEqual(out.stream.getvalue(), expected)
Exemplo n.º 17
0
    def test_jbos(self):
        self.assertEqual(
            posix.escape_line(jbos('foo', literal('bar'))),
            shell_list([jbos(shell_literal('foo'), literal('bar'))]))

        s = jbos(r'foo\bar', literal(r'baz\quux'))
        with mock.patch('bfg9000.shell.posix.platform_info',
                        return_value=self.FakePlatform('posix')):
            self.assertEqual(
                posix.escape_line(s),
                shell_list(
                    [jbos(shell_literal(r'foo\bar'), literal(r'baz\quux'))]))

        with mock.patch('bfg9000.shell.posix.platform_info',
                        return_value=self.FakePlatform('windows')):
            self.assertEqual(
                posix.escape_line(s),
                shell_list(
                    [jbos(shell_literal(r'foo\\bar'), literal(r'baz\quux'))]))
Exemplo n.º 18
0
    def test_multiple(self):
        env = OrderedDict((('FOO', 'oof'), ('BAR', 'rab')))
        self.assertEqual(
            posix.global_env(env),
            shell_list([
                'export',
                jbos('FOO', shell_literal('='), 'oof'),
                shell_literal('&&'), 'export',
                jbos('BAR', shell_literal('='), 'rab')
            ]))

        self.assertEqual(
            posix.global_env(env, ['cmd']),
            shell_list([
                'export',
                jbos('FOO', shell_literal('='), 'oof'),
                shell_literal('&&'), 'export',
                jbos('BAR', shell_literal('='), 'rab'),
                shell_literal('&&'),
                shell_literal('cmd')
            ]))

        self.assertEqual(
            posix.global_env(env, [['cmd']]),
            shell_list([
                'export',
                jbos('FOO', shell_literal('='), 'oof'),
                shell_literal('&&'), 'export',
                jbos('BAR', shell_literal('='), 'rab'),
                shell_literal('&&'), 'cmd'
            ]))
Exemplo n.º 19
0
    def test_single(self):
        env = {'NAME': 'VALUE'}
        self.assertEqual(
            posix.global_env(env),
            shell_list(['export',
                        jbos('NAME', shell_literal('='), 'VALUE')]))

        self.assertEqual(
            posix.global_env(env, ['cmd']),
            shell_list([
                'export',
                jbos('NAME', shell_literal('='), 'VALUE'),
                shell_literal('&&'),
                shell_literal('cmd')
            ]))

        self.assertEqual(
            posix.global_env(env, [['cmd']]),
            shell_list([
                'export',
                jbos('NAME', shell_literal('='), 'VALUE'),
                shell_literal('&&'), 'cmd'
            ]))
Exemplo n.º 20
0
    def test_flags_lib(self):
        lib1 = Path('/path/to/lib/libfoo.jar')
        lib2 = Path('/path/to/lib/libbar.jar')

        self.assertEqual(
            self.compiler.flags(
                opts.option_list(
                    opts.lib(file_types.StaticLibrary(lib1, 'jvm')))),
            ['-cp', jbos(lib1)])
        self.assertEqual(
            self.compiler.flags(
                opts.option_list(
                    opts.lib(file_types.StaticLibrary(lib1, 'jvm')),
                    opts.lib(file_types.StaticLibrary(lib2, 'jvm')))),
            ['-cp', lib1 + os.pathsep + lib2])
Exemplo n.º 21
0
 def test_jbos(self):
     self.assertEqual(
         windows.escape_line(jbos('foo', literal('bar'))),
         shell_list([jbos(shell_literal('foo'), literal('bar'))]))
Exemplo n.º 22
0
 def test_write_jbos_function(self):
     out = Writer(StringIO())
     s = safe_str.jbos('$foo', safe_str.escaped_str('$bar'))
     out.write(s, Syntax.function)
     self.assertEqual(out.stream.getvalue(), quoted('$$foo') + '$bar')
Exemplo n.º 23
0
    def test_flags_lib_dir(self):
        libdir = Path('/path/to/lib')
        lib = Path('/path/to/lib/libfoo.a')
        output = file_types.Executable(Path('exe'), 'native')

        if self.env.target_platform.name == 'linux':
            rpath = rpath_with_output = ['-Wl,-rpath,' + libdir]
        elif self.env.target_platform.name == 'darwin':
            rpath = []
            rpath_with_output = [jbos('-Wl,-rpath,', '@loader_path')]
        else:
            rpath = rpath_with_output = []

        # Lib dir
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib_dir(file_types.Directory(libdir)))),
            ['-L' + libdir])

        # Shared library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib(file_types.SharedLibrary(lib, 'native')))),
            ['-L' + libdir] + rpath)
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib(file_types.SharedLibrary(lib, 'native'))),
                output), ['-L' + libdir] + rpath_with_output)

        if self.env.target_platform.name == 'linux':
            libdir2 = Path('foo')
            lib2 = Path('foo/libbar.a')

            with self.assertRaises(ValueError):
                self.linker.flags(
                    opts.option_list(
                        opts.lib(file_types.SharedLibrary(lib2, 'native'))))
            self.assertEqual(
                self.linker.flags(
                    opts.option_list(
                        opts.lib(file_types.SharedLibrary(lib2, 'native'))),
                    output),
                ['-L' + libdir2,
                 jbos('-Wl,-rpath,', '$ORIGIN/foo')])

        # Static library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib(file_types.StaticLibrary(lib, 'native')))), [])
        self.assertEqual(
            self.linker.flags(opts.option_list(
                opts.lib(file_types.StaticLibrary(lib, 'native'))),
                              mode='pkg-config'), ['-L' + libdir])

        # Generic library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib(file_types.Library(lib, 'native')))),
            ['-L' + libdir])

        mingw_lib = Path('/path/to/lib/foo.lib')
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib(file_types.Library(mingw_lib, 'native')))), [])
        with self.assertRaises(ValueError):
            self.linker.flags(opts.option_list(
                opts.lib(file_types.Library(mingw_lib, 'native'))),
                              mode='pkg-config')

        # Framework
        self.assertEqual(
            self.linker.flags(opts.option_list(opts.lib(Framework('cocoa')))),
            [])

        # Mixed
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib_dir(file_types.Directory(libdir)),
                    opts.lib(file_types.SharedLibrary(lib, 'native')))),
            ['-L' + libdir] + rpath)
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib_dir(file_types.Directory(libdir)),
                    opts.lib(file_types.SharedLibrary(lib, 'native'))),
                output), ['-L' + libdir] + rpath_with_output)
Exemplo n.º 24
0
 def test_jbos(self):
     j = jbos('foo', literal('='), 'bar baz')
     self.assertEqual(textify(j), 'foo=bar baz')
     self.assertEqual(textify(j, True), 'foo="bar baz"')
Exemplo n.º 25
0
 def test_concat_pattern(self):
     self.assertEqual(
         Pattern('%.c') + Pattern('%.h'),
         safe_str.jbos(safe_str.literal('%'), '.c', safe_str.literal('%'),
                       '.h'))
Exemplo n.º 26
0
 def test_clean(self):
     out = Writer(StringIO())
     s = safe_str.jbos('$foo', safe_str.literal('$bar'))
     out.write(s, Syntax.clean)
     self.assertEqual(out.stream.getvalue(), '$$foo$bar')
Exemplo n.º 27
0
 def test_shell(self):
     out = Writer(StringIO())
     s = safe_str.jbos('$foo', safe_str.literal('$bar'))
     out.write(s, Syntax.shell)
     self.assertEqual(out.stream.getvalue(), quoted('$$foo') + '$bar')
Exemplo n.º 28
0
 def test_jbos(self):
     self.assertEqual(convert_args([jbos('foo', 'bar')]), ['foobar'])
     self.assertEqual(convert_args([jbos('foo', self.Path('/bar'))]),
                      ['foo' + self.ospath.sep + 'bar'])
Exemplo n.º 29
0
 def test_write_jbos_input(self):
     out = Writer(StringIO())
     s = safe_str.jbos('$foo', safe_str.escaped_str('$bar'))
     out.write(s, Syntax.input)
     self.assertEqual(out.stream.getvalue(), '$$foo$bar')
Exemplo n.º 30
0
 def test_input(self):
     s = safe_str.jbos('$foo', safe_str.literal('$bar'))
     self.out.write(s, Syntax.input)
     self.assertEqual(self.out.stream.getvalue(), '$$foo$bar')