fix(testgen): distinguish between C and C++ based on file extension #4
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/testgen_for_cpp"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
This PR introduces improved language detection logic in the
testgencommand to better handle files labeled as "C/C++". Previously, files with this language designation were treated uniformly, which could lead to unsupported language warnings or incorrect processing. Now, the code inspects the file extension to accurately distinguish between C and C++ files, mapping them to the appropriate supported language ("C" or "C++").This change ensures that the tool provides more precise feedback and avoids false positives for unsupported languages when processing C/C++ source files.
Changes
lang == "C/C++":filepath.Ext(filePath)and converts it to lowercase for case-insensitive matching..cpp,.cc,.cxx) and setslang = "C++"if matched.lang = "C"for all other extensions (e.g.,.cor unrecognized).No other files or functionalities were modified.
Motivation
The
testgentool relies on accurate language identification to generate tests effectively. Files in repositories often use a generic "C/C++" label (e.g., from language detection libraries or metadata), but the tool's supported languages list distinguishes between "C" and "C++". Without this refinement, valid C or C++ files could trigger unnecessary "unsupported language" warnings, leading to skipped processing or user confusion. This change enhances usability, reduces false warnings, and aligns the tool's behavior with real-world file types, making it more robust for mixed-language projects.Testing Notes
testgencommand on sample files:.cfile (expected: lang="C", no warning)..cpp,.cc, and.cxxfiles (expected: lang="C++", no warning)..hunder "C/C++") – defaults to "C" as a safe fallback, but still checks against supported langs..CPP), empty files, and non-C/C++ languages (unchanged behavior).testgencommand on a mixed-language test repository to ensure no regressions in Go, Python, or other supported languages.go build.If additional automated tests are needed, I can add them in a follow-up. Please review and let me know if any adjustments are required!