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

prioritize wide strings over strings on MSVC #876

Merged
merged 11 commits into from
Jun 15, 2023

Conversation

phlptp
Copy link
Collaborator

@phlptp phlptp commented May 5, 2023

to handle std::filesystem::path better widestring operations should be preferred over regular strings.

Fix Issue #875

Comment on lines 1718 to 1740
#if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0
TEST_CASE_METHOD(TApp, "filesystemWideName", "[app]") {
std::filesystem::path myfile{L"voil\u20ac.txt"};

std::filesystem::path fpath;
app.add_option("--file", fpath)->check(CLI::ExistingFile, "existing file");

CHECK_THROWS_AS(app.parse(L"--file voil\u20ac.txt"), CLI::ValidationError);

bool ok = static_cast<bool>(std::ofstream(myfile).put('a')); // create file
CHECK(ok);

// deactivate the check, so it should run now

CHECK_NOTHROW(app.parse(L"--file voil\u20ac.txt"));

CHECK(fpath == myfile);

CHECK(std::filesystem::exists(fpath));
std::filesystem::remove(myfile);
CHECK(!std::filesystem::exists(fpath));
}
#endif
Copy link

Choose a reason for hiding this comment

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

On Ubuntu 20.04, if you do run this test it fails

That means necessarily passing -DCMAKE_CXX_STANDARD:STRING=20 (or 17)

-------------------------------------------------------------------------------
filesystemWideName
-------------------------------------------------------------------------------
CLI11/tests/AppTest.cpp:1719
...............................................................................

CLI11/tests/AppTest.cpp:1719: FAILED:
due to unexpected exception with message:
  filesystem error: Cannot convert character sequence: Invalid or incomplete
  multibyte or wide character

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A couple of the CI builds are failing with the same error, I am going to take a closer look today. Seems there is some ambiguity in the standards about how filesystem::path is treated with respect to strings and some differences between compilers.

@codecov
Copy link

codecov bot commented May 5, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (0700bc1) 99.46% compared to head (e1cf74d) 99.46%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #876   +/-   ##
=======================================
  Coverage   99.46%   99.46%           
=======================================
  Files          18       18           
  Lines        4086     4086           
=======================================
  Hits         4064     4064           
  Misses         22       22           
Impacted Files Coverage Δ
include/CLI/TypeTools.hpp 100.00% <ø> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@phlptp
Copy link
Collaborator Author

phlptp commented May 5, 2023

I swapped the prioritize wstring to only be active on MSVC, not sure if that should be all windows or just visual studio?

@phlptp phlptp changed the title prioritize wide strings over strings if applicable prioritize wide strings over strings on MSVC May 7, 2023
@phlptp
Copy link
Collaborator Author

phlptp commented Jun 15, 2023

@jmarrec I am going to merge this and close #878, feel free to resubmit if there are situations this doesn't resolve.

@phlptp phlptp merged commit 1939301 into CLIUtils:main Jun 15, 2023
@phlptp phlptp deleted the prioritize_wstring branch June 15, 2023 13:28
@github-actions github-actions bot added needs changelog Hasn't been added to the changelog yet needs README Needs to be mentioned in the README labels Jun 15, 2023
@jmarrec
Copy link

jmarrec commented Jun 17, 2023

I swapped the prioritize wstring to only be active on MSVC, not sure if that should be all windows or just visual studio?

Great that you limited it to not affect Unix, I think that's the right decision!

Ultimately, it should be all of windows and not just MSVC. std::filesystem::path is wide on Windows as a whole (I have a doubt for cygwin though)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs changelog Hasn't been added to the changelog yet needs README Needs to be mentioned in the README
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants