Example #1
0
 def test_path(self):
     proj = Project('foo/')
     build = Build(proj, 'bar/')
     self.assertEquals(build.project.srcdir, 'foo')
     self.assertEquals(build.builddir, 'bar')
     self.assertEquals(build.relative_source(), '../foo')
Example #2
0
    def test_configure(self):
        def check_foo(bld, FOO):
            self.assertEqual(FOO, 'B')
        def check_bar(bld, BAR):
            self.assertEqual(BAR, 1)
        def check_qux(bld, QUX):
            self.assertEqual(QUX, '')
        def check_var(bld, VAR):
            self.assertEqual(VAR, 'value')

        proj = Project('.')
        proj.add_alias('--alias', ['--foo=A', '--bar=1', '--foo=B'],
                help=None, hidden=False)
        proj.add_option('--foo', init='X',
                type=shell_word, check=check_foo,
                help='help for string foo', hidden=False)
        proj.add_option('--bar', init=0,
                type=uint, check=check_bar,
                help='help for int bar', hidden=False)
        proj.add_option('--qux', init='',
                type=maybe(uint), check=check_qux,
                help='help for int qux', hidden=False,
                help_def='auto')
        proj.add_option('VAR', init='',
                type=shell_partial_word, check=check_var,
                help='help for string VAR', hidden=False)

        build = Build(proj, '.')
        build.configure(['--alias'],
                {
                    'VAR': 'value',
                    'QUX': 'a',
                    '--qux': 'b',
                })
        os.remove('config.status')
        self.assertEqual(build.vars,
                {
                    'FOO': 'B',
                    'BAR': 1,
                    'QUX': '',
                    'VAR': 'value',
                })
Example #3
0
    def test_help(self):
        proj = Project('foo')
        proj.add_help('General:', False)
        proj.add_alias('--help', ['--help=default'],
                help='display standard help, then exit', hidden=False)
        proj.add_option('--help', init='none',
                type=proj.do_help, check=None,
                help='display some subset of help', hidden=False,
                help_var='TYPE')
        proj.help.add_option('--help=hidden',
                help='display help you should never ever ever care about',
                hidden=True)
        proj.add_option('--foo', init='asdf',
                type=shell_word, check=None,
                help='set frob target', hidden=False)
        proj.add_option('--bar', init='',
                type=maybe(shell_word), check=None,
                help='set frob source', hidden=False,
                help_def='FOO')

        build = Build(proj, 'bar')

        out = StringIO()
        with ReplacingStdout(out):
            with self.assertRaises(SystemExit):
                build.apply_arg('--help')
        self.assertEqual(out.getvalue(), '''
General:
  --help       display standard help, then exit
  --help=TYPE  display some subset of help [none]
  --foo=FOO    set frob target [asdf]
  --bar=BAR    set frob source [FOO]

'''[1:])

        out = StringIO()
        with ReplacingStdout(out):
            with self.assertRaises(SystemExit):
                build.apply_arg('--help=hidden')
        self.assertEqual(out.getvalue(), '''
General:
  --help         display standard help, then exit
  --help=TYPE    display some subset of help [none]
  --help=hidden  display help you should never ever ever care about
  --foo=FOO      set frob target [asdf]
  --bar=BAR      set frob source [FOO]

'''[1:])