Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trailing space checker to remove existing trailing spaces #6748

Merged
merged 3 commits into from
Apr 2, 2024

Conversation

ksco
Copy link
Contributor

@ksco ksco commented Mar 31, 2024

We rely on git diff to do trailing space checks, so to remove the trailing spaces in existing lines that may have been introduced by mistake, deletion lines should be excluded during the check.

Tested with following snippets:

cmake_minimum_required(VERSION 3.0)
project(StringRegexMatchExample)

function(match_string_with_regex input_string regex_pattern)
    string(REGEX MATCH "${regex_pattern}" match_result "${input_string}")
    if(match_result)
        message("Match")
    else()
        message("Not match")
    endif()
endfunction()

set(regex_pattern "\n[+ ][^\n]* \n")

set(input_string "diff\n hello  \n")
match_string_with_regex("${input_string}" "${regex_pattern}")

set(input_string "diff\n+ \n")
match_string_with_regex("${input_string}" "${regex_pattern}")

set(input_string "diff\n  \n")
match_string_with_regex("${input_string}" "${regex_pattern}")

set(input_string "diff\n \n")
match_string_with_regex("${input_string}" "${regex_pattern}")

set(input_string "diff\n-hello  \n")
match_string_with_regex("${input_string}" "${regex_pattern}")

set(input_string "diff\n-  \n")
match_string_with_regex("${input_string}" "${regex_pattern}")

set(input_string "diff\n hello\n")
match_string_with_regex("${input_string}" "${regex_pattern}")

set(input_string "diff\n+hello\n-  \n")
match_string_with_regex("${input_string}" "${regex_pattern}")

set(input_string "diff\n hello\n-  \n")
match_string_with_regex("${input_string}" "${regex_pattern}")

set(input_string "diff\nhello\n")
match_string_with_regex("${input_string}" "${regex_pattern}")

set(input_string "diff\n\n")
match_string_with_regex("${input_string}" "${regex_pattern}")

Outputs:

Match
Match
Match
Not match
Not match
Not match
Not match
Not match
Not match
Not match
Not match

@ksco ksco requested a review from derekbruening March 31, 2024 07:07
suite/runsuite.cmake Outdated Show resolved Hide resolved
suite/runsuite.cmake Outdated Show resolved Hide resolved
Copy link
Contributor

@derekbruening derekbruening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for improving this check!

suite/runsuite.cmake Show resolved Hide resolved
@ksco ksco merged commit 60eb0b1 into DynamoRIO:master Apr 2, 2024
16 checks passed
@ksco ksco deleted the trailing-space branch April 2, 2024 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants