Exemplo n.º 1
0
def test_simple_lib(tmp_project: Project) -> None:
    """
    Test that dds can build a simple library withsome actual content, and that
    the manifest files will affect the output name.
    """
    tmp_project.write('src/foo.cpp', 'int the_answer() { return 42; }')
    tmp_project.package_json = {
        'name': 'TestProject',
        'version': '0.0.0',
        'namespace': 'test',
    }
    tmp_project.library_json = {'name': 'TestLibrary'}
    tmp_project.build()
    assert (tmp_project.build_root / 'compile_commands.json').is_file()
    assert list(tmp_project.build_root.glob('libTestLibrary.*')) != []
Exemplo n.º 2
0
def test_get_build_use_cryptopp(test_parent_dir: Path, tmp_project: Project,
                                http_repo: RepoServer) -> None:
    http_repo.import_json_data(CRYPTOPP_JSON)
    tmp_project.dds.repo_add(http_repo.url)
    tmp_project.package_json = {
        'name': 'usr-cryptopp',
        'version': '1.0.0',
        'namespace': 'test',
        'depends': ['[email protected]'],
    }
    tmp_project.library_json = {
        'name': 'use-cryptopp',
        'uses': ['cryptopp/cryptopp'],
    }
    tc_fname = 'gcc.tc.jsonc' if 'gcc' in toolchain.get_default_test_toolchain(
    ).name else 'msvc.tc.jsonc'
    tmp_project.write('src/use-cryptopp.main.cpp', APP_CPP)
    tmp_project.build(toolchain=test_parent_dir / tc_fname, timeout=60 * 10)
    proc.check_run([
        (tmp_project.build_root / 'use-cryptopp').with_suffix(paths.EXE_SUFFIX)
    ])
Exemplo n.º 3
0
def test_build_simple(tmp_project: Project) -> None:
    """
    Test that dds can build a simple library, and handles rebuilds correctly.
    """
    # Build a bad project
    tmp_project.write('src/f.cpp', 'syntax error')
    with pytest.raises(CalledProcessError):
        tmp_project.build()
    # Now we can build:
    tmp_project.write('src/f.cpp', r'void f() {}')
    tmp_project.build()
    # Writing again will build again:
    time.sleep(1)  # Sleep long enough to register a file change
    tmp_project.write('src/f.cpp', r'bad again')
    with pytest.raises(CalledProcessError):
        tmp_project.build()
Exemplo n.º 4
0
def test_partial_build_rebuild(test_project: Project) -> None:
    """
    Change the content of a header, but cause one user of that header to fail
    compilation. The fact that compilation fails means it is still `out-of-date`,
    and will need to be compiled after we have fixed it up.
    """
    assert build_and_get_rc(test_project) == 0
    test_project.write(
        'src/values.hpp', '''
        const int first_value_q  = 6;
        const int second_value_q = 99;
    ''')
    # Header now causes errors in 1.cpp and 2.cpp
    with pytest.raises(subprocess.CalledProcessError):
        test_project.build()
    # Fix 1.cpp
    test_project.write(
        'src/1.cpp', '''
        #include "./values.hpp"

        int value_1() { return first_value_q; }
    ''')
    # We will still see a failure, but now the DB will record the updated values.hpp
    with pytest.raises(subprocess.CalledProcessError):
        test_project.build()

    # Should should raise _again_, even though we've successfully compiled one
    # of the two files with the changed `values.hpp`, because `2.cpp` still
    # has a pending update
    with pytest.raises(subprocess.CalledProcessError):
        test_project.build()

    # Pause long enough for timestamps to change
    test_project.write(
        'src/2.cpp', '''
        #include "./values.hpp"

        int value_2() { return second_value_q; }
    ''')
    # We should now compile and link to get the updated value
    assert build_and_get_rc(test_project) == (99 - 6)
Exemplo n.º 5
0
def test_empty_with_pkg_json(tmp_project: Project) -> None:
    tmp_project.package_json = TEST_PACKAGE
    tmp_project.build()
Exemplo n.º 6
0
def test_lib_with_failing_test(tmp_project: Project) -> None:
    tmp_project.write('src/foo.test.cpp', 'int main() { return 2; }')
    with expect_error_marker('build-failed-test-failed'):
        tmp_project.build()
Exemplo n.º 7
0
def test_lib_with_just_test(tmp_project: Project) -> None:
    tmp_project.write('src/foo.test.cpp', 'int main() {}')
    tmp_project.build()
    assert tmp_project.build_root.joinpath(
        f'test/foo{paths.EXE_SUFFIX}').is_file()
Exemplo n.º 8
0
def test_lib_with_app_only(tmp_project: Project) -> None:
    """Test that dds can build a simple application"""
    tmp_project.write('src/foo.main.cpp', r'int main() {}')
    tmp_project.build()
    assert (tmp_project.build_root / f'foo{paths.EXE_SUFFIX}').is_file()
Exemplo n.º 9
0
def test_build_empty(tmp_project: Project) -> None:
    """Check that dds is okay with building an empty project directory"""
    tmp_project.build()
Exemplo n.º 10
0
def build_and_get_rc(proj: Project) -> int:
    proj.build()
    app = proj.build_root.joinpath('app' + paths.EXE_SUFFIX)
    return proc.run([app]).returncode