Example #1
0
    def test_literal(self):
        self.assertQuote(shell_literal('>'), False, '>', '>')
        self.assertQuote(shell_literal(''), False, '', '')

        s = shell_literal('>') + 'foo bar'
        self.assertEqual(windows.quote(s), '>"foo bar"')
        self.assertEqual(windows.quote_info(s), ('>"foo bar"', True))
Example #2
0
    def test_literal(self):
        self.assertQuote(shell_literal('>'), False, '>', '>')
        self.assertQuote(shell_literal(''), False, '', '')

        s = shell_literal('>') + 'foo bar'
        self.assertEqual(posix.quote(s), ">'foo bar'")
        self.assertEqual(posix.quote_info(s), (">'foo bar'", True))
Example #3
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']))
Example #4
0
    def test_string(self):
        self.assertEqual(posix.escape_line('foobar'),
                         shell_list([shell_literal(r'foobar')]))

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

        with mock.patch('bfg9000.shell.posix.platform_info',
                        return_value=self.FakePlatform('windows')):
            self.assertEqual(posix.escape_line(r'foo\bar'),
                             shell_list([shell_literal(r'foo\\bar')]))
Example #5
0
    def test_string(self):
        class FakePlatform(object):
            def __init__(self, family):
                self.family = family

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

        with mock.patch('bfg9000.shell.posix.platform_info',
                        return_value=FakePlatform('windows')):
            self.assertEqual(posix.escape_line(r'foo\bar'),
                             shell_list([shell_literal(r'foo\\bar')]))
Example #6
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')
         ]))
Example #7
0
 def test_multiple(self):
     self.assertEqual(windows.join_lines(['foo', 'bar']), shell_list([
         shell_literal('foo'),
         shell_literal('&&'),
         shell_literal('bar'),
     ]))
     self.assertEqual(
         windows.join_lines([['foo', 'bar'], 'baz']),
         shell_list([
             'foo', 'bar',
             shell_literal('&&'),
             shell_literal('baz'),
         ])
     )
Example #8
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'
            ]))
Example #9
0
    def test_single(self):
        env = {'NAME': 'VALUE'}
        self.assertEqual(windows.global_env(env),
                         shell_list(['set', 'NAME=VALUE']))

        self.assertEqual(
            windows.global_env(env, ['cmd']),
            shell_list([
                'set', 'NAME=VALUE',
                shell_literal('&&'),
                shell_literal('cmd')
            ]))

        self.assertEqual(
            windows.global_env(env, [['cmd']]),
            shell_list(['set', 'NAME=VALUE',
                        shell_literal('&&'), 'cmd']))
Example #10
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])
Example #11
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)
Example #12
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'))]))
Example #13
0
    def test_arguments_shell_list(self):
        file = file_types.File(Path('foo.c', Root.srcdir))
        output = file_types.File(Path('foo.o'))
        self.compdb.append(file=file,
                           output=output,
                           arguments=shell_list([
                               'cmd',
                               shell_literal('<'), file,
                               shell_literal('>>'), output
                           ]))

        self.assertEqual(self._db_to_json(), [
            {
                'directory':
                self.env.builddir.string(),
                'command':
                'cmd < {} >> {}'.format(file.path.string(self.base_dirs),
                                        output.path.string(self.base_dirs)),
                'file':
                file.path.string(self.base_dirs),
                'output':
                'foo.o'
            },
        ])
Example #14
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'
            ]))
Example #15
0
    def test_multiple(self):
        env = OrderedDict((('FOO', 'oof'), ('BAR', 'rab')))
        self.assertEqual(windows.global_env(env), shell_list([
            'set', 'FOO=oof',
            shell_literal('&&'),
            'set', 'BAR=rab'
        ]))

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

        self.assertEqual(windows.global_env(env, [['cmd']]), shell_list([
            'set', 'FOO=oof',
            shell_literal('&&'),
            'set', 'BAR=rab',
            shell_literal('&&'),
            'cmd'
        ]))
Example #16
0
 def test_dependency(self):
     out = Writer(StringIO())
     out.write(safe_str.shell_literal('foo: $bar|baz,quux'),
               Syntax.dependency)
     self.assertEqual(out.stream.getvalue(),
                      'foo' + esc_colon + '\\ $$bar\\|baz,quux')
Example #17
0
 def test_empty(self):
     self.assertEqual(posix.global_env({}), [])
     self.assertEqual(posix.global_env({}, ['cmd']),
                      shell_list([shell_literal('cmd')]))
     self.assertEqual(posix.global_env({}, [['cmd']]), ['cmd'])
Example #18
0
 def test_depfixer(self):
     self.assertEqual(self.tool('depfile'), shell_list([
         self.tool, shell_literal('<'), 'depfile', shell_literal('>>'),
         'depfile'
     ]))
Example #19
0
 def test_output(self):
     out = Writer(StringIO())
     out.write(safe_str.shell_literal('foo: $bar'), Syntax.output)
     self.assertEqual(out.stream.getvalue(), 'foo$:$ $$bar')
Example #20
0
 def test_empty(self):
     self.assertEqual(posix.local_env({}, 'cmd'),
                      shell_list([shell_literal('cmd')]))
     self.assertEqual(posix.local_env({}, ['cmd']), ['cmd'])
Example #21
0
 def test_single(self):
     self.assertEqual(posix.join_lines(['foo']),
                      shell_list([shell_literal('foo')]))
     self.assertEqual(posix.join_lines([['foo']]), ['foo'])
     self.assertEqual(posix.join_lines([['foo', 'bar']]), ['foo', 'bar'])
Example #22
0
 def test_stringify_equal(self):
     r = SimpleRequirement('foo', '==1.0')
     self.assertEqual(safe_str(r), shell_literal('foo = 1.0'))
Example #23
0
 def test_stringify_no_version(self):
     r = SimpleRequirement('foo')
     self.assertEqual(safe_str(r), shell_literal('foo'))
Example #24
0
 def test_input(self):
     self.out.write(safe_str.shell_literal('foo: $bar'), Syntax.input)
     self.assertEqual(self.out.stream.getvalue(), 'foo$:$ $$bar')
Example #25
0
 def test_clean(self):
     self.out.write(safe_str.shell_literal('foo: $bar'), Syntax.clean)
     self.assertEqual(self.out.stream.getvalue(), 'foo: $$bar')
Example #26
0
 def test_basic(self):
     self._init_setenv()
     self.assertEqual(self.setenv({}, ['echo', 'hi']), ['echo', 'hi'])
     self.assertEqual(self.setenv({}, 'echo hi'),
                      shell_list([shell_literal('echo hi')]))
Example #27
0
 def test_convert_to_str(self):
     with self.assertRaises(NotImplementedError):
         str(safe_str.literal('foo'))
     with self.assertRaises(NotImplementedError):
         str(safe_str.shell_literal('foo'))
Example #28
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'
            ]))
Example #29
0
 def test_literal(self):
     self.assertEqual(posix.join(['foo bar',
                                  shell_literal('>'), 'baz']),
                      "'foo bar' > baz")
     self.assertEqual(posix.join(['foo bar' + shell_literal('>'), 'baz']),
                      "'foo bar'> baz")
Example #30
0
 def test_clean(self):
     out = Writer(StringIO())
     out.write(safe_str.shell_literal('foo: $bar|baz,quux'), Syntax.clean)
     self.assertEqual(out.stream.getvalue(), 'foo: $$bar|baz,quux')