Module luatest.treegen | Tarantool
Reference Rocks reference Luatest Module luatest.treegen

Module luatest.treegen

Working tree generator.

Generates a tree of Lua files using provided templates and filenames.

local t = require('luatest')
local treegen = require('luatest.treegen')

local g = t.group()

g.test_foo = function(g)
    treegen.add_template('^.*$', 'test_script')
    local dir = treegen.prepare_directory({'foo/bar.lua', 'main.lua'})
    ...
end

Save the template with the given pattern.

Parameters:

  • pattern: (string) File name template
  • template: (string) A content template for creating a file.

Create a temporary directory with given contents.

The contents are generated using templates added by treegen.add_template().

Parameters:

  • contents: (tab) List of bodies of the content to write.
  • replacements: (tab) List of replacement templates. (optional)

Returns:

string

Example for {'foo/bar.lua', 'baz.lua'}:

/
+ tmp/
  + rfbWOJ/
    + foo/
    | + bar.lua
    + baz.lua

The return value is '/tmp/rfbWOJ' for this example.

Remove the template by pattern.

Parameters:

  • pattern: (string) File name template

Write provided content into the given directory.

Parameters:

  • directory: (string) Directory where the content will be created.
  • filename: (string) File to write (possible nested path: /foo/bar/main.lua).
  • content: (string) The body to write.

Returns:

string

Found what you were looking for?
Feedback