Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jacob Vorreuter
committed
May 1, 2009
1 parent
c7834cc
commit eb12b70
Showing
13 changed files
with
1,547 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ all: | |
mkdir -p ebin/ | ||
#(cd templates;$(MAKE)) | ||
(cd src;$(MAKE)) | ||
(cd t;$(MAKE)) | ||
|
||
test: all | ||
prove -v t/*.t | ||
|
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
-module(ex_engine). | ||
-export([run/1]). | ||
|
||
-include("excavator.hrl"). | ||
|
||
%% when a list of instructions is passed in, create a | ||
%% new state and begin processing | ||
run(Instructions) when is_list(Instructions) -> | ||
run(#state{instructions=Instructions}); | ||
|
||
%% finished running | ||
run(#state{instructions=[], stack=[]}) -> | ||
ok; | ||
|
||
%% finished local instruction set, pop stack | ||
run(#state{instructions=[], stack=[#state{instructions=[{instr, onfail, _}|Instrs]}=S|_]}) -> | ||
run(S#state{instructions=Instrs}); | ||
|
||
run(#state{instructions=[], stack=[OldState|_]}) -> | ||
run(OldState); | ||
|
||
run(#state{instructions=[Instr|Instrs], stack=Stack}=State) -> | ||
NewState0 = | ||
case keep_instruction(Instr) of | ||
true -> State#state{instructions=[Instr|Instrs]}; | ||
false -> State#state{instructions=Instrs} | ||
end, | ||
case catch ex_consumer:execute(Instr, NewState0) of | ||
{'EXIT', Error} -> | ||
case Stack of | ||
[#state{instructions=[{instr, onfail, [_, FailInstrs]}|InstrsTail]}=OldState|StackTail] -> | ||
NewStack = [OldState#state{instructions=InstrsTail}|StackTail], | ||
NewState1 = #state{instructions=FailInstrs, stack=NewStack}, | ||
run(NewState1); | ||
_ -> | ||
exit(Error) %% perhaps someone else will enjoy this | ||
end; | ||
NewState1 -> | ||
run(NewState1) | ||
end. | ||
|
||
%% internal functions | ||
keep_instruction({instr, Instr, _}) when Instr==each; Instr==onfail -> true; | ||
keep_instruction(_) -> false. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
include ../support/include.mk | ||
|
||
all: $(EBIN_FILES) | ||
|
||
debug: | ||
$(MAKE) DEBUG=-DDEBUG | ||
|
||
clean: | ||
rm -rf $(EBIN_FILES) erl_crash.dump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/local/bin/escript | ||
%% -*- erlang -*- | ||
%%! -pa ebin -sasl errlog_type error -boot start_sasl -noshell | ||
|
||
main(_) -> | ||
etap:plan(unknown), | ||
case (catch start()) of | ||
{'EXIT', Err} -> | ||
io:format("# ~p~n", [Err]), | ||
etap:bail(); | ||
_ -> | ||
etap:end_tests() | ||
end, | ||
ok. | ||
|
||
start() -> | ||
application:start(inets), | ||
test_server:start_link(), | ||
Instrs = | ||
[ {instr, configure, [qps, 10]}, | ||
{instr, fetch, [artist_page, {get, "http://127.0.0.1:8888/gracenote_albums.html"}]}, | ||
{instr, assert, [artist_page, {status, 200}]}, | ||
{instr, assert, [artist_page, string]}, | ||
{instr, assign, [albums, {xpath, artist_page, "//div[@class='album-meta-data-wrapper']"}]}, | ||
{instr, assert, [albums, list_of_nodes]}, | ||
{instr, each, [album, albums, [ | ||
{instr, assign, [album_href, {xpath, album, "//a[1]/@href"}]}, | ||
{instr, assign, [album_id, {regexp, album_href, compile_re("tui_id=(.*)tui")}]}, | ||
{instr, assert, [album_id, string]}, | ||
{instr, fetch, [album_page, {get, ["http://127.0.0.1:8888/gracenote_album_", album_id, ".html"]}]}, | ||
{instr, onfail, [ | ||
[ {instr, assert, [album_page, {status, 200}]}, | ||
{instr, assert, [album_page, string]}, | ||
{instr, assign, [album_name_node, {xpath, album_page, "//div[@class='album-name']"}]}, | ||
{instr, assert, [album_name_node, node]}, | ||
{instr, assign, [album_name, {regexp, album_name_node, compile_re(" > (.*)</div>")}]}, | ||
{instr, assert, [album_name, string]}, | ||
{instr, commit, [{album, beatles}, {album_id, album_name}]}, | ||
{instr, print, [album_name]} | ||
], | ||
[{instr, function, [fun(S) -> io:format("This shit fAiLeD~n") end]}] | ||
]} | ||
]]} | ||
], | ||
|
||
ex_engine:run(Instrs), | ||
|
||
ok. | ||
|
||
compile_re(Regexp) -> | ||
{ok, RE} = re:compile(Regexp), RE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-module(test_server). | ||
-behaviour(web_server). | ||
|
||
-export([start_link/0]). | ||
|
||
%% web_server callbacks | ||
-export([dispatch/2]). | ||
|
||
start_link() -> | ||
web_server:start(?MODULE, [{address, "127.0.0.1"}, {port, 8888}]). | ||
|
||
%%==================================================================== | ||
%% web_server callbacks | ||
%%==================================================================== | ||
|
||
%%-------------------------------------------------------------------- | ||
%% Function: dispatch(Req, PathTokens) -> {reply, Status, Headers, Body} | | ||
%% {reply, Module, Function, Args} | | ||
%% undefined | ||
%% Req = mochiweb_request() | ||
%% PathTokens = list() | ||
%%-------------------------------------------------------------------- | ||
dispatch(_, _) -> | ||
undefined. |