From 7dd9f4b041a348d1e7916346b45b47f4c274133f Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Tue, 8 Apr 2014 15:50:00 -0400 Subject: [PATCH] Fix handling of "files:not Pattern*" for non-file contexts --- src/host/criteria_matches.c | 23 +++++++++++++++++------ tests/base/test_criteria.lua | 10 ++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/host/criteria_matches.c b/src/host/criteria_matches.c index 40d010db..39cc3cf5 100644 --- a/src/host/criteria_matches.c +++ b/src/host/criteria_matches.c @@ -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; } diff --git a/tests/base/test_criteria.lua b/tests/base/test_criteria.lua index 90e7a467..8a065ac8 100644 --- a/tests/base/test_criteria.lua +++ b/tests/base/test_criteria.lua @@ -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