Skip to content
Browse files

use include/exclude in foreach instead of filter (TSUN-162)

  • Loading branch information...
1 parent 96dcaf9 commit f454fbbe6cbaabcfc6ed0e9d75cf39554bfbaba9 @nniclausse nniclausse committed Sep 1, 2010
Showing with 22 additions and 11 deletions.
  1. +5 −2 src/test/ts_test_search.erl
  2. +5 −5 src/tsung/ts_client.erl
  3. +10 −3 src/tsung_controller/ts_config.erl
  4. +2 −1 tsung-1.0.dtd
View
7 src/test/ts_test_search.erl
@@ -351,8 +351,11 @@ parse_dynvar_xpath_single_test() ->
Expected = [<<"/index.html">>],
?assertEqual(Expected, R).
-filter_re_test() ->
- ?assertEqual(["/toto"], ts_client:filter({ok,["http://toto/", "/toto", "mailto:bidule"]}, "^/.*")).
+filter_re_include_test() ->
+ ?assertEqual(["/toto"], ts_client:filter({ok,["http://toto/", "/toto", "mailto:bidule"]}, {true, "^/.*"})).
+
+filter_re_exclude_test() ->
+ ?assertEqual(["http://toto/", "mailto:bidule"], ts_client:filter({ok,["http://toto/", "/toto", "mailto:bidule"]}, {false,"^/.*"})).
extract_body_test() ->
Data = << "HTTP header\r\nHeader: value\r\n\r\nbody\r\n" >>,
View
10 src/tsung/ts_client.erl
@@ -1082,13 +1082,13 @@ filter(false,undefined) ->
false;
filter({ok,List},undefined)->
List;
-filter({ok,List},Re) when is_list(List)->
+filter({ok,List},{Include,Re}) when is_list(List)->
Filter=fun(A) ->
case re:run(A,Re) of
- nomatch -> false;
- {match,_} -> true
+ nomatch -> not Include;
+ {match,_} -> Include
end
end,
lists:filter(Filter,List);
-filter({ok,Data},Re) ->
- filter({ok,[Data]},Re).
+filter({ok,Data},{Include,Re}) ->
+ filter({ok,[Data]},{Include,Re}).
View
13 src/tsung_controller/ts_config.erl
@@ -423,11 +423,18 @@ parse(_Element = #xmlElement{name=foreach, attributes=Attrs,content=Content},
VarName = getAttr(atom,Attrs,in),
ForName = getAttr(atom,Attrs,name),
- Filter = case getAttr(string,Attrs,filter)of
- "" -> undefined;
+ Filter = case getAttr(string,Attrs,include) of
+ "" ->
+ case getAttr(string,Attrs,exclude) of
+ "" ->
+ undefined;
+ Re2 ->
+ {ok, RegExp} = re:compile(Re2),
+ {false,RegExp}
+ end;
Re ->
{ok, CompiledRegExp} = re:compile(Re),
- CompiledRegExp
+ {true,CompiledRegExp}
end,
InitialAction = {ctrl_struct, {foreach_start, ForName, VarName, Filter}},
?LOGF("Add foreach_start action in session ~p as id ~p",
View
3 tsung-1.0.dtd
@@ -305,7 +305,8 @@ repeat | if | change_type | foreach)*>
<!ATTLIST foreach
name NMTOKEN #REQUIRED
in NMTOKEN #REQUIRED
- filter CDATA #IMPLIED
+ include CDATA #IMPLIED
+ exclude CDATA #IMPLIED
>
<!ELEMENT repeat (request | thinktime | transaction | setdynvars | for | repeat

0 comments on commit f454fbb

Please sign in to comment.
Something went wrong with that request. Please try again.