Skip to content

Commit

Permalink
Add tests for issue microsoft#290
Browse files Browse the repository at this point in the history
  • Loading branch information
heaths committed Jun 12, 2023
1 parent c7a417b commit ce76130
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/vswhere.lib/Glob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Glob::Glob(_In_ const wstring& root, _In_ const wstring& pattern) :
{
if (found_globstar)
{
// Replase globstar with any characer match plus optional directory separator.
// Replace globstar with any character match plus directory separator.
accumulator += L".*\\\\?";
}
else if (value_raw.length() == 1 && value_raw == L".")
Expand Down
30 changes: 30 additions & 0 deletions test/vswhere.test/GlobTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,34 @@ TEST_CLASS(GlobTests)
Assert::IsTrue(sut.Match(L"C:\\ShouldNotExist\\MSBuild\\Current\\Bin\\MSBuild.exe"));
Assert::IsTrue(sut.Match(L"C:\\ShouldNotExist\\MSBuild\\Current\\Bin\\amd64\\MSBuild.exe"));
}

BEGIN_TEST_METHOD_ATTRIBUTE(Ignores_Trailing_Separator)
TEST_WORKITEM(290)
END_TEST_METHOD_ATTRIBUTE()
TEST_METHOD(Ignores_Trailing_Separator)
{
Glob sut(L"C:\\ShouldNotExist\\", L"**\\cl.exe");

Assert::IsTrue(sut.Match(L"C:\\ShouldNotExist\\VC\\Tools\\MSVC\\14.36.32532\\bin\\Hostx64\\x64\\cl.exe"));
}

BEGIN_TEST_METHOD_ATTRIBUTE(Issue290)
TEST_WORKITEM(290)
END_TEST_METHOD_ATTRIBUTE()
TEST_METHOD(Issue290)
{
Glob sut(L"C:\\ShouldNotExist", L"**\\cl.exe");

#ifdef _DEBUG
#endif

Assert::IsFalse(sut.Match(L"C:\\ShouldNotExist\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\Git\\usr\\bin\\getfacl.exe"));
Assert::IsTrue(sut.Match(L"C:\\ShouldNotExist\\VC\\Tools\\MSVC\\14.36.32532\\bin\\Hostx64\\arm64\\cl.exe"));
Assert::IsTrue(sut.Match(L"C:\\ShouldNotExist\\VC\\Tools\\MSVC\\14.36.32532\\bin\\Hostx64\\x64\\cl.exe"));
Assert::IsTrue(sut.Match(L"C:\\ShouldNotExist\\VC\\Tools\\MSVC\\14.36.32532\\bin\\Hostx86\\arm\\cl.exe"));
Assert::IsTrue(sut.Match(L"C:\\ShouldNotExist\\VC\\Tools\\MSVC\\14.36.32532\\bin\\Hostx86\\x86\\cl.exe"));

// Assert the reason the last directory specifier is optional: to make sure we find cl.exe in the root directory.
Assert::IsTrue(sut.Match(L"C:\\ShouldNotExist\\cl.exe"));
}
};

0 comments on commit ce76130

Please sign in to comment.