Author: vborja
Date: Thu Apr 10 17:56:08 2008
New Revision: 647023

URL: http://svn.apache.org/viewvc?rev=647023&view=rev
Log:
Name validation on Project.define

Project.define makes sure that the name to be defined is not
already being used for a task.
If so, we fail telling the user not to use a task name for his project,
without this validation buildr would still fail but with a Rake error
message that is not so helpful.

Modified:
    incubator/buildr/trunk/lib/buildr/core/project.rb
    incubator/buildr/trunk/spec/project_spec.rb

Modified: incubator/buildr/trunk/lib/buildr/core/project.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/project.rb?rev=647023&r1=647022&r2=647023&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/project.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/project.rb Thu Apr 10 17:56:08 2008
@@ -198,6 +198,10 @@
         Buildr.application.current_scope == name.split(':')[0...-1] or
           raise "You can only define a sub project (#{name}) within the 
definition of its parent project"
 
+        # Projects with names like: compile, test, build are invalid, so we 
have
+        # to make sure the project has not the name of an already defined task
+        raise "Invalid project name: #{name.inspect} is already used for a 
task" if Buildr.application.lookup(name)
+
         @projects ||= {}
         raise "You cannot define the same project (#{name}) more than once" if 
@projects[name]
         Project.define_task(name).tap do |project|

Modified: incubator/buildr/trunk/spec/project_spec.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/project_spec.rb?rev=647023&r1=647022&r2=647023&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/project_spec.rb (original)
+++ incubator/buildr/trunk/spec/project_spec.rb Thu Apr 10 17:56:08 2008
@@ -27,6 +27,12 @@
     lambda { project('foo') }.should raise_error(RuntimeError, /No such 
project/)
   end
 
+  it 'should fail to be defined if its name is already used for a task' do
+    lambda { define('test') }.should raise_error(RuntimeError, /Invalid 
project name/i)
+    lambda { define('valid') { define('build') } }.should 
raise_error(RuntimeError, /Invalid project name/i)
+    lambda { define('valid') { define('valid:compile') } }.should 
raise_error(RuntimeError, /Invalid project name/i)
+  end
+
   it 'should exist once defined' do
     define 'foo'
     lambda { project('foo') }.should_not raise_error


Reply via email to