From 8fe33b3a8b61682e7a9abc7a97264d08eba7504b Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Tue, 2 Mar 2021 17:48:20 +0100 Subject: Added Result and ResultLeak tests --- tests/test/test_result.py | 467 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 456 insertions(+), 11 deletions(-) (limited to 'tests/test') diff --git a/tests/test/test_result.py b/tests/test/test_result.py index 35c6213..7b29f66 100644 --- a/tests/test/test_result.py +++ b/tests/test/test_result.py @@ -6,7 +6,7 @@ # By: cacharle +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/03/01 16:26:34 by cacharle #+# #+# # -# Updated: 2021/03/02 14:21:14 by cacharle ### ########.fr # +# Updated: 2021/03/02 17:47:59 by cacharle ### ########.fr # # # # ############################################################################ # @@ -15,12 +15,15 @@ import pytest from minishell_test.config import Config from minishell_test import colors +from minishell_test.test.result import BaseResult, Result, LeakResult, LeakResultException +from minishell_test.test.captured import CapturedCommand, CapturedTimeout + +from tests.helpers import config_context + + colors.disable() Config.init([]) -from minishell_test.test.result import BaseResult, Result, LeakResult -from minishell_test.test.captured import CapturedCommand - class TestBaseResult: @pytest.fixture @@ -39,6 +42,10 @@ class TestBaseResult: with pytest.raises(NotImplementedError): base_result.__repr__() + def test_summarize(self, base_result): + with pytest.raises(NotImplementedError): + base_result.summarize(0) + def test_cmd(self, base_result): assert "echo bonjour" == base_result._cmd assert "foo\\nbar" == BaseResult("foo\nbar")._cmd @@ -47,11 +54,6 @@ class TestBaseResult: assert "foo\\rbar" == BaseResult("foo\rbar")._cmd assert "foo\\fbar" == BaseResult("foo\fbar")._cmd - def test_summarize(self, base_result): - pass - - - class TestResult: @pytest.fixture @@ -72,11 +74,454 @@ class TestResult: CapturedCommand("aurevoir", 0, []), ) - def test_passed(self, result_pass, result_fail): + @pytest.fixture + def result_fail_status(self): + return Result( + "echo bonjour", + [], + CapturedCommand("bonjour", 0, []), + CapturedCommand("bonjour", 1, []), + ) + + @pytest.fixture + def result_fail_file(self): + return Result( + "echo bonjour > foo", + ["foo"], + CapturedCommand("bonjour", 0, ["bonjour"]), + CapturedCommand("bonjour", 0, ["aurevoir"]), + ) + + @pytest.fixture + def result_fail_file_not_exist(self): + return Result( + "echo bonjour > foo", + ["foo"], + CapturedCommand("bonjour", 0, ["bonjour"]), + CapturedCommand("bonjour", 0, [None]), + ) + + @pytest.fixture + def result_fail_file_multiple(self): + return Result( + "echo bonjour > foo > bar", + ["foo", "bar"], + CapturedCommand("bonjour", 0, ["", "bonjour"]), + CapturedCommand("bonjour", 0, ["bonjour", None]), + ) + + @pytest.fixture + def result_fail_timeout(self): + return Result("echo bonjour", [], CapturedCommand("bonjour", 0, []), CapturedTimeout()) + + def test_passed(self, result_pass, result_fail, result_fail_status, + result_fail_file, result_fail_file_not_exist, result_fail_file_multiple, result_fail_timeout): assert result_pass.passed assert not result_fail.passed + assert not result_fail_status.passed + assert not result_fail_file.passed + assert not result_fail_file_not_exist.passed + assert not result_fail_file_multiple.passed + assert not result_fail_timeout.passed - def test_failed(self, result_pass, result_fail): + def test_failed(self, result_pass, result_fail, result_fail_status, + result_fail_file, result_fail_file_not_exist, result_fail_file_multiple, result_fail_timeout): assert not result_pass.failed assert result_fail.failed + assert result_fail_status.failed + assert result_fail_file.failed + assert result_fail_file_not_exist.failed + assert result_fail_file_multiple.failed + assert result_fail_timeout.failed + + @pytest.mark.parametrize("term_cols", range(40, 300, 40)) + def test_summarize(self, result_pass, result_fail, result_fail_status, + result_fail_file, result_fail_file_not_exist, result_fail_timeout, term_cols): + with config_context(show_range=False, term_cols=term_cols): + assert f"{'echo bonjour':{term_cols - 7}} [PASS]" == result_pass.summarize(-1) + assert f"{'echo bonjour':{term_cols - 7}} [FAIL]" == result_fail.summarize(-1) + assert f"{'echo bonjour':{term_cols - 7}} [FAIL]" == result_fail_status.summarize(-1) + assert f"{'echo bonjour > foo':{term_cols - 7}} [FAIL]" == result_fail_file.summarize(-1) + assert f"{'echo bonjour > foo':{term_cols - 7}} [FAIL]" == result_fail_file_not_exist.summarize(-1) + assert f"{'echo bonjour':{term_cols - 7}} [FAIL]" == result_fail_timeout.summarize(-1) + with config_context(show_range=True, term_cols=term_cols): + assert f" 1: {'echo bonjour':{term_cols - 11}} [PASS]" == result_pass.summarize(1) + assert f" 1: {'echo bonjour':{term_cols - 11}} [FAIL]" == result_fail.summarize(1) + assert f" 1: {'echo bonjour':{term_cols - 11}} [FAIL]" == result_fail_status.summarize(1) + assert f" 1: {'echo bonjour > foo':{term_cols - 11}} [FAIL]" == result_fail_file.summarize(1) + assert f" 1: {'echo bonjour > foo':{term_cols - 11}} [FAIL]" == result_fail_file_not_exist.summarize(1) + assert f" 1: {'echo bonjour':{term_cols - 11}} [FAIL]" == result_fail_timeout.summarize(1) + assert f"99: {'echo bonjour':{term_cols - 11}} [PASS]" == result_pass.summarize(99) + assert f"99: {'echo bonjour':{term_cols - 11}} [FAIL]" == result_fail.summarize(99) + assert f"99: {'echo bonjour':{term_cols - 11}} [FAIL]" == result_fail_status.summarize(99) + assert f"99: {'echo bonjour > foo':{term_cols - 11}} [FAIL]" == result_fail_file.summarize(99) + assert f"99: {'echo bonjour > foo':{term_cols - 11}} [FAIL]" == result_fail_file_not_exist.summarize(99) + assert f"99: {'echo bonjour':{term_cols - 11}} [FAIL]" == result_fail_timeout.summarize(99) + assert f"100: {'echo bonjour':{term_cols - 12}} [PASS]" == result_pass.summarize(100) + assert f"100: {'echo bonjour':{term_cols - 12}} [FAIL]" == result_fail.summarize(100) + assert f"100: {'echo bonjour':{term_cols - 12}} [FAIL]" == result_fail_status.summarize(100) + assert f"100: {'echo bonjour > foo':{term_cols - 12}} [FAIL]" == result_fail_file.summarize(100) + assert f"100: {'echo bonjour > foo':{term_cols - 12}} [FAIL]" == result_fail_file_not_exist.summarize(100) + assert f"100: {'echo bonjour':{term_cols - 12}} [FAIL]" == result_fail_timeout.summarize(100) + + def test_repr(self, result_fail, result_fail_status, result_fail_file, + result_fail_file_not_exist, result_fail_file_multiple, result_fail_timeout): + assert """\ +|> WITH echo bonjour +|----------------------------------------EXPECTED------------------------------- +bonjour +|----------------------------------------ACTUAL--------------------------------- +aurevoir +""" == result_fail.__repr__() + assert """\ +|> WITH echo bonjour +| STATUS: expected 0 actual 1 +""" == result_fail_status.__repr__() + assert """\ +|> WITH echo bonjour > foo +|# FILE foo +|----------------------------------------EXPECTED------------------------------- +bonjour +|----------------------------------------ACTUAL--------------------------------- +aurevoir +""" == result_fail_file.__repr__() + assert """\ +|> WITH echo bonjour > foo +|# FILE foo +|----------------------------------------EXPECTED------------------------------- +bonjour +|----------------------------------------ACTUAL--------------------------------- +FROM TEST: File not created +""" == result_fail_file_not_exist.__repr__() + assert """\ +|> WITH echo bonjour > foo > bar +|# FILE foo +|----------------------------------------EXPECTED------------------------------- +|----------------------------------------ACTUAL--------------------------------- +bonjour +|# FILE bar +|----------------------------------------EXPECTED------------------------------- +bonjour +|----------------------------------------ACTUAL--------------------------------- +FROM TEST: File not created +""" == result_fail_file_multiple.__repr__() + assert """\ +|> WITH echo bonjour +TIMEOUT +""" == result_fail_timeout.__repr__() + + def test_expected_is_timeout(self): + with pytest.raises(RuntimeError): + Result("echo bonjour", [], CapturedTimeout(), CapturedCommand("bonjour", 0, [])) + + +class TestLeakResult: + @pytest.fixture + def result_leak_pass(self): + valgrind_output = r""" +==33584== Memcheck, a memory error detector +==33584== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==33584== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info +==33584== Command: ./minishell -c echo\ bonjour +==33584== +bonjour +==33584== +==33584== HEAP SUMMARY: +==33584== in use at exit: 0 bytes in 0 blocks +==33584== total heap usage: 88 allocs, 88 frees, 102,949 bytes allocated +==33584== +==33584== LEAK SUMMARY: +==33584== definitely lost: 0 bytes in 0 blocks +==33584== indirectly lost: 0 bytes in 0 blocks +==33584== possibly lost: 0 bytes in 0 blocks +==33584== still reachable: 0 bytes in 0 blocks +==33584== suppressed: 0 bytes in 0 blocks +==33584== +==33584== For lists of detected and suppressed errors, rerun with: -s +==33584== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) +""".lstrip("\n") + return LeakResult("echo bonjour", CapturedCommand(valgrind_output, 0, [])) + + @pytest.fixture + def result_leak_fail_definitive(self): + valgrind_output = r""" +==32896== Memcheck, a memory error detector +==32896== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==32896== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info +==32896== Command: ./minishell -c echo\ bonjour +==32896== +bonjour +==32896== +==32896== HEAP SUMMARY: +==32896== in use at exit: 3,787 bytes in 75 blocks +==32896== total heap usage: 88 allocs, 13 frees, 102,949 bytes allocated +==32896== +==32896== 3,787 (24 direct, 3,763 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5 +==32896== at 0x483E77F: malloc (vg_replace_malloc.c:307) +==32896== by 0x10D317: ft_vecnew (ft_vecnew.c:26) +==32896== by 0x109382: env_from_array (env.c:33) +==32896== by 0x1091C1: main (main.c:111) +==32896== +==32896== LEAK SUMMARY: +==32896== definitely lost: 24 bytes in 1 blocks +==32896== indirectly lost: 0 bytes in 0 blocks +==32896== possibly lost: 0 bytes in 0 blocks +==32896== still reachable: 0 bytes in 0 blocks +==32896== suppressed: 0 bytes in 0 blocks +==32896== +==32896== For lists of detected and suppressed errors, rerun with: -s +==32896== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) +""".lstrip("\n") + return LeakResult("echo bonjour", CapturedCommand(valgrind_output, 0, [])) + + @pytest.fixture + def result_leak_fail_indirect(self): + valgrind_output = r""" +==32896== Memcheck, a memory error detector +==32896== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==32896== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info +==32896== Command: ./minishell -c echo\ bonjour +==32896== +bonjour +==32896== +==32896== HEAP SUMMARY: +==32896== in use at exit: 3,787 bytes in 75 blocks +==32896== total heap usage: 88 allocs, 13 frees, 102,949 bytes allocated +==32896== +==32896== 3,787 (24 direct, 3,763 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5 +==32896== at 0x483E77F: malloc (vg_replace_malloc.c:307) +==32896== by 0x10D317: ft_vecnew (ft_vecnew.c:26) +==32896== by 0x109382: env_from_array (env.c:33) +==32896== by 0x1091C1: main (main.c:111) +==32896== +==32896== LEAK SUMMARY: +==32896== definitely lost: 0 bytes in 0 blocks +==32896== indirectly lost: 3,763 bytes in 74 blocks +==32896== possibly lost: 0 bytes in 0 blocks +==32896== still reachable: 0 bytes in 0 blocks +==32896== suppressed: 0 bytes in 0 blocks +==32896== +==32896== For lists of detected and suppressed errors, rerun with: -s +==32896== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) +""".lstrip("\n") + return LeakResult("echo bonjour", CapturedCommand(valgrind_output, 0, [])) + + @pytest.fixture + def result_leak_fail_both(self): + valgrind_output = r""" +==32896== Memcheck, a memory error detector +==32896== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==32896== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info +==32896== Command: ./minishell -c echo\ bonjour +==32896== +bonjour +==32896== +==32896== HEAP SUMMARY: +==32896== in use at exit: 3,787 bytes in 75 blocks +==32896== total heap usage: 88 allocs, 13 frees, 102,949 bytes allocated +==32896== +==32896== 3,787 (24 direct, 3,763 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5 +==32896== at 0x483E77F: malloc (vg_replace_malloc.c:307) +==32896== by 0x10D317: ft_vecnew (ft_vecnew.c:26) +==32896== by 0x109382: env_from_array (env.c:33) +==32896== by 0x1091C1: main (main.c:111) +==32896== +==32896== LEAK SUMMARY: +==32896== definitely lost: 24 bytes in 1 blocks +==32896== indirectly lost: 3,763 bytes in 74 blocks +==32896== possibly lost: 0 bytes in 0 blocks +==32896== still reachable: 0 bytes in 0 blocks +==32896== suppressed: 0 bytes in 0 blocks +==32896== +==32896== For lists of detected and suppressed errors, rerun with: -s +==32896== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) +""".lstrip("\n") + return LeakResult("echo bonjour", CapturedCommand(valgrind_output, 0, [])) + + @pytest.fixture + def result_leak_pass_no_count(self): + valgrind_output = r""" +==33584== Memcheck, a memory error detector +==33584== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==33584== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info +==33584== Command: ./minishell -c echo\ bonjour +==33584== +bonjour +==33584== +==33584== HEAP SUMMARY: +==33584== in use at exit: 0 bytes in 0 blocks +==33584== total heap usage: 88 allocs, 88 frees, 102,949 bytes allocated +==33584== +==33584== All heap blocks were freed -- no leaks are possible +==33584== +==33584== For lists of detected and suppressed errors, rerun with: -s +==33584== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) +""".lstrip("\n") + return LeakResult("echo bonjour", CapturedCommand(valgrind_output, 0, [])) + + @pytest.fixture + def result_leak_fail_timeout(self): + return LeakResult("echo bonjour", CapturedTimeout()) + + def test_passed(self, result_leak_pass, result_leak_fail_indirect, result_leak_fail_definitive, + result_leak_fail_both, result_leak_pass_no_count, result_leak_fail_timeout): + assert result_leak_pass.passed + assert result_leak_pass_no_count.passed + assert not result_leak_fail_indirect.passed + assert not result_leak_fail_definitive.passed + assert not result_leak_fail_both.passed + assert not result_leak_fail_timeout.passed + + def test_failed(self, result_leak_pass, result_leak_fail_indirect, result_leak_fail_definitive, + result_leak_fail_both, result_leak_pass_no_count, result_leak_fail_timeout): + assert not result_leak_pass.failed + assert not result_leak_pass_no_count.failed + assert result_leak_fail_indirect.failed + assert result_leak_fail_definitive.failed + assert result_leak_fail_both.failed + assert result_leak_fail_timeout.failed + + @pytest.mark.parametrize("term_cols", range(40, 300, 40)) + def test_summarize(self, result_leak_pass, result_leak_fail_indirect, result_leak_fail_definitive, + result_leak_fail_both, result_leak_pass_no_count, result_leak_fail_timeout, term_cols): + with config_context(show_range=False, term_cols=term_cols): + assert f"{'echo bonjour':{term_cols - 7}} [PASS]" == result_leak_pass.summarize(-1) + assert f"{'echo bonjour':{term_cols - 7}} [PASS]" == result_leak_pass_no_count.summarize(-1) + assert f"{'echo bonjour':{term_cols - 7}} [FAIL]" == result_leak_fail_definitive.summarize(-1) + assert f"{'echo bonjour':{term_cols - 7}} [FAIL]" == result_leak_fail_indirect.summarize(-1) + assert f"{'echo bonjour':{term_cols - 7}} [FAIL]" == result_leak_fail_both.summarize(-1) + assert f"{'echo bonjour':{term_cols - 7}} [FAIL]" == result_leak_fail_timeout.summarize(-1) + with config_context(show_range=True, term_cols=term_cols): + assert f" 1: {'echo bonjour':{term_cols - 11}} [PASS]" == result_leak_pass.summarize(1) + assert f" 1: {'echo bonjour':{term_cols - 11}} [PASS]" == result_leak_pass_no_count.summarize(1) + assert f" 1: {'echo bonjour':{term_cols - 11}} [FAIL]" == result_leak_fail_definitive.summarize(1) + assert f" 1: {'echo bonjour':{term_cols - 11}} [FAIL]" == result_leak_fail_indirect.summarize(1) + assert f" 1: {'echo bonjour':{term_cols - 11}} [FAIL]" == result_leak_fail_both.summarize(1) + assert f" 1: {'echo bonjour':{term_cols - 11}} [FAIL]" == result_leak_fail_timeout.summarize(1) + assert f"99: {'echo bonjour':{term_cols - 11}} [PASS]" == result_leak_pass.summarize(99) + assert f"99: {'echo bonjour':{term_cols - 11}} [PASS]" == result_leak_pass_no_count.summarize(99) + assert f"99: {'echo bonjour':{term_cols - 11}} [FAIL]" == result_leak_fail_definitive.summarize(99) + assert f"99: {'echo bonjour':{term_cols - 11}} [FAIL]" == result_leak_fail_indirect.summarize(99) + assert f"99: {'echo bonjour':{term_cols - 11}} [FAIL]" == result_leak_fail_both.summarize(99) + assert f"99: {'echo bonjour':{term_cols - 11}} [FAIL]" == result_leak_fail_timeout.summarize(99) + assert f"100: {'echo bonjour':{term_cols - 12}} [PASS]" == result_leak_pass.summarize(100) + assert f"100: {'echo bonjour':{term_cols - 12}} [PASS]" == result_leak_pass_no_count.summarize(100) + assert f"100: {'echo bonjour':{term_cols - 12}} [FAIL]" == result_leak_fail_definitive.summarize(100) + assert f"100: {'echo bonjour':{term_cols - 12}} [FAIL]" == result_leak_fail_indirect.summarize(100) + assert f"100: {'echo bonjour':{term_cols - 12}} [FAIL]" == result_leak_fail_both.summarize(100) + assert f"100: {'echo bonjour':{term_cols - 12}} [FAIL]" == result_leak_fail_timeout.summarize(100) + + def test_repr(self, result_leak_fail_indirect, result_leak_fail_definitive, result_leak_fail_both, result_leak_fail_timeout): + assert r""" +|> WITH echo bonjour +==32896== Memcheck, a memory error detector +==32896== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==32896== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info +==32896== Command: ./minishell -c echo\ bonjour +==32896== +bonjour +==32896== +==32896== HEAP SUMMARY: +==32896== in use at exit: 3,787 bytes in 75 blocks +==32896== total heap usage: 88 allocs, 13 frees, 102,949 bytes allocated +==32896== +==32896== 3,787 (24 direct, 3,763 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5 +==32896== at 0x483E77F: malloc (vg_replace_malloc.c:307) +==32896== by 0x10D317: ft_vecnew (ft_vecnew.c:26) +==32896== by 0x109382: env_from_array (env.c:33) +==32896== by 0x1091C1: main (main.c:111) +==32896== +==32896== LEAK SUMMARY: +==32896== definitely lost: 24 bytes in 1 blocks +==32896== indirectly lost: 0 bytes in 0 blocks +==32896== possibly lost: 0 bytes in 0 blocks +==32896== still reachable: 0 bytes in 0 blocks +==32896== suppressed: 0 bytes in 0 blocks +==32896== +==32896== For lists of detected and suppressed errors, rerun with: -s +==32896== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) +""".lstrip("\n") == result_leak_fail_definitive.__repr__() + assert r""" +|> WITH echo bonjour +==32896== Memcheck, a memory error detector +==32896== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==32896== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info +==32896== Command: ./minishell -c echo\ bonjour +==32896== +bonjour +==32896== +==32896== HEAP SUMMARY: +==32896== in use at exit: 3,787 bytes in 75 blocks +==32896== total heap usage: 88 allocs, 13 frees, 102,949 bytes allocated +==32896== +==32896== 3,787 (24 direct, 3,763 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5 +==32896== at 0x483E77F: malloc (vg_replace_malloc.c:307) +==32896== by 0x10D317: ft_vecnew (ft_vecnew.c:26) +==32896== by 0x109382: env_from_array (env.c:33) +==32896== by 0x1091C1: main (main.c:111) +==32896== +==32896== LEAK SUMMARY: +==32896== definitely lost: 0 bytes in 0 blocks +==32896== indirectly lost: 3,763 bytes in 74 blocks +==32896== possibly lost: 0 bytes in 0 blocks +==32896== still reachable: 0 bytes in 0 blocks +==32896== suppressed: 0 bytes in 0 blocks +==32896== +==32896== For lists of detected and suppressed errors, rerun with: -s +==32896== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) +""".lstrip("\n") == result_leak_fail_indirect.__repr__() + assert r""" +|> WITH echo bonjour +==32896== Memcheck, a memory error detector +==32896== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==32896== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info +==32896== Command: ./minishell -c echo\ bonjour +==32896== +bonjour +==32896== +==32896== HEAP SUMMARY: +==32896== in use at exit: 3,787 bytes in 75 blocks +==32896== total heap usage: 88 allocs, 13 frees, 102,949 bytes allocated +==32896== +==32896== 3,787 (24 direct, 3,763 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5 +==32896== at 0x483E77F: malloc (vg_replace_malloc.c:307) +==32896== by 0x10D317: ft_vecnew (ft_vecnew.c:26) +==32896== by 0x109382: env_from_array (env.c:33) +==32896== by 0x1091C1: main (main.c:111) +==32896== +==32896== LEAK SUMMARY: +==32896== definitely lost: 24 bytes in 1 blocks +==32896== indirectly lost: 3,763 bytes in 74 blocks +==32896== possibly lost: 0 bytes in 0 blocks +==32896== still reachable: 0 bytes in 0 blocks +==32896== suppressed: 0 bytes in 0 blocks +==32896== +==32896== For lists of detected and suppressed errors, rerun with: -s +==32896== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) +""".lstrip("\n") == result_leak_fail_both.__repr__() + assert r""" +|> WITH echo bonjour +TIMEOUT +""".lstrip("\n") == result_leak_fail_timeout.__repr__() + @pytest.mark.parametrize( + "output", + [ + "", + "foo", + "asdlfjas;dkljfaslkdjflas", + "==32896== definitely lost: bytes in 1 blocks" + "==32896== definitely lost: a bytes in 1 blocks" + "==32896== definitely lost: _ bytes in 1 blocks" + "==32896== indirectly lost: bytes in 1 blocks" + "==32896== indirectly lost: a bytes in 1 blocks" + "==32896== indirectly lost: _ bytes in 1 blocks" + "==32896== bonjour lost: 1 bytes in 1 blocks" + ] + ) + def test_parsing_error(self, output): + with pytest.raises(LeakResultException) as e: + LeakResult("echo bonjour", CapturedCommand(output, 0, [])).passed + assert "echo bonjour" == e.value._cmd + assert output == e.value._captured.output + assert f"valgrind output parsing failed for `echo bonjour`:\n{output}" == e.value.__str__() -- cgit