#!/bin/sh

# Test flipdiff with /dev/null automatic -p detection
# This tests that flipdiff can auto-detect -p values when dealing with /dev/null

. ${top_srcdir-.}/tests/common.sh

# Create first patch (creates a file)
cat << EOF > patch1
--- /dev/null
+++ b/testfile.c
@@ -0,0 +1,2 @@
+#include <stdio.h>
+int main() { return 0; }
EOF

# Create second patch (modifies the same file)
cat << EOF > patch2
--- a/testfile.c
+++ b/testfile.c
@@ -1,2 +1,3 @@
 #include <stdio.h>
+#include <stdlib.h>
 int main() { return 0; }
EOF

# Expected flipdiff output (should auto-detect -p1)
cat << EOF > expected
--- a/testfile.c
+++ b/testfile.c
@@ -0,0 +1 @@
+#include <stdlib.h>

=== 8< === cut here === 8< ===

--- /dev/null
+++ b/testfile.c
@@ -1 +1,3 @@
+#include <stdio.h>
 #include <stdlib.h>
+int main() { return 0; }
EOF

# Run flipdiff - should auto-detect -p1 and produce flipped patches
${FLIPDIFF} patch1 patch2 2>errors >actual || exit 1
[ -s errors ] && exit 1

# Compare the actual output with expected
diff -u expected actual || exit 1

exit 0
