Skip to content

Commit

Permalink
Add test for #18 and #24
Browse files Browse the repository at this point in the history
  • Loading branch information
klmr committed Jun 17, 2014
1 parent 66b0f58 commit 8a3f337
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions inst/tests/modules/a.r
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ inc = function ()

`+.string` = function (a, b)
paste(a, b, sep = '')

which = function () '/a'
2 changes: 2 additions & 0 deletions inst/tests/modules/nested/a/__init__.r
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
cat('a/__init__.r\n')

which = function () 'nested/a'
6 changes: 6 additions & 0 deletions inst/tests/modules/nested/relative_a.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a = import('a')
local_a = import('./a')

a_which = function () a$which()

local_a_which = function () local_a$which()
27 changes: 27 additions & 0 deletions inst/tests/test-relative-import.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
context('Relative imports test')

setup = function () {
thispath = file.path(getwd(), 'modules/nested')
prev = getOption('import.path')
if (! identical(prev, thispath))
previous_import_path <<- prev
options(import.path = thispath)
}

teardown = function () {
options(import.path = previous_import_path)
}

test_that('Imports are absolute by default', {
on.exit(teardown())
setup()
ra = import('relative_a')
expect_that(ra$a_which(), equals('/a'))
})

test_that('Relative import are always local', {
on.exit(teardown())
setup()
ra = import('relative_a')
expect_that(ra$local_a_which(), equals('nested/a'))
})

0 comments on commit 8a3f337

Please sign in to comment.