+
Skip to content

Conversation

tgrez
Copy link
Contributor

@tgrez tgrez commented Jun 12, 2025

Follow up to #8158

The issue #8063 found in expr substr was also present in index, length, match. This PR applies the same fix for those remaining builtin expr functions.

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

Comment on lines 532 to 545
new_ucmd!()
.args(&["index", "abcd", "c", "!=", "2"])
.succeeds()
.stdout_only("1\n");

new_ucmd!()
.args(&["index", "abcd", "c", "=", "2"])
.fails_with_code(1)
.stdout_only("0\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason you deviate from the pattern used for substr and length, where the commands with = are expected to succeed and the commands with != are expected to fail?

Copy link
Member

Choose a reason for hiding this comment

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

I haven't been following this, but it probably makes sense to test all combinations right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason for that was that I wrote tests before fixing the bug and in case of index the first test case, for &["index", "abcd", "c", "!=", "3"] passed even before the fix, so I changed it to fail.

Now, the second test case for index (&["index", "abcd", "c", "=", "2"]) would pass also without the fix and match is missing such second test case.

I guess it's a good idea to make all cases consistent, like so:

#[test]
fn test_builtin_functions_precedence() {
    new_ucmd!()
        .args(&["substr", "ab cd", "3", "1", "!=", " "])
        .fails_with_code(1)
        .stdout_only("0\n");

    new_ucmd!()
        .args(&["substr", "ab cd", "3", "1", "=", " "])
        .succeeds()
        .stdout_only("1\n");

    new_ucmd!()
        .args(&["length", "abcd", "!=", "4"])
        .fails_with_code(1)
        .stdout_only("0\n");

    new_ucmd!()
        .args(&["length", "abcd", "=", "4"])
        .succeeds()
        .stdout_only("1\n");

    new_ucmd!()
        .args(&["index", "abcd", "c", "!=", "3"])
        .fails_with_code(1)
        .stdout_only("0\n");

    new_ucmd!()
        .args(&["index", "abcd", "c", "=", "3"])
        .succeeds()
        .stdout_only("1\n");

    new_ucmd!()
        .args(&["match", "abcd", "ab\\(.*\\)", "!=", "cd"])
        .fails_with_code(1)
        .stdout_only("0\n");

    new_ucmd!()
        .args(&["match", "abcd", "ab\\(.*\\)", "=", "cd"])
        .succeeds()
        .stdout_only("1\n");
}

Should I apply those changes to the PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, please :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes applied, rebased on the latest main branch, and verified that for each expr builtin function (match, substr, index, length) at least one of the test cases fails without the fix.

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)

@cakebaker cakebaker merged commit c9f76d4 into uutils:main Jun 13, 2025
74 of 75 checks passed
@cakebaker
Copy link
Contributor

Thanks!

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.

3 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载