Skip to content

test: add unit tests for Curl_range - #23236

Closed
ElGitMan74 wants to merge 1 commit into
curl:masterfrom
ElGitMan74:unit1700-curl-range
Closed

ElGitMan74 wants to merge 1 commit into
curl:masterfrom
ElGitMan74:unit1700-curl-range

Conversation

@ElGitMan74

@ElGitMan74 ElGitMan74 commented Oct 2, 2026 •

Copy link
Copy Markdown

unit1700: test all Curl_range paths and all boundary conditions

Summary by CodeRabbit

  • Tests
    • Added automated coverage for range handling, including malformed and whitespace-containing values, open-ended and bounded ranges, signed values, leading zeros, and numeric limits.
    • The tests check expected range offsets and download limits. No user-facing behavior changes are included.

@github-actions github-actions Bot added the tests label Oct 2, 2026
@testclutch

Copy link
Copy Markdown

Analysis of PR #23236 at f3f2a357:

Test 1700 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 4 different CI jobs (the link just goes to one of them).

Generated by Testclutch

@vszakats

vszakats commented Oct 2, 2026

Copy link
Copy Markdown
Member

Isn't this function tested indirectly via FTP/FILE tests?

@ElGitMan74

Copy link
Copy Markdown
Author

Hello @vszakats , we have an opportunity for a direct Curl_range test with this unit test. I didn't see this level of range or boundary exercise in the existing unit tests.

@vszakats

vszakats commented Oct 2, 2026

Copy link
Copy Markdown
Member

Hello @vszakats , we have an opportunity for a direct Curl_range test with this unit test. I didn't see this level of range or boundary exercise in the existing unit tests.

It may be because it's already tested indirectly. I'm not personally convinced
this is code and machine time the best spent. It seems like something an LLM
would generate.

@ElGitMan74

ElGitMan74 commented Oct 2, 2026 via email

Copy link
Copy Markdown
Author

@jay

jay commented Oct 2, 2026

Copy link
Copy Markdown
Member

Why did you replace test 1700 which is unrelated? I agree with Viktor there's hints of an LLM here. We have range testing already tests 1016-1020 test1063, probably others, though yours may have better coverage in one place. I think what we have now is ok? For now I'll leave this open for more feedback.

@ElGitMan74

Copy link
Copy Markdown
Author

Hello @jay , there was no existing 1700, that number was skipped

@jay

jay commented Oct 2, 2026

Copy link
Copy Markdown
Member

Hello @jay , there was no existing 1700, that number was skipped

https://github.com/curl/curl/blob/master/tests/data/test1700

@ElGitMan74

Copy link
Copy Markdown
Author

Hello @jay , there was no existing 1700, that number was skipped

https://github.com/curl/curl/blob/master/tests/data/test1700

I sit corrected. I'll move the code to a new number.

@ElGitMan74

Copy link
Copy Markdown
Author

@vszakats and @jay : Thanks for your feedback. I've got the stress tests passing now, the github checks are all passing. I'll move the code to a new unit number now.

@ElGitMan74
ElGitMan74 force-pushed the unit1700-curl-range branch 4 times, most recently from 4bb8edc to b118645 Compare October 2, 2026 20:03
@vszakats

vszakats commented Oct 2, 2026

Copy link
Copy Markdown
Member

The LLM found the lack of unit testing for this item.

That's my issue; an LLM will point out any internal function without a dedicated
test as an "issue to fix", because it has no capacity to weight the importance
of something and has no sense of limits.

@ElGitMan74

Copy link
Copy Markdown
Author

The LLM found the lack of unit testing for this item.

That's my issue; an LLM will point out any internal function without a dedicated test as an "issue to fix", because it has no capacity to weight the importance of something and has no sense of limits.

Ok, test moved to an unused number unit1694. Appreciate your patience, code is ready for your review. One github check failed on timeout, passed previously.

If you guys decide to reject this PR because an LLM pointed me to an area that didn't have it's own unit test, how would you suggest I find an area to help with the unit testing? I want to help here.

@bagder

bagder commented Oct 5, 2026

Copy link
Copy Markdown
Member

I think a unit test for this makes sense.

But I think it should be written in a way so that we can have list of ranges, and the test case should iterate over those and test them. Not copy-and-paste all the logic for the few tests done. I think many other existing unit tests can serve as inspiration for that.

