Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor tests to use eunit and other goodies.

  • Loading branch information...
commit b2691f06f6f56cf7e6a379be73ad560b57314838 1 parent ce1a665
@mojombo mojombo authored
View
1  .gitignore
@@ -1 +1,2 @@
ebin
+*.dump
View
14 README.md
@@ -10,6 +10,20 @@ structures.
It is currently slower than a slow-motion replay of a cold-weather molasses
drip-race judged by sloths who just took Nyquil. Slowly.
+Installation
+====================
+
+To compile ErlanGit, run the following from within the project directory:
+
+ $ rake build
+
+To test that everything is working properly, run the tests:
+
+ $ rake
+
+When you run the test, the project is built with tests enabled. Before
+deploying to a production system make sure you do a normal build.
+
Basic API
====================
View
22 Rakefile
@@ -1,13 +1,23 @@
require 'rubygems'
require 'rake'
-ERLC_FLAGS = "+debug_info -W2 -o ../ebin"
+ERLC_FLAGS = "+debug_info -W2 -o ebin"
-task :default do
- cd "src"
- sh "erlc #{ERLC_FLAGS} *.erl"
+task :chdir do
+ Dir.chdir(File.join(File.dirname(__FILE__), *%w[.]))
end
-task :console do
- sh "erl +Bc +K true -smp enable -pz ./ebin/ -sname local_console_#{$$} -kernel start_boot_server true"
+task :build => :chdir do
+ sh "mkdir -p ebin"
+ sh "erlc #{ERLC_FLAGS} src/*.erl"
+end
+
+task :default => :chdir do
+ sh "erlc #{ERLC_FLAGS} -DTEST -I etest src/*.erl"
+ # sh "erl -pa ebin -run git test -run git_io test -run erlang halt"
+ sh "erl -pa ebin -eval \"git:test(), git_io:test(), erlang:halt().\""
+end
+
+task :console => :chdir do
+ sh "erl +Bc +K true -smp enable -pa ebin -sname local_console_#{$$} -kernel start_boot_server true"
end
View
0  t/000-benchmarks.t → contrib/benchmarks.es
File renamed without changes
View
10 etest/git_io_test.erl
@@ -0,0 +1,10 @@
+-include_lib("eunit/include/eunit.hrl").
+
+print_log_test() ->
+ Git = git:open("test_git"),
+ git_io:print_log(Git, ["25daa907ccb6feb267bfec70a130d5fe13e48a79"]).
+
+ls_tree_test() ->
+ Git = git:open("test_git"),
+ {ok, Tree} = git:object(Git, "c67da89afe12df86e7b8324f1ac5fa470de2bb48"),
+ git_io:print_tree(Tree).
View
45 etest/git_test.erl
@@ -0,0 +1,45 @@
+-include_lib("eunit/include/eunit.hrl").
+
+object_data_blob_test() ->
+ Git = git:open("test_git"),
+ {blob, 13, <<"test\nanother\n">>} = git:object_data(Git, "8d47f3435ce5dfd0b2ab5758590c2db21b5294b4").
+
+object_data_tree_test() ->
+ Git = git:open("test_git"),
+ Data = <<49,48,48,54,52,52,32,82,69,65,68,77,69,0,157,174,175,185,134,76,244,48,
+ 85,174,147,190,176,175,214,199,209,68,191,164,52,48,48,48,48,32,100,
+ 105,114,111,110,101,0,128,43,239,80,141,163,41,195,101,202,199,105,170,
+ 6,7,56,74,5,166,173,52,48,48,48,48,32,100,105,114,116,119,111,0,1,50,
+ 186,7,196,230,60,172,232,178,133,56,3,228,235,228,20,151,111,253>>,
+ {tree, 100, Data} = git:object_data(Git, "aa7dfe7c2a634cb9e7a9d5838eb58fe150ebd7fb").
+
+object_exists_test() ->
+ Git = git:open("test_git"),
+ true = git:object_exists(Git, "8d47f3435ce5dfd0b2ab5758590c2db21b5294b4"), %% LooseT
+ false = git:object_exists(Git, "ad47f3435ce5afd0b2ab5758590c2db21b5294b4"), %% LooseF
+ true = git:object_exists(Git, "be62addb149d286893e2ec254e0dc783a871e8af"), %% PackT
+ false = git:object_exists(Git, "ae62addb149d286893e2ec254e0dc783a871e8af"). %% PackF
+
+cat_file_packed_delta_test() ->
+ Git = git:open("test_git"),
+ Data = <<49,48,48,54,52,52,32,82,69,65,68,77,69,0,157,174,175,185,134,76,244,48,
+ 85,174,147,190,176,175,214,199,209,68,191,164,52,48,48,48,48,32,100,
+ 105,114,111,110,101,0,128,43,239,80,141,163,41,195,101,202,199,105,170,
+ 6,7,56,74,5,166,173>>,
+ {tree, 67, Data} = git:object_data(Git, "9cad8d7e8ee5b3b6fcb401ac9dcc557dd808762d").
+
+cat_file_packed_ref_delta_test() ->
+ Git = git:open("test_git"),
+ Data = <<"# -*- ruby -*-\n\nrequire 'rubygems'\nrequire 'hoe'\nrequire './lib/grit.rb'\n\nHoe.new('grit', Grit::VERSION) do |p|\n p.rubyforge_name = 'grit'\n # p.author = 'FIX'\n # p.email = 'FIX'\n # p.summary = 'FIX'\n # p.description = p.paragraphs_of('README.txt', 2..5).join(\"\\n\\n\")\n # p.url = p.paragraphs_of('README.txt', 0).first.split(/\\n/)[1..-1]\n p.changes = p.paragraphs_of('History.txt', 0..1).join(\"\\n\\n\")\nend\n\n# vim: syntax=Ruby\n">>,
+ {blob, 430, Data} = git:object_data(Git, "ff69c3684a18592c741332b290492aa39d980e02").
+
+rev_list_test() ->
+ Git = git:open("test_git"),
+ RevList = ["25daa907ccb6feb267bfec70a130d5fe13e48a79",
+ "dd991a4966e8807d448305e67a9b3727efc6060c",
+ "be62addb149d286893e2ec254e0dc783a871e8af",
+ "208fc4a6a08fb1e5136cf9943d79ad81097a0f36",
+ "ef8285c69ceac3f2ff2fee154d3d6ad6a71fb826",
+ "61fa970afbf82f79611220203213cd9562a809e3",
+ "a361a3163a1b521f277e3877232d94b787750c36"],
+ RevList = git:rev_list(Git, ["25daa907ccb6feb267bfec70a130d5fe13e48a79"]).
View
4 src/git.erl
@@ -6,6 +6,10 @@
-module(git).
-export([open/1, object_data/2, object/2, object_exists/2, rev_list/2]).
+-ifdef(TEST).
+-include("etest/git_test.erl").
+-endif.
+
-include("git.hrl").
%%-define(cassandra_ZERO, 0).
View
4 src/git_io.erl
@@ -5,6 +5,10 @@
-module(git_io).
-export([print_log/2, print_tree/1]).
+-ifdef(TEST).
+-include("etest/git_io_test.erl").
+-endif.
+
-include("git.hrl").
%print_branches(Git) ->
View
10 t/001-cat-file-loose.t
@@ -1,10 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-%%! -pa ./ebin -sasl -boot start_sasl -noshell
-
-main(_) ->
- Git = git:open("test_git"),
- {Type, Size, Data} = git:object_data(Git, "8d47f3435ce5dfd0b2ab5758590c2db21b5294b4"), %% blob
- io:fwrite("Data: ~p ~p~n", [Type, Size]),
- io:fwrite("Data: ~p~n", [Data]).
-
View
12 t/002-cat-file-packed.t
@@ -1,12 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-%%! -pa ./ebin -sasl -boot start_sasl -noshell
-
-main(_) ->
- Git = git:open("test_git"),
- {Type, Size, Data} = git:object_data(Git, "aa7dfe7c2a634cb9e7a9d5838eb58fe150ebd7fb"), %% tree
- %{Type, Size, Data} = git:object_data(Git, "be62addb149d286893e2ec254e0dc783a871e8af"), %% tree
- io:fwrite("Data: ~p ~p~n", [Type, Size]),
- io:fwrite("Data: ~p~n", [Data]),
- io:fwrite("Data: ~s~n", [binary_to_list(Data)]).
-
View
15 t/003-object_exists.t
@@ -1,15 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-%%! -pa ./ebin -sasl -boot start_sasl -noshell
-
-main(_) ->
- Git = git:open("test_git"),
- Result = git:object_exists(Git, "8d47f3435ce5dfd0b2ab5758590c2db21b5294b4"), %% blob
- io:fwrite("LooseT: ~p ~n", [Result]),
- Result2 = git:object_exists(Git, "ad47f3435ce5afd0b2ab5758590c2db21b5294b4"), %% blob
- io:fwrite("LooseF: ~p ~n", [Result2]),
- Result3 = git:object_exists(Git, "be62addb149d286893e2ec254e0dc783a871e8af"), %% blob
- io:fwrite("PackT : ~p ~n", [Result3]),
- Result4 = git:object_exists(Git, "ae62addb149d286893e2ec254e0dc783a871e8af"), %% blob
- io:fwrite("PackF : ~p ~n", [Result4]).
-
View
11 t/004-cat-file-packed-delta.t
@@ -1,11 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-%%! -pa ./ebin -sasl -boot start_sasl -noshell
-
-main(_) ->
- Git = git:open("test_git"),
- {Type, Size, Data} = git:object_data(Git, "9cad8d7e8ee5b3b6fcb401ac9dcc557dd808762d"), %% tree
- io:fwrite("Data: ~p ~p~n", [Type, Size]),
- io:fwrite("Data: ~p~n", [Data]),
- io:fwrite("Data: ~s~n", [binary_to_list(Data)]).
-
View
11 t/005-cat-file-packed_ref_delta.t
@@ -1,11 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-%%! -pa ./ebin -sasl -boot start_sasl -noshell
-
-main(_) ->
- Git = git:open("test_git"),
- {Type, Size, Data} = git:object_data(Git, "ff69c3684a18592c741332b290492aa39d980e02"), %% blob
- io:fwrite("Data: ~p ~p~n", [Type, Size]),
- io:fwrite("Data: ~p~n", [Data]),
- io:fwrite("Data: ~s~n", [binary_to_list(Data)]).
-
View
9 t/006-rev-list.t
@@ -1,9 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-%%! -pa ./ebin -sasl -boot start_sasl -noshell
-
-main(_) ->
- Git = git:open("test_git"),
- RevList = git:rev_list(Git, ["25daa907ccb6feb267bfec70a130d5fe13e48a79"]), %% blob
- io:fwrite("RevList: ~p~n", [RevList]).
-
View
8 t/007-git-simple-log.t
@@ -1,8 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-%%! -pa ./ebin -sasl -boot start_sasl -noshell
-
-main(_) ->
- Git = git:open("test_git"),
- git_io:print_log(Git, ["25daa907ccb6feb267bfec70a130d5fe13e48a79"]).
-
View
9 t/008-ls-tree.t
@@ -1,9 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-%%! -pa ./ebin -sasl -boot start_sasl -noshell
-
-main(_) ->
- Git = git:open("test_git"),
- {ok, Tree} = git:object(Git, "c67da89afe12df86e7b8324f1ac5fa470de2bb48"),
- git_io:print_tree(Tree).
-
Please sign in to comment.
Something went wrong with that request. Please try again.