Permalink
Browse files

tidy

  • Loading branch information...
1 parent be4cebd commit 513e92d33fd42e283dfb23e2ac0196c2c325e7f9 @freke committed Oct 24, 2011
Showing with 576 additions and 407 deletions.
  1. +80 −67 test/erlang_protobuffs_SUITE.erl
  2. +41 −33 test/protobuffs_compile_tests.erl
  3. +179 −148 test/protobuffs_proper.erl
  4. +276 −159 test/protobuffs_tests.erl
@@ -98,8 +98,8 @@ groups() -> [].
%% @end
%%--------------------------------------------------------------------
all() ->
- [protobuffs_test_case, protobuffs_packed_test_case, test_proto_files,
- test_extendable_messages].
+ [protobuffs_test_case, protobuffs_packed_test_case,
+ test_proto_files, test_extendable_messages].
%%--------------------------------------------------------------------
%% @spec TestCase() -> Info
@@ -134,81 +134,94 @@ protobuffs_packed_test_case(Config) ->
test_proto_files(Config) ->
DataDir = (?config(data_dir, Config)),
NumTests = (?config(num_tests, Config)),
- ProtoFiles = filelib:wildcard(filename:join([DataDir,"proto","*.proto"])),
-
- TestProtoFile = fun(ProtoFile,Acc) ->
+ ProtoFiles = filelib:wildcard(filename:join([DataDir,
+ "proto", "*.proto"])),
+ TestProtoFile = fun (ProtoFile, Acc) ->
Path = filename:absname(ProtoFile),
- Message = filename:basename(ProtoFile,".proto"),
+ Message = filename:basename(ProtoFile, ".proto"),
test_server:format("~n===Testcase ~p, testing message ~p===~n",
[self(), Message]),
test_server:format("Testcase ~p, parse file ~p",
[self(), Path]),
- protobuffs_compile:scan_file(
- Path,
- [{imports_dir, [filename:join([DataDir,"proto"]),
- filename:join([DataDir,"proto","import"])]}]),
- Test = list_to_atom("proper_protobuffs_"++Message),
- Result = proper:quickcheck(
- proper:numtests(
- NumTests,
- protobuffs_proper:Test()),[long_result,
- {on_output, fun(".",_) -> ok;
- (S,F) -> test_server:format(S,F)
- end}]),
+ protobuffs_compile:scan_file(Path,
+ [{imports_dir,
+ [filename:join([DataDir,
+ "proto"]),
+ filename:join([DataDir,
+ "proto",
+ "import"])]}]),
+ Test = list_to_atom("proper_protobuffs_" ++
+ Message),
+ Result = proper:quickcheck(proper:numtests(NumTests,
+ protobuffs_proper:Test()),
+ [long_result,
+ {on_output,
+ fun (".", _) -> ok;
+ (S, F) ->
+ test_server:format(S,
+ F)
+ end}]),
case Result of
- true -> test_server:format("Test ~p: ok~n~n~n",[Message]),
- Acc andalso true;
- F -> test_server:format("Test ~p: Failed with ~p~n~n~n",[Message,Result]),
- false
+ true ->
+ test_server:format("Test ~p: ok~n~n~n",
+ [Message]),
+ Acc andalso true;
+ F ->
+ test_server:format("Test ~p: Failed with ~p~n~n~n",
+ [Message, Result]),
+ false
end
end,
- case lists:foldl(TestProtoFile,true,ProtoFiles) of
- true -> ok;
- _ -> ct:fail("One or more property test cases failed")
+ case lists:foldl(TestProtoFile, true, ProtoFiles) of
+ true -> ok;
+ _ -> ct:fail("One or more property test cases failed")
end.
test_extendable_messages(Config) ->
DataDir = (?config(data_dir, Config)),
NumTests = (?config(num_tests, Config)),
ProtoFiles = [begin
- Filename = filename:join([DataDir,"proto",X]),
- Path = filename:absname(Filename),
- Options = [{imports_dir, [
- filename:join([DataDir,"proto"]),
- filename:join([DataDir,"proto","import"])
- ]}],
- protobuffs_compile:scan_file(Path,Options)
- end || X <- ["extend.proto","extensions.proto"]],
- Tests = [
- proper_protobuffs_extend_degraded,
- proper_protobuffs_extend_assign,
- proper_protobuffs_extend_get,
- proper_protobuffs_extend_has_enum,
- proper_protobuffs_extend_has_message,
- proper_protobuffs_extend_has_string
- ],
- Folder = fun(Testname,Acc) ->
- test_server:format("~n===Extensions Testcase ~p===~n",[Testname]),
- Result = proper:quickcheck(proper:numtests(NumTests, protobuffs_proper:Testname()),[
- long_result,
- {on_output, fun(".",_) -> ok;
- (S,F) -> test_server:format(S,F)
- end}
- ]),
- case Result of
- true ->
- test_server:format("Test ~p: ok~n~n~n",[Testname]),
- Acc andalso true;
- _ ->
- test_server:format("Test ~p: Failed with ~p~n~n~n",[Testname,Result]),
- false
- end
- end,
- BigRes = lists:foldl(Folder,true,Tests),
- case BigRes of
- true -> ok;
- _ -> ct:fail("One or more extension tests failed")
- end.
+ Filename = filename:join([DataDir, "proto", X]),
+ Path = filename:absname(Filename),
+ Options = [{imports_dir,
+ [filename:join([DataDir, "proto"]),
+ filename:join([DataDir, "proto", "import"])]}],
+ protobuffs_compile:scan_file(Path, Options)
+ end
+ || X <- ["extend.proto", "extensions.proto"]],
+ Tests = [proper_protobuffs_extend_degraded,
+ proper_protobuffs_extend_assign,
+ proper_protobuffs_extend_get,
+ proper_protobuffs_extend_has_enum,
+ proper_protobuffs_extend_has_message,
+ proper_protobuffs_extend_has_string],
+ Folder = fun (Testname, Acc) ->
+ test_server:format("~n===Extensions Testcase ~p===~n",
+ [Testname]),
+ Result = proper:quickcheck(proper:numtests(NumTests,
+ protobuffs_proper:Testname()),
+ [long_result,
+ {on_output,
+ fun (".", _) -> ok;
+ (S, F) ->
+ test_server:format(S,
+ F)
+ end}]),
+ case Result of
+ true ->
+ test_server:format("Test ~p: ok~n~n~n", [Testname]),
+ Acc andalso true;
+ _ ->
+ test_server:format("Test ~p: Failed with ~p~n~n~n",
+ [Testname, Result]),
+ false
+ end
+ end,
+ BigRes = lists:foldl(Folder, true, Tests),
+ case BigRes of
+ true -> ok;
+ _ -> ct:fail("One or more extension tests failed")
+ end.
%%---------------------------------------------------------------------
%% Help flies
@@ -223,8 +236,8 @@ parse(FileName) ->
loop(InFile, Acc) ->
case io:request(InFile,
{get_until, prompt, protobuffs_scanner, token, [1]})
- of
- {ok, Token, _EndLine} -> loop(InFile, Acc ++ [Token]);
- {error, token} -> exit(scanning_error);
- {eof, _} -> Acc
+ of
+ {ok, Token, _EndLine} -> loop(InFile, Acc ++ [Token]);
+ {error, token} -> exit(scanning_error);
+ {eof, _} -> Acc
end.
@@ -12,48 +12,56 @@
-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").
-
+
setup() ->
Modules = [protobuffs_file],
meck:new(Modules),
- meck:expect(protobuffs_file,open,fun(_,_) -> {ok,in_file} end),
- meck:expect(protobuffs_file,close,fun(_) -> ok end),
- meck:expect(protobuffs_file,request,fun(_) -> {eof,dummy} end),
- meck:expect(protobuffs_file,compile_forms,fun(_,_) -> {ok, dummy, <<"Bytest">>, dummy} end),
- meck:expect(protobuffs_file,write_file,fun(_,_) -> ok end),
- meck:expect(protobuffs_file,format,fun(_,_,_) -> ok end),
- meck:expect(protobuffs_file,path_open, fun(Path,FileName,_) -> {ok, io_device, filename:join([Path,FileName])} end),
+ meck:expect(protobuffs_file, open,
+ fun (_, _) -> {ok, in_file} end),
+ meck:expect(protobuffs_file, close, fun (_) -> ok end),
+ meck:expect(protobuffs_file, request,
+ fun (_) -> {eof, dummy} end),
+ meck:expect(protobuffs_file, compile_forms,
+ fun (_, _) -> {ok, dummy, <<"Bytest">>, dummy} end),
+ meck:expect(protobuffs_file, write_file,
+ fun (_, _) -> ok end),
+ meck:expect(protobuffs_file, format,
+ fun (_, _, _) -> ok end),
+ meck:expect(protobuffs_file, path_open,
+ fun (Path, FileName, _) ->
+ {ok, io_device, filename:join([Path, FileName])}
+ end),
Modules.
-cleanup(Modules) ->
- meck:unload(Modules).
-
+cleanup(Modules) -> meck:unload(Modules).
+
scan_file_test_() ->
- {foreach,
- fun setup/0,
- fun cleanup/1,
- [?_assertMatch(ok,protobuffs_compile:scan_file(dummy_file)),
- ?_assertMatch(ok,protobuffs_compile:scan_file("dummy_file.proto"))]}.
+ {foreach, fun setup/0, fun cleanup/1,
+ [?_assertMatch(ok,
+ (protobuffs_compile:scan_file(dummy_file))),
+ ?_assertMatch(ok,
+ (protobuffs_compile:scan_file("dummy_file.proto")))]}.
scan_string_test_() ->
- {setup,
- fun setup/0,
- fun cleanup/1,
- [?_assertMatch(ok,protobuffs_compile:scan_string("","dummy"))]}.
+ {setup, fun setup/0, fun cleanup/1,
+ [?_assertMatch(ok,
+ (protobuffs_compile:scan_string("", "dummy")))]}.
generate_source_test_() ->
- {foreach,
- fun setup/0,
- fun cleanup/1,
- [?_assertMatch(ok,protobuffs_compile:generate_source(dummy_file)),
- ?_assertMatch(ok,protobuffs_compile:generate_source("dummy_file.proto"))]}.
+ {foreach, fun setup/0, fun cleanup/1,
+ [?_assertMatch(ok,
+ (protobuffs_compile:generate_source(dummy_file))),
+ ?_assertMatch(ok,
+ (protobuffs_compile:generate_source("dummy_file.proto")))]}.
parse_imports_test_() ->
- {foreach,
- fun setup/0,
- fun cleanup/1,
- [?_assertMatch([],protobuffs_compile:parse_imports([],dummy_path)),
- ?_assertMatch([{import , dummy_import_file}],
- protobuffs_compile:parse_imports(
- [{import,dummy_import_file}],"dummy_path")),
- ?_assertMatch([what_ever],protobuffs_compile:parse_imports([what_ever],dummy_path))]}.
+ {foreach, fun setup/0, fun cleanup/1,
+ [?_assertMatch([],
+ (protobuffs_compile:parse_imports([], dummy_path))),
+ ?_assertMatch([{import, dummy_import_file}],
+ (protobuffs_compile:parse_imports([{import,
+ dummy_import_file}],
+ "dummy_path"))),
+ ?_assertMatch([what_ever],
+ (protobuffs_compile:parse_imports([what_ever],
+ dummy_path)))]}.
Oops, something went wrong.

0 comments on commit 513e92d

Please sign in to comment.