| 2678 | |
| 2679 | |
| 2680 | def test_outputfile(tmp_path): # #14051 |
| 2681 | test_file = tmp_path / 'test.cpp' |
| 2682 | out_file = tmp_path / 'out.txt' |
| 2683 | with open(test_file, 'wt') as f: |
| 2684 | f.write( |
| 2685 | """ |
| 2686 | int main() |
| 2687 | { |
| 2688 | int x = 1 / 0; |
| 2689 | } |
| 2690 | """) |
| 2691 | |
| 2692 | args = [ |
| 2693 | '-q', |
| 2694 | '--output-file={}'.format(out_file), |
| 2695 | str(test_file) |
| 2696 | ] |
| 2697 | |
| 2698 | out_exp = [ |
| 2699 | '{}:4:15: error: Division by zero. [zerodiv]'.format(test_file), |
| 2700 | ' int x = 1 / 0;', |
| 2701 | ' ^', |
| 2702 | ] |
| 2703 | |
| 2704 | exitcode, stdout, stderr = cppcheck(args) |
| 2705 | assert exitcode == 0, stdout |
| 2706 | assert stdout == '' |
| 2707 | assert stderr == '' |
| 2708 | |
| 2709 | with open(out_file, 'rt') as f: |
| 2710 | out_text = f.read() |
| 2711 | |
| 2712 | assert out_text.splitlines() == out_exp |
| 2713 | |
| 2714 | |
| 2715 | def test_internal_error_loc_int(tmp_path): |