core icon indicating copy to clipboard operation
core copied to clipboard

[test] Add unit tests for untested functions and edge cases in portability_path

Open roshankumar0036singh opened this issue 3 months ago • 7 comments

[test] Add unit tests for untested functions and edge cases in portability_path

Context & Motivation source/portability/source/portability_path.c implements core cross-platform path utilities used by 20+ language loaders and runtime components in MetaCall. A code health audit found that 8 declared functions have zero unit tests, and several API edge cases (NULL output buffers, separator normalization) are untested.(used repowise in it)

Audit Findings

  1. Untested functions in portability_path.h
  • portability_path_get_name_canonical
  • portability_path_get_extension
  • portability_path_get_directory_inplace
  • portability_path_is_absolute
  • portability_path_is_subpath
  • portability_path_separator_normalize_inplace
  • portability_path_is_pattern
  • portability_path_resolve, portability_path_exists, portability_path_file_exists
  1. Missing edge case coverage
  • Buffer query contract: NULL output buffer or size 0 should return required allocation size — untested.
  • Undersized output buffers: truncation behavior untested.
  • Windows-style backslash separators rarely tested vs POSIX forward slashes.

Proposed Solution Extend portability_path_test.cpp with new TEST_F cases:

  • Unit tests for all 8 untested functions listed above
  • Buffer query tests (NULL pointer / size 0 → required size)
  • Boundary tests for undersized buffers
  • Windows/POSIX separator coverage

Build & Verify mkdir build && cd build cmake .. cmake --build . --target portability_path_test

  • [ x] Is this something you can debug and fix? Create an apt issue and send us a pull request! Bug fixes and documentation fixes are welcome.

roshankumar0036singh avatar Aug 14 '26 10:08 roshankumar0036singh

@josead @viferga Hi maintainers, I’d like to work on this issue by adding the requested unit tests for the currently untested portability_path functions and edge cases, including NULL/zero-size buffers, undersized buffers, and Windows/POSIX separators.

I’ll keep the change limited to portability_path_test.cpp, follow the existing test conventions, and avoid production-code changes unless a test exposes an existing bug.

Would this approach be acceptable? If so, I’d be happy to proceed with the implementation and submit a PR.

Rajkaran-122 avatar Aug 17 '26 20:08 Rajkaran-122

@josead @viferga Hi maintainers, I’d like to work on this issue by adding the requested unit tests for the currently untested portability_path functions and edge cases, including NULL/zero-size buffers, undersized buffers, and Windows/POSIX separators.

I’ll keep the change limited to portability_path_test.cpp, follow the existing test conventions, and avoid production-code changes unless a test exposes an existing bug.

Would this approach be acceptable? If so, I’d be happy to proceed with the implementation and submit a PR.

If someone is already working on it it's better if you do some other thing. I left you a message in your PR, we discourage vibe coded PRs without any human review.

viferga avatar Aug 18 '26 09:08 viferga

@viferga i am working on it will open a pr soon

roshankumar0036singh avatar Aug 19 '26 00:08 roshankumar0036singh

@viferga i am working on it will open a pr soon

Great, thanks 👍

viferga avatar Aug 19 '26 00:08 viferga

@viferga during writing tests i came to a bug i wanted to clarify it with you

so the portability_path_get_name_canonical processes files that start with a dot and have no additional extension (e.g., .hidden)

When evaluating a path like /a/b/c/.hidden:

name_start correctly identifies the start of .hidden (index 7). The condition if (leftmost_dot == name_start) evaluates to true. The do-while loop advances leftmost_dot looking for the next dot. Because there are no other dots, it increments until leftmost_dot == path_size (index 15, which is exactly past the original string's \0 character).

The Missing Guard: Unlike the normal parsing branch (which explicitly does --leftmost_dot; on line 129 if it reaches path_size), this branch lacks that check.

The length is calculated as 15 - 7 = 8, causing memcpy to copy 8 bytes (.hidden\0) instead of 7 bytes (.hidden).

The function appends its own null terminator at index 8 and returns size 9.

roshankumar0036singh avatar Aug 20 '26 16:08 roshankumar0036singh

so should i fix this in this pr itself or for now let the test pass and verify more against it and open a seprate issue

roshankumar0036singh avatar Aug 20 '26 16:08 roshankumar0036singh

so should i fix this in this pr itself or for now let the test pass and verify more against it and open a seprate issue

Create a PR with a test case that reproduces the bug and fails, then ping me, let's run the CI and verify it fails, then commit the patch. Once the CI passes we merge the PR. You can reference this issue and for each bug you can do a new PR referencing this issue and using the same method I told you. By this way we do TDD and we verify the failing test and the patch solving the issue.

viferga avatar Aug 20 '26 18:08 viferga