Use eunit for tests

This commit is contained in:
Alexey Romanov
2010-10-12 15:02:37 +04:00
parent b1b0869bc3
commit 27720f493e
2 changed files with 19 additions and 12 deletions

View File

@@ -14,7 +14,7 @@ all: compile docs
test: compile_test test: compile_test
$(ERL) -noshell -pa ebin \ $(ERL) -noshell -pa ebin \
-eval 'eunit:dir("ebin")' \ -eval 'eunit:test({dir, "ebin"})' \
-s init stop -s init stop
compile: compile_c compile: compile_c

View File

@@ -7,11 +7,6 @@
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
-module(sqlite3_test). -module(sqlite3_test).
%% API
-export([create_table_test/0]).
-record(user, {name, age, wage}).
%%==================================================================== %%====================================================================
%% API %% API
%%==================================================================== %%====================================================================
@@ -19,20 +14,32 @@
%% Function: %% Function:
%% Description: %% Description:
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
create_table_test() -> create_table_test() ->
file:delete("ct.db"), file:delete("ct.db"),
sqlite3:open(ct), sqlite3:open(ct),
sqlite3:create_table(ct, user, [{name, text}, {age, integer}, {wage, integer}]), sqlite3:create_table(ct, user, [{id, integer, [primary_key]}, {name, text}, {age, integer}, {wage, integer}]),
[user] = sqlite3:list_tables(ct), [user] = sqlite3:list_tables(ct),
[{name, primary_key}, {age, integer}, {wage, integer}] = sqlite3:table_info(ct, user), [{id, integer, [primary_key]}, {name, text}, {age, integer}, {wage, integer}] = sqlite3:table_info(ct, user),
sqlite3:write(ct, user, [{name, "abby"}, {age, 20}, {wage, 2000}]), {id, Id1} = sqlite3:write(ct, user, [{name, "abby"}, {age, 20}, {wage, 2000}]),
sqlite3:write(ct, user, [{name, "marge"}, {age, 30}, {wage, 3000}]), Id1 = 1,
sqlite3:sql_exec(ct, "select * from user;"), {id, Id2} = sqlite3:write(ct, user, [{name, "marge"}, {age, 30}, {wage, 2000}]),
sqlite3:read(ct, user, {name, "abby"}), Id2 = 2,
[{columns, Columns}, {rows, Rows1}] = sqlite3:sql_exec(ct, "select * from user;"),
Columns = ["id", "name", "age", "wage"],
Rows1 = [{1, <<"abby">>, 20, 2000}, {2, <<"marge">>, 30, 2000}],
[{columns, Columns}, {rows, Rows2}] = sqlite3:read(ct, user, {name, "abby"}),
Rows2 = [{1, <<"abby">>, 20, 2000}],
[{columns, Columns}, {rows, Rows1}] = sqlite3:read(ct, user, {wage, 2000}),
sqlite3:delete(ct, user, {name, "abby"}), sqlite3:delete(ct, user, {name, "abby"}),
sqlite3:drop_table(ct, user), sqlite3:drop_table(ct, user),
%sqlite3:delete_db(ct) %sqlite3:delete_db(ct)
sqlite3:close(ct). sqlite3:close(ct).
-endif.
% create, read, update, delete % create, read, update, delete
%%==================================================================== %%====================================================================
%% Internal functions %% Internal functions