class TestLanguages(unittest.TestCase): def setUp(self): self.known_langs = Languages() with self.known_langs.make('c') as x: x.vars(compiler='CC') x.exts(source='.c') def test_make(self): with self.known_langs.make('c++') as x: x.vars(compiler='CXX') x.exts(source=['.cxx', '.cpp']) self.assertEqual(self.known_langs['c'].name, 'c') self.assertEqual(self.known_langs['c'].var('compiler'), 'CC') self.assertEqual(self.known_langs['c'].exts('source'), ['.c']) self.assertEqual(self.known_langs['c++'].name, 'c++') self.assertEqual(self.known_langs['c++'].var('compiler'), 'CXX') self.assertEqual(self.known_langs['c++'].exts('source'), ['.cxx', '.cpp']) def test_make_duplicate_ext(self): msg = r"^'\.c' already used by 'c'$" with assertRaisesRegex(self, ValueError, msg): with self.known_langs.make('c++') as x: x.exts(source=['.c', '.cpp']) def test_get_unrecognized_lang(self): msg = r"^unrecognized language 'c\+\+'$" with assertRaisesRegex(self, ValueError, msg): self.known_langs['c++'] def test_get_unrecognized_var(self): msg = r"^language 'c' does not support var 'goofy'$" with assertRaisesRegex(self, ValueError, msg): self.known_langs['c'].var('goofy') def test_get_unrecognized_exts(self): msg = r"^language 'c' does not support file type 'goofy'$" with assertRaisesRegex(self, ValueError, msg): self.known_langs['c'].exts('goofy') def test_fromext(self): self.assertEqual(self.known_langs.fromext('.c', 'source'), 'c') self.assertEqual(self.known_langs.fromext('.c', 'header'), None) self.assertEqual(self.known_langs.fromext('.c', 'goofy'), None) self.assertEqual(self.known_langs.fromext('.foo', 'source'), None)
from .. import * from bfg9000 import options as opts from bfg9000.file_types import * from bfg9000.languages import Languages from bfg9000.path import Path, Root from bfg9000.tools.lex import LexBuilder known_langs = Languages() with known_langs.make('lex') as x: x.vars(compiler='LEX', flags='LFLAGS') class TestLexBuilder(CrossPlatformTestCase): def __init__(self, *args, **kwargs): super().__init__(clear_variables=True, *args, **kwargs) def setUp(self): self.lex = LexBuilder(self.env, known_langs['lex'], ['lex'], 'version') self.compiler = self.lex.transpiler def test_properties(self): self.assertEqual(self.compiler.num_outputs, 'all') self.assertEqual(self.compiler.deps_flavor, None) def test_call(self): self.assertEqual(self.compiler('in', 'out'), [self.compiler, '-o', 'out', 'in']) self.assertEqual(self.compiler('in', 'out', ['flags']), [self.compiler, 'flags', '-o', 'out', 'in'])
class TestLanguages(TestCase): def setUp(self): self.known_langs = Languages() with self.known_langs.make('c') as x: x.vars(compiler='CC') x.exts(source='.c', header='.h') def test_make(self): with self.known_langs.make('c++') as x: x.vars(compiler='CXX') x.exts(source=['.cxx', '.cpp'], header=['.hpp']) x.auxexts(header=['.h']) with self.known_langs.make('goofy', src_lang='c++') as x: x.vars(compiler='GOOFY') x.exts(source=['.goofy']) x.auxexts(header=['.h']) c = self.known_langs['c'] self.assertEqual(c.name, 'c') self.assertEqual(c.src_lang, 'c') self.assertEqual(c.var('compiler'), 'CC') self.assertEqual(c.exts('source'), ['.c']) self.assertEqual(c.exts('header'), ['.h']) self.assertEqual(c.auxexts('source'), []) self.assertEqual(c.auxexts('header'), []) self.assertEqual(c.allexts('source'), ['.c']) self.assertEqual(c.allexts('header'), ['.h']) self.assertEqual(c.default_ext('source'), '.c') self.assertEqual(c.default_ext('header'), '.h') self.assertEqual(c.extkind('.c'), 'source') self.assertEqual(c.extkind('.h'), 'header') self.assertEqual(c.extkind('.none'), None) cxx = self.known_langs['c++'] self.assertEqual(cxx.name, 'c++') self.assertEqual(cxx.src_lang, 'c++') self.assertEqual(cxx.var('compiler'), 'CXX') self.assertEqual(cxx.exts('source'), ['.cxx', '.cpp']) self.assertEqual(cxx.exts('header'), ['.hpp']) self.assertEqual(cxx.auxexts('header'), ['.h']) self.assertEqual(cxx.allexts('source'), ['.cxx', '.cpp']) self.assertEqual(cxx.allexts('header'), ['.hpp', '.h']) self.assertEqual(cxx.default_ext('source'), '.cxx') self.assertEqual(cxx.default_ext('header'), '.hpp') self.assertEqual(cxx.extkind('.cxx'), 'source') self.assertEqual(cxx.extkind('.hpp'), 'header') self.assertEqual(cxx.extkind('.h'), 'header') self.assertEqual(cxx.extkind('.none'), None) g = self.known_langs['goofy'] self.assertEqual(g.name, 'goofy') self.assertEqual(g.src_lang, 'c++') self.assertEqual(g.var('compiler'), 'GOOFY') self.assertEqual(g.exts('source'), ['.goofy']) self.assertEqual(g.exts('header'), []) self.assertEqual(g.auxexts('header'), ['.h']) self.assertEqual(g.allexts('source'), ['.goofy']) self.assertEqual(g.allexts('header'), ['.h']) self.assertEqual(g.default_ext('source'), '.goofy') self.assertEqual(g.default_ext('header'), '.h') self.assertEqual(g.extkind('.goofy'), 'source') self.assertEqual(g.extkind('.h'), 'header') self.assertEqual(g.extkind('.none'), None) def test_make_duplicate_ext(self): msg = r"^'\.c' already used by 'c'$" with self.assertRaisesRegex(ValueError, msg): with self.known_langs.make('c++') as x: x.exts(source=['.c', '.cpp']) def test_make_invalid_attr(self): with self.known_langs.make('c++') as x: with self.assertRaises(AttributeError): x.unknown() def test_in(self): self.assertTrue('c' in self.known_langs) self.assertFalse('c' not in self.known_langs) self.assertFalse('c++' in self.known_langs) self.assertTrue('c++' not in self.known_langs) def test_get_unrecognized_lang(self): msg = r"^unrecognized language 'c\+\+'$" with self.assertRaisesRegex(ValueError, msg): self.known_langs['c++'] def test_get_unrecognized_var(self): msg = r"^language 'c' does not support var 'goofy'$" with self.assertRaisesRegex(ValueError, msg): self.known_langs['c'].var('goofy') def test_get_unrecognized_exts(self): msg = r"^language 'c' does not support file type 'goofy'$" with self.assertRaisesRegex(ValueError, msg): self.known_langs['c'].exts('goofy') def test_fromext(self): self.assertEqual(self.known_langs.fromext('.c', 'source'), 'c') self.assertEqual(self.known_langs.fromext('.c', 'header'), None) self.assertEqual(self.known_langs.fromext('.c', 'goofy'), None) self.assertEqual(self.known_langs.fromext('.foo', 'source'), None)
from unittest import mock from .. import * from bfg9000.languages import Languages from bfg9000.path import Root from bfg9000.tools import cc, common known_langs = Languages() with known_langs.make('c') as x: x.vars(compiler='CC', flags='CFLAGS') def mock_which(*args, **kwargs): return ['command'] def mock_execute(args, **kwargs): if args[-1] == '--version': return ('g++ (Ubuntu 5.4.0-6ubuntu1~16.04.6) 5.4.0 20160609\n' + 'Copyright (C) 2015 Free Software Foundation, Inc.') elif args[-1] == '-Wl,--version': return '', '/usr/bin/ld --version\n' elif args[-1] == '-print-search-dirs': return 'libraries: =/lib/search/dir1:/lib/search/dir2\n' elif args[-1] == '-print-sysroot': return '/' elif args[-1] == '--verbose': return 'SEARCH_DIR("/usr")\n'
from unittest import mock from .. import * from bfg9000 import options as opts, platforms from bfg9000.exceptions import PackageResolutionError from bfg9000.file_types import * from bfg9000.languages import Languages from bfg9000.packages import Framework from bfg9000.path import InstallRoot, Path, Root from bfg9000.tools.cc import CcBuilder from bfg9000.versioning import Version known_langs = Languages() with known_langs.make('c++') as x: x.vars(compiler='CXX', flags='CXXFLAGS') with known_langs.make('java') as x: x.vars(compiler='JAVAC', flags='JAVAFLAGS') def mock_which(*args, **kwargs): return ['command'] def mock_execute(args, **kwargs): if args[-1] == '-Wl,--version': return '', ('COLLECT_GCC=g++\n/usr/bin/collect2 --version\n' + '/usr/bin/ld --version\n') elif args[-1] == '-print-search-dirs': return 'libraries: =/lib/search/dir1:/lib/search/dir2\n' elif args[-1] == '-print-sysroot':
import os from unittest import mock from .. import * from bfg9000 import file_types, options as opts from bfg9000.languages import Languages from bfg9000.path import Path, Root from bfg9000.tools.jvm import JvmBuilder from bfg9000.versioning import Version known_langs = Languages() with known_langs.make('java') as x: x.vars(compiler='JAVAC', runner='JAVACMD', flags='JAVAFLAGS') with known_langs.make('scala') as x: x.vars(compiler='SCALAC', runner='SCALACMD', flags='SCALAFLAGS') def mock_which(*args, **kwargs): return ['command'] class TestJvmBuilder(CrossPlatformTestCase): def __init__(self, *args, **kwargs): super().__init__(clear_variables=True, *args, **kwargs) def test_properties(self): def mock_execute(*args, **kwargs): return 'version' with mock.patch('bfg9000.shell.which', mock_which), \
from .. import * from bfg9000 import options as opts from bfg9000.file_types import * from bfg9000.languages import Languages from bfg9000.path import Path, Root from bfg9000.tools.yacc import YaccBuilder known_langs = Languages() with known_langs.make('yacc') as x: x.vars(compiler='YACC', flags='YFLAGS') class TestYaccBuilder(CrossPlatformTestCase): def __init__(self, *args, **kwargs): super().__init__(clear_variables=True, *args, **kwargs) def setUp(self): self.yacc = YaccBuilder(self.env, known_langs['yacc'], ['yacc'], 'version') self.compiler = self.yacc.transpiler def test_properties(self): self.assertEqual(self.compiler.num_outputs, 1) self.assertEqual(self.compiler.deps_flavor, None) def test_call(self): self.assertEqual(self.compiler('in', 'out'), [self.compiler, 'in', '-o', 'out']) self.assertEqual(self.compiler('in', 'out', ['flags']), [self.compiler, 'flags', 'in', '-o', 'out'])
from .. import * from bfg9000 import options as opts from bfg9000.file_types import * from bfg9000.languages import Languages from bfg9000.path import Path, Root from bfg9000.tools.qt import MocBuilder, RccBuilder, UicBuilder known_langs = Languages() with known_langs.make('qtmoc') as x: x.vars(compiler='MOC', flags='MOCFLAGS') with known_langs.make('qrc') as x: x.vars(compiler='RCC', flags='RCCFLAGS') with known_langs.make('qtui') as x: x.vars(compiler='UIC', flags='UICFLAGS') def mock_which(*args, **kwargs): return ['command'] class TestMocBuilder(CrossPlatformTestCase): def __init__(self, *args, **kwargs): CrossPlatformTestCase.__init__(self, clear_variables=True, *args, **kwargs) def setUp(self): self.moc = MocBuilder(self.env, known_langs['qtmoc'], ['moc'], 'version')