slash-lang / slash

A new language for the web
http://slash-lang.org
MIT License
386 stars 22 forks source link

test.sl doesn't work from the test directory #5

Open acook opened 11 years ago

acook commented 11 years ago

Given: slash-cli is compiled and you have the slash source code

When: You're in the slash/test directory And: You run slash-cli test.sl core/array.sl Then: You see this error:

NameError: Undefined constant 'Test' in Object
  at <main> in /Users/acook/Pork/slash/test/test.sl, line 3
  at <main> in test.sl, line 3

However

When: You're in the slash root source directory And: You run slash-cli test/test.sl test/core/array.sl Then: Tests are run successfully with this output:

...................

Tests finished. 19 passes, 0 failures, 182 assertions.

That seems weird to me. I can't figure out why just from looking at the source code either.

haileys commented 11 years ago

. is in INC by default. I'd like to keep it this way for ease of use, but then you run into issues like this.

I think the best way to solve this would be to put . at the end of INC. Thoughts?

acook commented 11 years ago

Ruby 1.9 deals with a similar problem by requiring ./ at the beginning of require statements that aren't in the path:

require './test'

I think its a pretty solid approach. You shouldn't have to choose between your files and your standard library.

haileys commented 11 years ago

Yeah it works well for Ruby, but not so much for the use case Slash is designed for IMO.

Also, Slash has explicit require but I want to emphasize use Foo::Bar; syntax which doesn't let you specify a full path.

acook commented 11 years ago

Ah, I see, you want autodiscovery of classes. That's actually a more interesting goal.

In that case, you should probably just rename the file to run_test.sl, and establish a convention of avoiding reserved names.

Another option, would be to ignore the current file when doing a lookup, and you might want to do that anyway, but I still think renaming the file is in order.