Fix handling of "files:not Pattern*" for non-file contexts

This commit is contained in:
Jason Perkins 2014-04-08 15:50:00 -04:00
parent 0f713d5c39
commit 7dd9f4b041
2 changed files with 27 additions and 6 deletions

View File

@ -101,8 +101,13 @@ static int testContext(lua_State* L, const char* prefix, const char* part,
/*
if prefix then
local result = testValue(context[prefix], part, wildcard)
if result == assertion and prefix == "files" then
filematched = true
if prefix == "files" then
if not filename then
return false
end
if result == assertion then
filematched = true
end
end
if result then
return assertion
@ -126,8 +131,13 @@ static int testContext(lua_State* L, const char* prefix, const char* part,
lua_getfield(L, 2, prefix);
result = testValue(L, part, wildcard);
lua_pop(L, 1);
if (result == assertion && strcmp(prefix, "files") == 0) {
(*fileMatched) = 1;
if (strcmp(prefix, "files") == 0) {
if (filename == NULL) {
return 0;
}
if (result == assertion) {
(*fileMatched) = 1;
}
}
if (result) {
return assertion;
@ -229,9 +239,9 @@ int criteria_matches(lua_State* L)
/* stack [2] = context */
const char* filename;
int fileMatched;
int top = lua_gettop(L);
int matched = 1;
int fileMatched = 0;
/*
Cache string.match for a quicker lookup in match() above
@ -246,6 +256,7 @@ int criteria_matches(lua_State* L)
lua_getfield(L, 2, "files");
filename = lua_tostring(L, -1);
fileMatched = (filename == NULL);
/*
for i, pattern in pairs(criteria.patterns) do
@ -273,7 +284,7 @@ int criteria_matches(lua_State* L)
return matched
*/
if (matched && filename && !fileMatched) {
if (filename != NULL && !fileMatched) {
matched = 0;
}

View File

@ -214,3 +214,13 @@
crit = criteria.new { "files:not **.h" }
test.istrue(criteria.matches(crit, { files = "hello.cpp" }))
end
function suite.filesTermFails_onNoValue()
crit = criteria.new { "files:Debug**" }
test.isfalse(criteria.matches(crit, { configurations = "Debug32" }))
end
function suite.filesTermFails_onNotModifierAndNoMatch()
crit = criteria.new { "files:not Debug**" }
test.isfalse(criteria.matches(crit, { configurations = "Debug32" }))
end