---
 features/sin_testability.feature |   11 +++++++++++
 src/sinan.erl                    |   24 +++++++++---------------
 test/sin_testability.erl         |   27 +++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 15 deletions(-)
 create mode 100644 features/sin_testability.feature
 create mode 100644 test/sin_testability.erl

diff --git a/features/sin_testability.feature b/features/sin_testability.feature
new file mode 100644
index 0000000..c4be6ac
--- /dev/null
+++ b/features/sin_testability.feature
@@ -0,0 +1,11 @@
+Feature: Make sinan more testable
+  In order to make it easier to test sinan from sinan
+  As an Erlang Developer
+  I want sinan to be able to pass the start directory to the a sinan
+  call instead of having it inferred.
+
+  Scenario: Pass the start dir to a sinan project
+    Given a generated project in a different location then the CWD
+    When a build step is run on this project
+    And a start dir is passed to the build
+    Then sinan should build the project in the location specified by the start 
dir
diff --git a/src/sinan.erl b/src/sinan.erl
index efe7973..70fbb32 100644
--- a/src/sinan.erl
+++ b/src/sinan.erl
@@ -115,7 +115,7 @@ run_sinan(Args) ->
 -spec do_build(term(), [string()]) -> sin_config:config().
 do_build(Options, [Target | Rest]) ->
     do_task(list_to_atom(Target),
-           find_start_dir(Rest),
+           find_start_dir(Options),
            setup_config_overrides(Options, Rest));
 do_build(Options, []) ->
     do_build(Options, ["build"]).
@@ -136,6 +136,7 @@ usage(OptSpecList) ->
 option_spec_list() ->
     [{verbose, $v, "verbose", {boolean, false},
       "Be verbose about what gets done"},
+     {start_dir, $s, "start-dir", string, "The search location for the 
project"},
      {release, $r, "release", string, "the release to build"},
      {project, $p, "project", string, "the name of the project"},
      {version, $n, "nversion", string, "the version of the project"}].
@@ -172,20 +173,12 @@ run_task(Task, ProjectDir, BuildConfig) ->
     end.
 
 %% @doc parse the start dir out of the args passed in.
--spec find_start_dir(args()) -> string().
-find_start_dir({obj, Data}) ->
-    find_start_dir(Data);
-find_start_dir(Data) ->
-    case lists:keysearch("build", 1, Data) of
-         {value, {"build", {obj, Data2}}} ->
-            case lists:keysearch("start_dir", 1,  Data2) of
-                {value, {"start_dir", StartDir}} ->
-                    StartDir;
-                _ ->
-                   {ok, Dir} = file:get_cwd(),
-                   Dir
-            end;
-        _ ->
+-spec find_start_dir(Options::term()) -> string().
+find_start_dir(Options) ->
+    case lists:keysearch(start_dir, 1, Options) of
+         {value, {start_dir, StartDir}} ->
+           StartDir;
+       _ ->
            {ok, Dir} = file:get_cwd(),
            Dir
     end.
@@ -197,6 +190,7 @@ setup_config_overrides(Options, Args) ->
     push_values_if_exist(sin_config:parse_args(Args, sin_config:new()),
                         Options,
                         [{release, "-r"},
+                         {start_dir, "start_dir"},
                          {project, "project.name"},
                          {version, "project.vsn"}]).
 
diff --git a/test/sin_testability.erl b/test/sin_testability.erl
new file mode 100644
index 0000000..fc87cca
--- /dev/null
+++ b/test/sin_testability.erl
@@ -0,0 +1,27 @@
+%%%-------------------------------------------------------------------
+%%% @copyright (C) 2011, Erlware, LLC.
+%%% @doc
+%%%  Test the ability to specify a start directory
+%%% @end
+%%% Created :  5 Sep 2011 by Eric Merritt <[email protected]>
+%%%-------------------------------------------------------------------
+-module(sin_testability).
+
+-export([given/2, 'when'/2, then/2, step/2]).
+
+% Step definitions for the sample calculator Addition feature.
+
+given([a, generated, project, in, a, different, location, then, the, 'CWD'],
+      _) ->
+    io:format("~p~n", [file:get_cwd()]).
+
+'when'([a, build, step, is, run, on, this, project], _) ->
+    ok;
+'when'([a, start, dir, is, passed, to, the, build], _) ->
+    ok.
+
+then([sinan, should, build, the, project, in, the, location,
+      specified, by, the, start, dir], _) ->
+    ok.
+
+step(_, _) -> undefined.
-- 
1.7.5.2

-- 
You received this message because you are subscribed to the Google Groups 
"erlware-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/erlware-dev?hl=en.

Reply via email to