Пример #1
0
def test_simple_rebuild(test_project: Project) -> None:
    """
    Check that changing a source file will update the resulting application.
    """
    assert build_and_get_rc(test_project) == 0
    test_project.write('src/1.cpp', 'int value_1() { return 33; }')
    # 33 - 32 = 1
    assert build_and_get_rc(test_project) == 1
Пример #2
0
def test_create_pkg(test_project: Project, tmp_path: Path) -> None:
    # Create in the default location
    test_project.pkg_create()
    sd_dir = test_project.build_root / '*****@*****.**'
    assert sd_dir.is_file(), 'Did not create an sdist in the default location'
    # Create in a different location
    dest = tmp_path / 'dummy.tar.gz'
    test_project.pkg_create(dest=dest)
    assert dest.is_file(), 'Did not create an sdist in the new location'
Пример #3
0
def test_from_file(test_project: Project) -> None:
    """build-deps using a file listing deps"""
    test_project.write('deps.json5', json.dumps({'depends':
                                                 ['neo-fun+0.3.0']}))
    test_project.dds.build_deps(['-d', 'deps.json5'])
    assert test_project.root.joinpath('_deps/[email protected]').is_dir()
    assert test_project.root.joinpath('_deps/_libman/neo-fun.lmp').is_file()
    assert test_project.root.joinpath('_deps/_libman/neo/fun.lml').is_file()
    assert test_project.root.joinpath('INDEX.lmi').is_file()
Пример #4
0
def test_rebuild_header_change(test_project: Project) -> None:
    """Change the content of the header which defines the values"""
    assert build_and_get_rc(test_project) == 0
    test_project.write(
        'src/values.hpp', '''
        const int first_value = 63;
        const int second_value = 88;
    ''')
    assert build_and_get_rc(test_project) == (88 - 63)
Пример #5
0
def test_simple_compile_file(tmp_project: Project) -> None:
    """
    Check that changing a source file will update the resulting application.
    """
    with pytest.raises(subprocess.CalledProcessError):
        tmp_project.compile_file('src/answer.cpp')
    tmp_project.write('src/answer.cpp', 'int get_answer() { return 42; }')
    # No error:
    tmp_project.compile_file('src/answer.cpp')
    # Fail:
    time.sleep(1)  # Sleep long enough to register a file change
    tmp_project.write(
        'src/answer.cpp',
        'int get_answer() { return "How many roads must a man walk down?"; }')
    with pytest.raises(subprocess.CalledProcessError):
        tmp_project.compile_file('src/answer.cpp')
Пример #6
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.*')) != []
Пример #7
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)
    ])
Пример #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()
Пример #9
0
def test_sdist_invalid_json5(tmp_project: Project) -> None:
    tmp_project.write('package.json5', 'bogus json5')
    with error.expect_error_marker('package-json5-parse-error'):
        tmp_project.pkg_create()
Пример #10
0
def test_empty_sdist_create(tmp_project: Project) -> None:
    tmp_project.package_json = TEST_PACKAGE
    tmp_project.pkg_create()
    assert tmp_project.build_root.joinpath('*****@*****.**').is_file(), \
        'The expected sdist tarball was not generated'
Пример #11
0
def test_empty_with_pkg_json(tmp_project: Project) -> None:
    tmp_project.package_json = TEST_PACKAGE
    tmp_project.build()
Пример #12
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()
Пример #13
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()
Пример #14
0
def _test_pkg(test_project: Project) -> Tuple[Path, Project]:
    repo_content_path = test_project.dds.repo_dir / '[email protected]'
    assert not repo_content_path.is_dir()
    test_project.pkg_create()
    assert not repo_content_path.is_dir()
    return test_project.build_root / '*****@*****.**', test_project
Пример #15
0
def test_build_empty(tmp_project: Project) -> None:
    """Check that dds is okay with building an empty project directory"""
    tmp_project.build()
Пример #16
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)
Пример #17
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
Пример #18
0
def test_sdist_invalid_project(tmp_project: Project) -> None:
    with error.expect_error_marker('no-package-json5'):
        tmp_project.pkg_create()
Пример #19
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()