Repository: MarvinJWendt/testza
Pull request #133 (2022-04-07 10:50:40)

Fixed line numbers starting with `0` instead of `1`


Patch:
diff --git a/README.md b/README.md
index 01ea454..833dc2b 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@
 </a>
 
 <a href="https://codecov.io/gh/MarvinJWendt/testza">
-<!-- unittestcount:start --><img src="https://img.shields.io/badge/Unit_Tests-3209-magenta?style=flat-square" alt="Unit test count"><!-- unittestcount:end -->
+<!-- unittestcount:start --><img src="https://img.shields.io/badge/Unit_Tests-3207-magenta?style=flat-square" alt="Unit test count"><!-- unittestcount:end -->
 </a>
   
 <a href="https://pkg.go.dev/github.com/MarvinJWendt/testza" target="_blank">
diff --git a/internal/fail-printer.go b/internal/fail-printer.go
index ed057c4..bcc563e 100644
--- a/internal/fail-printer.go
+++ b/internal/fail-printer.go
@@ -129,12 +129,13 @@ func FailS(message string, objects Objects, args ...interface{}) string {
 		}
 	}
 
+	// Prepend line numbers
 	newMessage := "\n"
 	lines := strings.Split(message, "\n")
 	for i, line := range lines {
 		if !(i == 0 && strings.TrimSpace(line) == "") && i < len(lines)-1 {
 			if LineNumbersEnabled {
-				newMessage += pterm.FgGray.Sprintf("%4d| ", i) + line + "\n" + pterm.Reset.Sprint()
+				newMessage += pterm.FgGray.Sprintf("%4d| ", i+1) + line + "\n" + pterm.Reset.Sprint()
 			} else {
 				newMessage += line + "\n"
 			}


Test patch:
diff --git a/testdata/snapshots/TestOutputConsistency/failed_test.testza b/testdata/snapshots/TestOutputConsistency/failed_test.testza
old mode 100755
new mode 100644
index e57ace0..f52cd1a
--- a/testdata/snapshots/TestOutputConsistency/failed_test.testza
+++ b/testdata/snapshots/TestOutputConsistency/failed_test.testza
@@ -1,1 +1,1 @@
-(string) (len=215) "\n\n   0| Two objects that should be equal, are not equal.\n   1| \n   2| Expected:\n   3| (bool) true\n   4| \n   5| Actual:\n   6| (bool) false\n   7| \n   8| Difference:\n   9| (1. -) (bool) true\n  10| (1. +) (bool) false\n\n"
+(string) (len=215) "\n\n   1| Two objects that should be equal, are not equal.\n   2| \n   3| Expected:\n   4| (bool) true\n   5| \n   6| Actual:\n   7| (bool) false\n   8| \n   9| Difference:\n  10| (1. -) (bool) true\n  11| (1. +) (bool) false\n\n"
diff --git a/testdata/snapshots/TestOutputConsistency/failed_test_many_matching_lines.testza b/testdata/snapshots/TestOutputConsistency/failed_test_many_matching_lines.testza
old mode 100755
new mode 100644
index 6e72c00..13c0673
--- a/testdata/snapshots/TestOutputConsistency/failed_test_many_matching_lines.testza
+++ b/testdata/snapshots/TestOutputConsistency/failed_test_many_matching_lines.testza
@@ -1,1 +1,1 @@
-(string) (len=1041) "\n\n   0| Two objects that should be equal, are not equal.\n   1| \n   2| Expected:\n   3| (string) (len=139) \"0\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12\\n13\\n14\\n15\\n16\\n17\\n18\\n19\\n20\\n21\\n22\\n23\\n24\\n25\\n26\\n27\\n28\\n29\\n30\\n31\\n32\\n33\\n34\\n35\\n36\\n37\\n38\\n39\\n40\\n41\\n42\\n43\\n44\\n45\\n46\\n47\\n48\\n49\"\n   4| \n   5| Actual:\n   6| (string) (len=147) \"0\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\nhello\\n11\\n12\\n13\\n14\\n15\\n16\\n17\\n18\\n19\\nworld\\n21\\n22\\n23\\n24\\n25\\n26\\n27\\n28\\n29\\nfoo\\n31\\n32\\n33\\n34\\n35\\n36\\n37\\n38\\n39\\nbar\\n41\\n42\\n43\\n44\\n45\\n46\\n47\\n48\\n49\"\n   7| \n   8| Difference:\n   9| [...]\n  10| ( 9. #) 8\n  11| (10. #) 9\n  12| (11. -) 10\n  13| (11. +) hello\n  14| (12. #) 11\n  15| (13. #) 12\n  16| [...]\n  17| (19. #) 18\n  18| (20. #) 19\n  19| (21. -) 20\n  20| (21. +) world\n  21| (22. #) 21\n  22| (23. #) 22\n  23| [...]\n  24| (29. #) 28\n  25| (30. #) 29\n  26| (31. -) 30\n  27| (31. +) foo\n  28| (32. #) 31\n  29| (33. #) 32\n  30| [...]\n  31| (39. #) 38\n  32| (40. #) 39\n  33| (41. -) 40\n  34| (41. +) bar\n  35| (42. #) 41\n  36| (43. #) 42\n  37| [...]\n\n"
+(string) (len=1041) "\n\n   1| Two objects that should be equal, are not equal.\n   2| \n   3| Expected:\n   4| (string) (len=139) \"0\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12\\n13\\n14\\n15\\n16\\n17\\n18\\n19\\n20\\n21\\n22\\n23\\n24\\n25\\n26\\n27\\n28\\n29\\n30\\n31\\n32\\n33\\n34\\n35\\n36\\n37\\n38\\n39\\n40\\n41\\n42\\n43\\n44\\n45\\n46\\n47\\n48\\n49\"\n   5| \n   6| Actual:\n   7| (string) (len=147) \"0\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\nhello\\n11\\n12\\n13\\n14\\n15\\n16\\n17\\n18\\n19\\nworld\\n21\\n22\\n23\\n24\\n25\\n26\\n27\\n28\\n29\\nfoo\\n31\\n32\\n33\\n34\\n35\\n36\\n37\\n38\\n39\\nbar\\n41\\n42\\n43\\n44\\n45\\n46\\n47\\n48\\n49\"\n   8| \n   9| Difference:\n  10| [...]\n  11| ( 9. #) 8\n  12| (10. #) 9\n  13| (11. -) 10\n  14| (11. +) hello\n  15| (12. #) 11\n  16| (13. #) 12\n  17| [...]\n  18| (19. #) 18\n  19| (20. #) 19\n  20| (21. -) 20\n  21| (21. +) world\n  22| (22. #) 21\n  23| (23. #) 22\n  24| [...]\n  25| (29. #) 28\n  26| (30. #) 29\n  27| (31. -) 30\n  28| (31. +) foo\n  29| (32. #) 31\n  30| (33. #) 32\n  31| [...]\n  32| (39. #) 38\n  33| (40. #) 39\n  34| (41. -) 40\n  35| (41. +) bar\n  36| (42. #) 41\n  37| (43. #) 42\n  38| [...]\n\n"
diff --git a/testdata/snapshots/TestOutputConsistency/failed_test_newline_end.testza b/testdata/snapshots/TestOutputConsistency/failed_test_newline_end.testza
old mode 100755
new mode 100644
index 3d706a7..ef9fa82
--- a/testdata/snapshots/TestOutputConsistency/failed_test_newline_end.testza
+++ b/testdata/snapshots/TestOutputConsistency/failed_test_newline_end.testza
@@ -1,1 +1,1 @@
-(string) (len=227) "\n\n   0| Two objects that should be equal, are not equal.\n   1| \n   2| Expected:\n   3| (string) (len=1) \"1\"\n   4| \n   5| Actual:\n   6| (string) (len=2) \"1\\n\"\n   7| \n   8| Difference:\n   9| (1. -) 1\n  10| (1. +) 1\n  11| (2. +) \n\n"
+(string) (len=227) "\n\n   1| Two objects that should be equal, are not equal.\n   2| \n   3| Expected:\n   4| (string) (len=1) \"1\"\n   5| \n   6| Actual:\n   7| (string) (len=2) \"1\\n\"\n   8| \n   9| Difference:\n  10| (1. -) 1\n  11| (1. +) 1\n  12| (2. +) \n\n"
diff --git a/testdata/snapshots/TestOutputConsistency/failed_test_newline_start.testza b/testdata/snapshots/TestOutputConsistency/failed_test_newline_start.testza
old mode 100755
new mode 100644
index 32098de..28459b6
--- a/testdata/snapshots/TestOutputConsistency/failed_test_newline_start.testza
+++ b/testdata/snapshots/TestOutputConsistency/failed_test_newline_start.testza
@@ -1,1 +1,1 @@
-(string) (len=212) "\n\n   0| Two objects that should be equal, are not equal.\n   1| \n   2| Expected:\n   3| (string) (len=1) \"1\"\n   4| \n   5| Actual:\n   6| (string) (len=2) \"\\n1\"\n   7| \n   8| Difference:\n   9| (1. +) \n  10| (2. #) 1\n\n"
+(string) (len=212) "\n\n   1| Two objects that should be equal, are not equal.\n   2| \n   3| Expected:\n   4| (string) (len=1) \"1\"\n   5| \n   6| Actual:\n   7| (string) (len=2) \"\\n1\"\n   8| \n   9| Difference:\n  10| (1. +) \n  11| (2. #) 1\n\n"
diff --git a/testdata/snapshots/TestOutputConsistency/failed_test_newlines.testza b/testdata/snapshots/TestOutputConsistency/failed_test_newlines.testza
old mode 100755
new mode 100644
index 09d085d..f405e36
--- a/testdata/snapshots/TestOutputConsistency/failed_test_newlines.testza
+++ b/testdata/snapshots/TestOutputConsistency/failed_test_newlines.testza
@@ -1,1 +1,1 @@
-(string) (len=404) "\n\n   0| Two objects that should be equal, are not equal.\n   1| \n   2| Expected:\n   3| (string) (len=10) \"1234567890\"\n   4| \n   5| Actual:\n   6| (string) (len=19) \"1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n0\"\n   7| \n   8| Difference:\n   9| ( 1. -) 1234567890\n  10| ( 1. +) 1\n  11| ( 2. +) 2\n  12| ( 3. +) 3\n  13| ( 4. +) 4\n  14| ( 5. +) 5\n  15| ( 6. +) 6\n  16| ( 7. +) 7\n  17| ( 8. +) 8\n  18| ( 9. +) 9\n  19| (10. +) 0\n\n"
+(string) (len=404) "\n\n   1| Two objects that should be equal, are not equal.\n   2| \n   3| Expected:\n   4| (string) (len=10) \"1234567890\"\n   5| \n   6| Actual:\n   7| (string) (len=19) \"1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n0\"\n   8| \n   9| Difference:\n  10| ( 1. -) 1234567890\n  11| ( 1. +) 1\n  12| ( 2. +) 2\n  13| ( 3. +) 3\n  14| ( 4. +) 4\n  15| ( 5. +) 5\n  16| ( 6. +) 6\n  17| ( 7. +) 7\n  18| ( 8. +) 8\n  19| ( 9. +) 9\n  20| (10. +) 0\n\n"
diff --git a/testdata/snapshots/TestOutputConsistency/failed_test_slice.testza b/testdata/snapshots/TestOutputConsistency/failed_test_slice.testza
old mode 100755
new mode 100644
index 9dd6c1d..8d15677
--- a/testdata/snapshots/TestOutputConsistency/failed_test_slice.testza
+++ b/testdata/snapshots/TestOutputConsistency/failed_test_slice.testza
@@ -1,1 +1,1 @@
-(string) (len=393) "\n\n   0| Two objects that should be equal, are not equal.\n   1| \n   2| Expected:\n   3| (interface {}) <nil>\n   4| \n   5| Actual:\n   6| ([]int) (len=3 cap=3) {\n   7|  (int) 1,\n   8|  (int) 2,\n   9|  (int) 3\n  10| }\n  11| \n  12| Difference:\n  13| (1. -) (interface {}) <nil>\n  14| (1. +) ([]int) (len=3 cap=3) {\n  15| (2. +)  (int) 1,\n  16| (3. +)  (int) 2,\n  17| (4. +)  (int) 3\n  18| (5. +) }\n\n"
+(string) (len=393) "\n\n   1| Two objects that should be equal, are not equal.\n   2| \n   3| Expected:\n   4| (interface {}) <nil>\n   5| \n   6| Actual:\n   7| ([]int) (len=3 cap=3) {\n   8|  (int) 1,\n   9|  (int) 2,\n  10|  (int) 3\n  11| }\n  12| \n  13| Difference:\n  14| (1. -) (interface {}) <nil>\n  15| (1. +) ([]int) (len=3 cap=3) {\n  16| (2. +)  (int) 1,\n  17| (3. +)  (int) 2,\n  18| (4. +)  (int) 3\n  19| (5. +) }\n\n"
diff --git a/testdata/snapshots/TestOutputConsistency/failed_test_string.testza b/testdata/snapshots/TestOutputConsistency/failed_test_string.testza
old mode 100755
new mode 100644
index 85b10ad..4ff6d51
--- a/testdata/snapshots/TestOutputConsistency/failed_test_string.testza
+++ b/testdata/snapshots/TestOutputConsistency/failed_test_string.testza
@@ -1,1 +1,1 @@
-(string) (len=1484) "\n\n   0| Two objects that should be equal, are not equal.\n   1| \n   2| Expected:\n   3| (string) (len=297) \"Lorem ipsum dolor sit amet, consectetur adipiscing elit.\\nFusce consectetur quam id turpis blandit, pulvinar fermentum justo sollicitudin.\\nCurabitur vehicula eros posuere efficitur egestas.\\n\\nDuis et lectus in nisi mattis convallis non a odio.\\nProin pulvinar felis consectetur condimentum tincidunt.\"\n   4| \n   5| Actual:\n   6| (string) (len=302) \"Lorem ipsum sit amet, consechbtetur adipiscing elit.z\\n\\nzFusce consecetur quam iod turpis blandit, pulvnar fermentum justo sollicitudin.\\nCurdabitur veicular eros posuere hello efficitulr egestas.\\nDuis et lectus in nisi mattis convallis non a odio.\\nProin puvinar feliss consectetur codiementum tincidunt.\"\n   7| \n   8| Difference:\n   9| (1. -) Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n  10| (2. -) Fusce consectetur quam id turpis blandit, pulvinar fermentum justo sollicitudin.\n  11| (3. -) Curabitur vehicula eros posuere efficitur egestas.\n  12| (4. -) \n  13| (1. +) Lorem ipsum sit amet, consechbtetur adipiscing elit.z\n  14| (2. +) \n  15| (3. +) zFusce consecetur quam iod turpis blandit, pulvnar fermentum justo sollicitudin.\n  16| (4. +) Curdabitur veicular eros posuere hello efficitulr egestas.\n  17| (5. #) Duis et lectus in nisi mattis convallis non a odio.\n  18| (6. -) Proin pulvinar felis consectetur condimentum tincidunt.\n  19| (6. +) Proin puvinar feliss consectetur codiementum tincidunt.\n\n"
+(string) (len=1484) "\n\n   1| Two objects that should be equal, are not equal.\n   2| \n   3| Expected:\n   4| (string) (len=297) \"Lorem ipsum dolor sit amet, consectetur adipiscing elit.\\nFusce consectetur quam id turpis blandit, pulvinar fermentum justo sollicitudin.\\nCurabitur vehicula eros posuere efficitur egestas.\\n\\nDuis et lectus in nisi mattis convallis non a odio.\\nProin pulvinar felis consectetur condimentum tincidunt.\"\n   5| \n   6| Actual:\n   7| (string) (len=302) \"Lorem ipsum sit amet, consechbtetur adipiscing elit.z\\n\\nzFusce consecetur quam iod turpis blandit, pulvnar fermentum justo sollicitudin.\\nCurdabitur veicular eros posuere hello efficitulr egestas.\\nDuis et lectus in nisi mattis convallis non a odio.\\nProin puvinar feliss consectetur codiementum tincidunt.\"\n   8| \n   9| Difference:\n  10| (1. -) Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n  11| (2. -) Fusce consectetur quam id turpis blandit, pulvinar fermentum justo sollicitudin.\n  12| (3. -) Curabitur vehicula eros posuere efficitur egestas.\n  13| (4. -) \n  14| (1. +) Lorem ipsum sit amet, consechbtetur adipiscing elit.z\n  15| (2. +) \n  16| (3. +) zFusce consecetur quam iod turpis blandit, pulvnar fermentum justo sollicitudin.\n  17| (4. +) Curdabitur veicular eros posuere hello efficitulr egestas.\n  18| (5. #) Duis et lectus in nisi mattis convallis non a odio.\n  19| (6. -) Proin pulvinar felis consectetur condimentum tincidunt.\n  20| (6. +) Proin puvinar feliss consectetur codiementum tincidunt.\n\n"
diff --git a/testdata/snapshots/TestOutputConsistency/failed_test_struct.testza b/testdata/snapshots/TestOutputConsistency/failed_test_struct.testza
old mode 100755
new mode 100644
index 1dbcb02..92a09bb
--- a/testdata/snapshots/TestOutputConsistency/failed_test_struct.testza
+++ b/testdata/snapshots/TestOutputConsistency/failed_test_struct.testza
@@ -1,1 +1,1 @@
-(string) (len=1005) "\n\n   0| Two objects that should be equal, are not equal.\n   1| \n   2| Expected:\n   3| (testza_test.assertionTestStruct) {\n   4|  Name: (string) (len=4) \"John\",\n   5|  Age: (int) 34,\n   6|  Meta: (testza_test.assertionTestStructNested) {\n   7|   ID: (int) 512345,\n   8|   Admin: (bool) false\n   9|  }\n  10| }\n  11| \n  12| Actual:\n  13| (testza_test.assertionTestStruct) {\n  14|  Name: (string) (len=3) \"Bob\",\n  15|  Age: (int) 22,\n  16|  Meta: (testza_test.assertionTestStructNested) {\n  17|   ID: (int) 123456,\n  18|   Admin: (bool) true\n  19|  }\n  20| }\n  21| \n  22| Difference:\n  23| (1. #) (testza_test.assertionTestStruct) {\n  24| (2. -)  Name: (string) (len=4) \"John\",\n  25| (3. -)  Age: (int) 34,\n  26| (2. +)  Name: (string) (len=3) \"Bob\",\n  27| (3. +)  Age: (int) 22,\n  28| (4. #)  Meta: (testza_test.assertionTestStructNested) {\n  29| (5. -)   ID: (int) 512345,\n  30| (6. -)   Admin: (bool) false\n  31| (5. +)   ID: (int) 123456,\n  32| (6. +)   Admin: (bool) true\n  33| (7. #)  }\n  34| (8. #) }\n\n"
+(string) (len=1005) "\n\n   1| Two objects that should be equal, are not equal.\n   2| \n   3| Expected:\n   4| (testza_test.assertionTestStruct) {\n   5|  Name: (string) (len=4) \"John\",\n   6|  Age: (int) 34,\n   7|  Meta: (testza_test.assertionTestStructNested) {\n   8|   ID: (int) 512345,\n   9|   Admin: (bool) false\n  10|  }\n  11| }\n  12| \n  13| Actual:\n  14| (testza_test.assertionTestStruct) {\n  15|  Name: (string) (len=3) \"Bob\",\n  16|  Age: (int) 22,\n  17|  Meta: (testza_test.assertionTestStructNested) {\n  18|   ID: (int) 123456,\n  19|   Admin: (bool) true\n  20|  }\n  21| }\n  22| \n  23| Difference:\n  24| (1. #) (testza_test.assertionTestStruct) {\n  25| (2. -)  Name: (string) (len=4) \"John\",\n  26| (3. -)  Age: (int) 34,\n  27| (2. +)  Name: (string) (len=3) \"Bob\",\n  28| (3. +)  Age: (int) 22,\n  29| (4. #)  Meta: (testza_test.assertionTestStructNested) {\n  30| (5. -)   ID: (int) 512345,\n  31| (6. -)   Admin: (bool) false\n  32| (5. +)   ID: (int) 123456,\n  33| (6. +)   Admin: (bool) true\n  34| (7. #)  }\n  35| (8. #) }\n\n"
diff --git a/testdata/snapshots/TestOutputConsistency/failed_test_with_custom_formatted_msg.testza b/testdata/snapshots/TestOutputConsistency/failed_test_with_custom_formatted_msg.testza
old mode 100755
new mode 100644
index 79a746a..89c5026
--- a/testdata/snapshots/TestOutputConsistency/failed_test_with_custom_formatted_msg.testza
+++ b/testdata/snapshots/TestOutputConsistency/failed_test_with_custom_formatted_msg.testza
@@ -1,1 +1,1 @@
-(string) (len=253) "\n\n   0| Two objects that should be equal, are not equal.\n   1| \n   2| Message: Custom message!\n   3| \n   4| Expected:\n   5| (bool) true\n   6| \n   7| Actual:\n   8| (bool) false\n   9| \n  10| Difference:\n  11| (1. -) (bool) true\n  12| (1. +) (bool) false\n\n"
+(string) (len=253) "\n\n   1| Two objects that should be equal, are not equal.\n   2| \n   3| Message: Custom message!\n   4| \n   5| Expected:\n   6| (bool) true\n   7| \n   8| Actual:\n   9| (bool) false\n  10| \n  11| Difference:\n  12| (1. -) (bool) true\n  13| (1. +) (bool) false\n\n"
diff --git a/testdata/snapshots/TestOutputConsistency/failed_test_with_custom_msg.testza b/testdata/snapshots/TestOutputConsistency/failed_test_with_custom_msg.testza
old mode 100755
new mode 100644
index 79a746a..89c5026
--- a/testdata/snapshots/TestOutputConsistency/failed_test_with_custom_msg.testza
+++ b/testdata/snapshots/TestOutputConsistency/failed_test_with_custom_msg.testza
@@ -1,1 +1,1 @@
-(string) (len=253) "\n\n   0| Two objects that should be equal, are not equal.\n   1| \n   2| Message: Custom message!\n   3| \n   4| Expected:\n   5| (bool) true\n   6| \n   7| Actual:\n   8| (bool) false\n   9| \n  10| Difference:\n  11| (1. -) (bool) true\n  12| (1. +) (bool) false\n\n"
+(string) (len=253) "\n\n   1| Two objects that should be equal, are not equal.\n   2| \n   3| Message: Custom message!\n   4| \n   5| Expected:\n   6| (bool) true\n   7| \n   8| Actual:\n   9| (bool) false\n  10| \n  11| Difference:\n  12| (1. -) (bool) true\n  13| (1. +) (bool) false\n\n"