Then we can extend the set to make sure we test all reasonable variations, including all edge cases and wrong ones.

@ElGitMan74

Copy link
Copy Markdown
Author

I think a unit test for this makes sense.

But I think it should be written in a way so that we can have list of ranges, and the test case should iterate over those and test them. Not copy-and-paste all the logic for the few tests done. I think many other existing unit tests can serve as inspiration for that.

Then we can extend the set to make sure we test all reasonable variations, including all edge cases and wrong ones.

Hello @bagder and thanks for your response. I love that idea! Very clean implementation. It looks like unit1307 has an appropriate pattern for testing multiple sets of input values:

https://github.com/curl/curl/blob/master/tests/unit/unit1307.c

I'm traveling this week so I won't be able to pick this up again until next week. I can close this PR to get it out of your way while I'm out, or I can reuse this PR starting next week. Up to you guys whatever keeps your queue cleaned up. Again, thank you all for your time and patience.

@ElGitMan74 ElGitMan74 closed this Oct 13, 2026
@ElGitMan74
ElGitMan74 deleted the unit1700-curl-range branch October 13, 2026 15:39
@ElGitMan74
ElGitMan74 restored the unit1700-curl-range branch October 13, 2026 15:42
@ElGitMan74 ElGitMan74 reopened this Oct 13, 2026
@ElGitMan74

Copy link
Copy Markdown
Author

Greetings @bagder , @vszakats , and @jay . As per @bagder 's suggestion, I have reworked unit1694 to mimic the approach of unit1307: "we can have list of ranges, and the test case should iterate over those and test them". Looking forward to your comments and thanks again for your patience.

Comment thread tests/unit/unit1694.c Resolved
Comment thread tests/unit/unit1694.c Resolved
Comment thread tests/unit/unit1694.c Resolved
Comment thread tests/unit/unit1694.c Resolved
@ElGitMan74
ElGitMan74 force-pushed the unit1700-curl-range branch 2 times, most recently from 520e0a5 to ad7d8db Compare October 13, 2026 19:19
@ElGitMan74

Copy link
Copy Markdown
Author

Greetings @vszakats , thank you for your comments, I have incorporated them all. One CI/CD test is timing out that passed previously. Please let me know if I need to do anything further to move this PR forward, thanks.

@ElGitMan74
ElGitMan74 force-pushed the unit1700-curl-range branch 3 times, most recently from dfc9c8b to 2e38a64 Compare October 16, 2026 17:58
Comment thread tests/unit/unit1694.c Outdated
/* Start at the beginning, go to a byte */
{ TRUE, "-100", CURLE_OK, -100, 100 },
/* A range of bytes */
{ TRUE, "100-201", CURLE_OK, 100, 102 }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this can test many more variants:

  • ranges that use numbers with (many) zero prefixes to the number
  • ranges that end of the largest possible (2^63-1) number
  • ranges that use hexadecimal numbers
  • ranges that use more spaces sprinkled "- 100", "1 - 100", "1 - 200" etc
  • ranges that have a tab in the string "0 -\x09 100"
  • negative to positive "-100 - 200"
  • negative to negative "-100 - -200"
  • ranges that use + for the number "+100 - +200"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same number to number: "100 - 100"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hello @bagder and thanks for your suggestions! Lots of new tests added and git committed. I added comments around some of the tests explaining their weird behavior, we fed the parser some stuff it's wasn't used to! Not enough to core dump it ;-) A few of the commit tests are timing out again. Let me know if you have further suggestions or feedback, your time is much appreciated.

@bagder

bagder commented Oct 26, 2026

Copy link
Copy Markdown
Member

"Merge conflicts", please fix and force-push

Add unit1694 covering Curl_range() with a table of valid and invalid range strings: the no-op cases, the parse errors, and the N-, -N and N-M forms.
@ElGitMan74

Copy link
Copy Markdown
Author

"Merge conflicts", please fix and force-push

Thanks @bagder , I rebased on current master and force-pushed as a single commit; the conflicts are resolved.

@curl curl deleted a comment from coderabbitai Bot Oct 27, 2026
@bagder bagder closed this in f5ac97b Oct 27, 2026
@bagder

bagder commented Oct 27, 2026

Copy link
Copy Markdown
Member

Thanks, merged!

@ElGitMan74
ElGitMan74 deleted the unit1700-curl-range branch October 30, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

5 participants