MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / test_platform_lookup_path

Function test_platform_lookup_path

test/cli/lookup_test.py:447–474  ·  view source on GitHub ↗
(tmpdir)

Source from the content-addressed store, hash-verified

445
446
447def test_platform_lookup_path(tmpdir):
448 test_file = os.path.join(tmpdir, 'test.c')
449 with open(test_file, 'wt'):
450 pass
451
452 cppcheck = 'cppcheck' # No path
453 path = os.path.dirname(__lookup_cppcheck_exe())
454 env = os.environ.copy()
455 env['PATH'] = path
456 exitcode, stdout, stderr, _ = cppcheck_ex(args=['--debug-lookup=platform', '--platform=avr8.xml', test_file], cppcheck_exe=cppcheck, cwd=str(tmpdir), env=env)
457 assert exitcode == 0, stdout if stdout else stderr
458 def format_path(p):
459 return p.replace('\\', '/').replace('"', '\'')
460 def try_fail(f):
461 f = format_path(f)
462 return "try to load platform file '{}' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}".format(f, f)
463 def try_success(f):
464 f = format_path(f)
465 return "try to load platform file '{}' ... Success".format(f)
466 lines = stdout.replace('\\', '/').replace('"', '\'').splitlines()
467 assert lines == [
468 "looking for platform 'avr8.xml'",
469 try_fail(os.path.join(tmpdir, 'avr8.xml')),
470 try_fail(os.path.join(tmpdir, 'platforms', 'avr8.xml')),
471 try_fail(os.path.join(path, 'avr8.xml')),
472 try_success(os.path.join(path, 'platforms', 'avr8.xml')),
473 'Checking {} ...'.format(format_path(test_file))
474 ]
475
476
477def test_platform_lookup_notfound(tmpdir):

Callers

nothing calls this directly

Calls 10

__lookup_cppcheck_exeFunction · 0.90
cppcheck_exFunction · 0.90
strFunction · 0.85
try_failFunction · 0.85
try_successFunction · 0.85
format_pathFunction · 0.85
formatMethod · 0.80
joinMethod · 0.45
copyMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected