Exemplo n.º 1
0
def test_order():
    finished = False
    link_after_compile_finished = False

    def compile(ctx):
        nonlocal finished
        sleep(1)
        finished = True

    def link(ctx):
        nonlocal link_after_compile_finished
        link_after_compile_finished = finished

    tasks = [
        Task(
            matcher=PlainTextMatcher(target="compile", sources=[]),
            handler=compile,
            phony=True,
        ),
        Task(
            matcher=PlainTextMatcher(target="link", sources=["compile"]),
            handler=link,
            phony=True,
        ),
    ]

    fs = TestFileSystem({})

    executor = create_test_executor(fs, tasks, jobs=4)
    executor.execute("link")

    assert link_after_compile_finished
Exemplo n.º 2
0
def test_plain_text_matcher():
    matcher = PlainTextMatcher(target="{filename.#-+}", sources=["{}{}"])

    ctx = matcher.match("{filename.#-+}")
    assert ctx is not None
    assert ctx.target == "{filename.#-+}"
    assert ctx.sources == ["{}{}"]
Exemplo n.º 3
0
def fake_compile_tasks():
    compiled_files = []
    linked_files = []

    def compile(ctx):
        compiled_files.append((ctx.target, ctx.sources))

    def link(ctx):
        linked_files.append((ctx.target, ctx.sources))

    return (
        [
            Task(
                matcher=RegularExpressionMatcher(target="(.*).o",
                                                 sources=["{}.c"]),
                handler=compile,
            ),
            Task(
                matcher=RegularExpressionMatcher(
                    target="binary", sources=[f"test{i}.o" for i in range(2)]),
                handler=link,
            ),
            Task(
                matcher=PlainTextMatcher(target="test", sources=["binary"]),
                handler=lambda x: None,
                phony=True,
            ),
        ],
        compiled_files,
        linked_files,
    )
Exemplo n.º 4
0
def test_parallelization():
    task1_running = False
    task2_running = False

    def task1(ctx):
        nonlocal task1_running, task2_running
        task1_running = True
        while not task2_running:
            sleep(0.1)

    def task2(ctx):
        nonlocal task1_running, task2_running
        task2_running = True
        while not task2_running:
            sleep(0.1)

    tasks = [
        Task(
            matcher=PlainTextMatcher(target="task1", sources=[]),
            handler=task1,
            phony=True,
        ),
        Task(
            matcher=PlainTextMatcher(target="task2", sources=[]),
            handler=task2,
            phony=True,
        ),
        Task(
            matcher=PlainTextMatcher(target="all", sources=["task1", "task2"]),
            handler=lambda _: None,
            phony=True,
        ),
    ]

    fs = TestFileSystem({})

    executor = create_test_executor(fs, tasks, jobs=2)
    executor.execute("all")
Exemplo n.º 5
0
def test_failure_task():
    task1_executed = 0
    task2_executed = 0

    def task1(ctx):
        nonlocal task1_executed
        sleep(1)
        task1_executed += 1

    def task2(ctx):
        nonlocal task2_executed
        task2_executed += 1
        raise Exception("Exception on purpose")

    tasks = [
        Task(
            matcher=PercentPatternMatcher(target="task1%", sources=[]),
            handler=task1,
            phony=True,
        ),
        Task(
            matcher=PercentPatternMatcher(target="task2%", sources=[]),
            handler=task2,
            phony=True,
        ),
        Task(
            matcher=PlainTextMatcher(
                target="all",
                sources=[
                    "task1_1",
                    "task2_1",
                    "task1_2",
                    "task2_2",
                    "task1_3",
                    "task2_3",
                ],
            ),
            handler=lambda _: None,
            phony=True,
        ),
    ]

    fs = TestFileSystem({})
    executor = create_test_executor(fs, tasks, jobs=2)
    executor.execute("all")

    assert task1_executed == 1
    assert task2_executed == 1
Exemplo n.º 6
0
def test_phony_task_with_recorded_timestamp(fs_config, expected):
    run = False

    def execute(ctx):
        nonlocal run
        run = True

    tasks = [
        Task(
            matcher=PlainTextMatcher(target="clean", sources=["a.txt"]),
            handler=execute,
            phony=True,
        ),
    ]

    fs = TestFileSystem(fs_config)

    executor = create_test_executor(fs, tasks)
    executor.execute("clean")

    assert run == expected
Exemplo n.º 7
0
def test_run_phony_task():
    run = False

    def execute(ctx):
        nonlocal run
        run = True

    tasks = [
        Task(
            matcher=PlainTextMatcher(target="clean", sources=[]),
            handler=execute,
            phony=True,
        ),
    ]

    fs = TestFileSystem({})

    executor = create_test_executor(fs, tasks)
    executor.execute("clean")

    assert run