Skip to contentSkip to conversation

check: fix parsing expunge file with comments

PATCH Superseded Amir Goldstein 2 participants 4 messages Aug 13, 2023 – Aug 14, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 check: fix parsing expunge file with comments

commit 60054d51 ("check: fix excluded tests are only expunged in the first iteration") change to use exclude_tests array instead of file.

The check if a test is in expunge file was using grep -q $TEST_ID FILE so it was checking if the test was a non-exact match to one of the lines, for a common example: "generic/001 # exclude this test" would be a match to test generic/001.

The commit regressed this example, because the new code checks for exact match of [ "generic/001" == "generic/001 " ]. Change the code to use prefix match to deal with this case and any other suffix correctly.

While the original code would also match line "exclude test generic/001" I don't think that non-prefix match is a real use case.

---
 check | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
check +2 -1
index 549725eb..e8152f59 100755
@@ -592,7 +592,8 @@ _expunge_test()
 	local TEST_ID="$1"
 
 	for f in "${exclude_tests[@]}"; do
-		if [ "${TEST_ID}" == "$f" ]; then
+		# $f may contain traling spaces and comments
+		if [[ "$f" == ${TEST_ID}* ]]; then
 			echo "       [expunged]"
 			return 0
 		fi
Signature · 1 line
2.34.1
#1 lore raw
Quoted 25 lines · Amir Goldstein

commit 60054d51 ("check: fix excluded tests are only expunged in the first iteration") change to use exclude_tests array instead of file.

The check if a test is in expunge file was using grep -q $TEST_ID FILE so it was checking if the test was a non-exact match to one of the lines, for a common example: "generic/001 # exclude this test" would be a match to test generic/001.

The commit regressed this example, because the new code checks for exact match of [ "generic/001" == "generic/001 " ]. Change the code to use prefix match to deal with this case and any other suffix correctly.

While the original code would also match line "exclude test generic/001" I don't think that non-prefix match is a real use case.

---
 check | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
check +0 -0
index 549725eb..e8152f59 100755

check _expunge_test() · line 596

Quoted 6 lines
check +2 -1
@@ -592,7 +592,8 @@ _expunge_test()
 	local TEST_ID="$1"
 
 	for f in "${exclude_tests[@]}"; do
-		if [ "${TEST_ID}" == "$f" ]; then
+		# $f may contain traling spaces and comments
+		if [[ "$f" == ${TEST_ID}* ]]; then

We'll have seqnum with 4 numbers in one day, likes generic/1000. At that time, generic/100[0-9] will match generic/100*. That's not what we want.

I think we'd better to do exact match, or better to match the end of a word, for example

  local id_regex="^${TEST_ID}\b"
  if [[ "$f" =~ ${id_regex} ]];then
  ...

I think this will match "generic/100" and "generic/100 # xxxxx". But won't match "generic/1001".

Thanks,
Zorro

Quoted 6 lines
check +0 -0
 			echo "       [expunged]"
 			return 0
 		fi
Signature · 1 line
2.34.1
#2 lore raw
Quoted 29 lines · Zorro Lang
Quoted 27 lines · Amir Goldstein

commit 60054d51 ("check: fix excluded tests are only expunged in the first iteration") change to use exclude_tests array instead of file.

The check if a test is in expunge file was using grep -q $TEST_ID FILE so it was checking if the test was a non-exact match to one of the lines, for a common example: "generic/001 # exclude this test" would be a match to test generic/001.

The commit regressed this example, because the new code checks for exact match of [ "generic/001" == "generic/001 " ]. Change the code to use prefix match to deal with this case and any other suffix correctly.

While the original code would also match line "exclude test generic/001" I don't think that non-prefix match is a real use case.

---
 check | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
check +0 -0
index 549725eb..e8152f59 100755
@@ -592,7 +592,8 @@ _expunge_test()
      local TEST_ID="$1"
 
Quoted 8 lines

check _expunge_test() · line 596

Quoted 4 lines
check +2 -1
      for f in "${exclude_tests[@]}"; do
-             if [ "${TEST_ID}" == "$f" ]; then
+             # $f may contain traling spaces and comments
+             if [[ "$f" == ${TEST_ID}* ]]; then

We'll have seqnum with 4 numbers in one day, likes generic/1000. At that time, generic/100[0-9] will match generic/100*. That's not what we want.

Good point.

Quoted 10 lines

I think we'd better to do exact match, or better to match the end of a word, for example

  local id_regex="^${TEST_ID}\b"
  if [[ "$f" =~ ${id_regex} ]];then
  ...

I think this will match "generic/100" and "generic/100 # xxxxx". But won't match "generic/1001".

Nice. Looks good to me.

Thanks,
Amir.

#3 lore raw
Quoted 48 lines · Amir Goldstein
Quoted 29 lines · Zorro Lang
Quoted 27 lines · Amir Goldstein

commit 60054d51 ("check: fix excluded tests are only expunged in the first iteration") change to use exclude_tests array instead of file.

The check if a test is in expunge file was using grep -q $TEST_ID FILE so it was checking if the test was a non-exact match to one of the lines, for a common example: "generic/001 # exclude this test" would be a match to test generic/001.

The commit regressed this example, because the new code checks for exact match of [ "generic/001" == "generic/001 " ]. Change the code to use prefix match to deal with this case and any other suffix correctly.

While the original code would also match line "exclude test generic/001" I don't think that non-prefix match is a real use case.

---
 check | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
check +0 -0
index 549725eb..e8152f59 100755
@@ -592,7 +592,8 @@ _expunge_test()
      local TEST_ID="$1"
 
Quoted 8 lines

check _expunge_test() · line 596

Quoted 4 lines
check +2 -1
      for f in "${exclude_tests[@]}"; do
-             if [ "${TEST_ID}" == "$f" ]; then
+             # $f may contain traling spaces and comments
+             if [[ "$f" == ${TEST_ID}* ]]; then

We'll have seqnum with 4 numbers in one day, likes generic/1000. At that time, generic/100[0-9] will match generic/100*. That's not what we want.

Good point.

Quoted 7 lines

I think we'd better to do exact match, or better to match the end of a word, for example

  local id_regex="^${TEST_ID}\b"
  if [[ "$f" =~ ${id_regex} ]];then
  ...
Quoted 5 lines
Quoted 3 lines

I think this will match "generic/100" and "generic/100 # xxxxx". But won't match "generic/1001".

Nice. Looks good to me.

I didn't test it, please check if that can help you and won't break old things, if you'd like to write that in V2 :)

Thanks,
Zorro

Quoted 4 lines

Thanks,
Amir.