def test_process_include_file_with_multiple_files():
    p = Preprocessor()

    defines = p.process_include_file(resolve_relative_path('fixtures/incl.h'))
    defines = p.process_include_file(resolve_relative_path('fixtures/incl2.h'))

    assert defines['CONST1'] == '42', "constant from incl.h"
    assert defines['CONST2'] == '123', "constant overridden by incl2.h"
    assert defines['CONST3'] == '777', "constant from incl2.h"
def test_process_include_file_should_not_load_database_keys_into_instance_defines_dictionary(
):
    db = DefinesDB()
    db.clear()

    p = Preprocessor()
    p.use_db(db)

    p.process_include_file(resolve_relative_path('fixtures/incl.h'))

    # a bit hackish to reference instance-internal state
    # but it's important to verify this, as we otherwise run out of memory on device
    assert 'CONST2' not in p._defines
def test_process_include_file_using_database():
    db = DefinesDB()
    db.clear()

    p = Preprocessor()
    p.use_db(db)

    p.process_include_file(resolve_relative_path('fixtures/incl.h'))
    p.process_include_file(resolve_relative_path('fixtures/incl2.h'))

    assert db['CONST1'] == '42', "constant from incl.h"
    assert db['CONST2'] == '123', "constant overridden by incl2.h"
    assert db['CONST3'] == '777', "constant from incl2.h"

    db.close()
def test_process_include_file():
    p = Preprocessor()

    defines = p.process_include_file(resolve_relative_path('fixtures/incl.h'))

    assert defines['CONST1'] == '42'
    assert defines['CONST2'] == '99'
    assert defines.get(
        'MULTI_LINE',
        None) == 'abc \\'  # correct. line continuations not supported
    assert 'MACRO' not in defines