Debian Codegraph @

tests/malformed-diff-headers/run-test

raw
1 #!/bin/sh
2
3 # Test malformed diff headers and error handling paths
4 # This test covers the flush_continue code path in filterdiff
5
6 . ${top_srcdir-.}/tests/common.sh
7
8 # Test 1: Malformed diff header (triggers flush_continue path with verbose output)
9 cat << EOF > malformed-diff.patch
10 diff --git a/test.txt b/test.txt
11 some invalid header line here
12 EOF
13
14 # This should trigger the flush_continue path and output the malformed headers in verbose mode
15 ${FILTERDIFF} --verbose malformed-diff.patch 2>errors1 >result1 || exit 1
16 [ -s errors1 ] && exit 1
17
18 # Should output the original headers due to verbose mode
19 grep -q "diff --git a/test.txt b/test.txt" result1 || exit 1
20 grep -q "some invalid header line here" result1 || exit 1
21
22 # Test 2: Same malformed diff but with exclude patterns (different code path)
23 ${FILTERDIFF} --verbose -x "*.nonexistent" malformed-diff.patch 2>errors2 >result2 || exit 1
24 [ -s errors2 ] && exit 1
25
26 # Should also output the headers due to exclude pattern + verbose
27 grep -q "diff --git a/test.txt b/test.txt" result2 || exit 1
28 grep -q "some invalid header line here" result2 || exit 1
29
30 # Test 3: Malformed diff with clean option (should NOT output headers)
31 # Note: --verbose and --clean are mutually exclusive, so we test clean separately
32 ${FILTERDIFF} --clean malformed-diff.patch 2>errors3 >result3 || exit 1
33 [ -s errors3 ] && exit 1
34
35 # Should NOT contain the malformed header due to --clean
36 [ -s result3 ] && exit 1
37
38 # Test 4: Multiple malformed headers
39 cat << EOF > multi-malformed.patch
40 diff --git a/file1.txt b/file1.txt
41 invalid line 1
42 invalid line 2
43 diff --git a/file2.txt b/file2.txt
44 another invalid line
45 EOF
46
47 ${FILTERDIFF} --verbose multi-malformed.patch 2>errors4 >result4 || exit 1
48 [ -s errors4 ] && exit 1
49
50 # Should contain all the malformed content
51 grep -q "invalid line 1" result4 || exit 1
52 grep -q "invalid line 2" result4 || exit 1
53 grep -q "another invalid line" result4 || exit 1
54
55 exit 0