Skip to contentSkip to conversation

t5541-http-push: make grep expression check for one line only

PATCH In review Tay Ray Chuan 2 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 t5541-http-push: make grep expression check for one line only

Simplify the grep expressions in the non-fast-forward tests to check only for the first line of the non-fast-forward warning - having that line should be enough assurance that the full warning is printed.

In the first place, grep can't deal with expressions for multiple lines.

---
 t/t5541-http-push.sh |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
t/t5541-http-push.sh +4 -8
index 83a8e14..53f54a2 100755
@@ -105,10 +105,8 @@ test_expect_success 'non-fast-forward push show ref status' '
 '
 
 test_expect_success 'non-fast-forward push shows help message' '
-	grep \
-"To prevent you from losing history, non-fast-forward updates were rejected
-Merge the remote changes before pushing again.  See the '"'non-fast-forward'"'
-section of '"'git push --help'"' for details." output
+	grep "To prevent you from losing history, non-fast-forward updates were rejected" \
+		output
 '
 
 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
@@ -126,10 +124,8 @@ test_expect_success 'push fails for non-fast-forward refs unmatched by remote he
 	grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
 	grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output &&
 
-	grep \
-"To prevent you from losing history, non-fast-forward updates were rejected
-Merge the remote changes before pushing again.  See the '"'non-fast-forward'"'
-section of '"'git push --help'"' for details." output
+	grep "To prevent you from losing history, non-fast-forward updates were rejected" \
+		output
 '
 
 stop_httpd
Signature · 1 line
1.6.6
#1 lore raw
Quoted 6 lines · Tay Ray Chuan

Simplify the grep expressions in the non-fast-forward tests to check only for the first line of the non-fast-forward warning - having that line should be enough assurance that the full warning is printed.

In the first place, grep can't deal with expressions for multiple lines.

This shows that nobody has ever run this test since January 8th, not even the original author?

Hmmm.

Thanks.

Quoted 38 lines
---
 t/t5541-http-push.sh |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
t/t5541-http-push.sh +4 -8
index 83a8e14..53f54a2 100755
@@ -105,10 +105,8 @@ test_expect_success 'non-fast-forward push show ref status' '
 '
 
 test_expect_success 'non-fast-forward push shows help message' '
-	grep \
-"To prevent you from losing history, non-fast-forward updates were rejected
-Merge the remote changes before pushing again.  See the '"'non-fast-forward'"'
-section of '"'git push --help'"' for details." output
+	grep "To prevent you from losing history, non-fast-forward updates were rejected" \
+		output
 '
 
 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
@@ -126,10 +124,8 @@ test_expect_success 'push fails for non-fast-forward refs unmatched by remote he
 	grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
 	grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output &&
 
-	grep \
-"To prevent you from losing history, non-fast-forward updates were rejected
-Merge the remote changes before pushing again.  See the '"'non-fast-forward'"'
-section of '"'git push --help'"' for details." output
+	grep "To prevent you from losing history, non-fast-forward updates were rejected" \
+		output
 '
 
 stop_httpd
Signature · 1 line
1.6.6
#2 lore raw
Quoted 6 lines · Junio C Hamano
Quoted 4 lines · Tay Ray Chuan

Simplify the grep expressions in the non-fast-forward tests to check only for the first line of the non-fast-forward warning - having that line should be enough assurance that the full warning is printed.

Quoted 7 lines
Quoted 2 lines

In the first place, grep can't deal with expressions for multiple lines.

This shows that nobody has ever run this test since January 8th, not even the original author?

Hmmm.

Actually, if you grep with a pattern with multiple lines, it is equivalent to giving each of these lines as a separate pattern from the command line. So it is understandable that the tests passed. They were checking if these match, but it doesn't check (and grep is not designed to) if the first pattern matched the first line, the second to second, etc.

So I'd say something like...

Don't feed multiple-line pattern to grep and expect them to match with lines in order.

Simplify the grep expressions in the non-fast-forward tests to check only for the first line of the non-fast-forward warning - having that line should be enough assurance that the full warning is printed.

instead.

#3 lore raw

Hi,

Quoted 14 lines · Junio C Hamano
Quoted 12 lines · Junio C Hamano
Quoted 6 lines · Tay Ray Chuan

Simplify the grep expressions in the non-fast-forward tests to check only for the first line of the non-fast-forward warning - having that line should be enough assurance that the full warning is printed.

In the first place, grep can't deal with expressions for multiple lines.

This shows that nobody has ever run this test since January 8th, not even the original author?

Quoted 7 lines
Quoted 1 line

Hmmm.

Actually, if you grep with a pattern with multiple lines, it is equivalent to giving each of these lines as a separate pattern from the command line. So it is understandable that the tests passed.  They were checking if these match, but it doesn't check (and grep is not designed to) if the first pattern matched the first line, the second to second, etc.

that was why the tests passed then and passed now - I just happened to run them, and I noticed grep reported success, yet only matched 2 of the 3 lines. Then I remembered recently there had been a rewording of the fast-forward warning was reworded (c0eb604 "push: spell 'Note about fast-forwards'")...

Quoted 5 lines

So I'd say something like...

   Don't feed multiple-line pattern to grep and expect them to match with lines in order.

Quoted 7 lines

   Simplify the grep expressions in the non-fast-forward tests to check only for the first line of the non-fast-forward warning - having that line should be enough assurance that the full warning is printed.

instead.

No problem.

Signature · 2 lines
Cheers,
Ray Chuan
#4 lore raw

PATCH 1/1 t5541-http-push: make grep expression check for one line only

Don't feed multiple-line pattern to grep and expect them to match with lines in order.

Simplify the grep expressions in the non-fast-forward tests to check only for the first line of the non-fast-forward warning - having that line should be enough assurance that the full warning is printed.

---
 t/t5541-http-push.sh |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
t/t5541-http-push.sh +4 -8
index 83a8e14..53f54a2 100755
@@ -105,10 +105,8 @@ test_expect_success 'non-fast-forward push show ref status' '
 '
 
 test_expect_success 'non-fast-forward push shows help message' '
-	grep \
-"To prevent you from losing history, non-fast-forward updates were rejected
-Merge the remote changes before pushing again.  See the '"'non-fast-forward'"'
-section of '"'git push --help'"' for details." output
+	grep "To prevent you from losing history, non-fast-forward updates were rejected" \
+		output
 '
 
 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
@@ -126,10 +124,8 @@ test_expect_success 'push fails for non-fast-forward refs unmatched by remote he
 	grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
 	grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output &&
 
-	grep \
-"To prevent you from losing history, non-fast-forward updates were rejected
-Merge the remote changes before pushing again.  See the '"'non-fast-forward'"'
-section of '"'git push --help'"' for details." output
+	grep "To prevent you from losing history, non-fast-forward updates were rejected" \
+		output
 '
 
 stop_httpd
Signature · 1 line
1.6.6.1.436.gaba7d