lunarmodules / busted

Elegant Lua unit testing.
https://lunarmodules.github.io/busted/
MIT License
1.39k stars 184 forks source link

add a function for current file location, to find relative fixtures #644

Closed Tieske closed 3 years ago

Tieske commented 3 years ago

Add a busted function busted.path (?) that returns the absolute path of the current test file.

file /lua/my-project/spec/01-unit/some-unit-test_spec.lua:

it("some test", function()
    assert.equal("/lua/my-project/spec/01-unit", busted.path())
    assert.equal("/lua/my-project/fixtures/template.txt", busted.path("../fixtures/template.txt"))

    local logfile = busted.path("servroot/logs/error.log") -- /lua/my-project/spec/servroot/logs/error.log
end)