diff options
| author | Peter Melnichenko <mpeterval@gmail.com> | 2016-07-08 15:49:59 +0300 |
|---|---|---|
| committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-07-08 15:49:59 +0300 |
| commit | c3975b3758e83486039c04cdd251445ed3e3b938 (patch) | |
| tree | 0fb4d9021f47b81d02dd4d77f662b2a5c87a9aa2 | |
| parent | d13af5115615a851125b4b20df370ec4d79ba939 (diff) | |
| download | luarocks-c3975b3758e83486039c04cdd251445ed3e3b938.tar.gz luarocks-c3975b3758e83486039c04cdd251445ed3e3b938.tar.bz2 luarocks-c3975b3758e83486039c04cdd251445ed3e3b938.zip | |
Tests: move config creation into its function
| -rw-r--r-- | test/test_environment.lua | 82 |
1 files changed, 44 insertions, 38 deletions
diff --git a/test/test_environment.lua b/test/test_environment.lua index a3802cc0..f5cc701e 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua | |||
| @@ -194,12 +194,12 @@ local function download_rocks(rocks, save_path) | |||
| 194 | return make_manifest | 194 | return make_manifest |
| 195 | end | 195 | end |
| 196 | 196 | ||
| 197 | --- Create config files for testing | 197 | --- Create a file containing a string. |
| 198 | -- @param config_path string: path where to save config file | 198 | -- @param path string: path to file. |
| 199 | -- @param config_content string: content of this config file | 199 | -- @param str string: content of the file. |
| 200 | local function create_config(config_path, config_content) | 200 | local function write_file(path, str) |
| 201 | local file = assert(io.open(config_path, "w")) | 201 | local file = assert(io.open(path, "w")) |
| 202 | file:write(config_content) | 202 | file:write(str) |
| 203 | file:close() | 203 | file:close() |
| 204 | end | 204 | end |
| 205 | 205 | ||
| @@ -443,27 +443,10 @@ local function substitute(str, replacements) | |||
| 443 | end)) | 443 | end)) |
| 444 | end | 444 | end |
| 445 | 445 | ||
| 446 | --- | ||
| 447 | -- Main function to create config files and testing environment | ||
| 448 | function test_env.main(luaversion_full, env_type, env_clean) | ||
| 449 | luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V | ||
| 450 | local testing_paths = create_paths(luaversion_full) | ||
| 451 | 446 | ||
| 452 | env_clean = env_clean or test_env.TEST_ENV_CLEAN | 447 | --- Create configs for luacov and several versions of Luarocks |
| 453 | if env_clean then | 448 | -- configs needed for some tests. |
| 454 | print("Cleaning testing directory...") | 449 | local function create_configs() |
| 455 | test_env.remove_dir(testing_paths.luarocks_tmp) | ||
| 456 | test_env.remove_dir_pattern(testing_paths.testing_dir, "testing_") | ||
| 457 | test_env.remove_dir_pattern(testing_paths.testing_dir, "testing-") | ||
| 458 | test_env.remove_files(testing_paths.testing_dir, "testing_") | ||
| 459 | test_env.remove_files(testing_paths.testing_dir, "luacov") | ||
| 460 | print("Cleaning done!") | ||
| 461 | end | ||
| 462 | |||
| 463 | lfs.mkdir(testing_paths.testing_cache) | ||
| 464 | lfs.mkdir(testing_paths.luarocks_tmp) | ||
| 465 | |||
| 466 | --- CONFIG FILES | ||
| 467 | -- testing_config.lua and testing_config_show_downloads.lua | 450 | -- testing_config.lua and testing_config_show_downloads.lua |
| 468 | local config_content = substitute([[ | 451 | local config_content = substitute([[ |
| 469 | rocks_trees = { | 452 | rocks_trees = { |
| @@ -495,14 +478,14 @@ function test_env.main(luaversion_full, env_type, env_clean) | |||
| 495 | } | 478 | } |
| 496 | ]], { | 479 | ]], { |
| 497 | user = os.getenv("USER"), | 480 | user = os.getenv("USER"), |
| 498 | testing_sys_tree = testing_paths.testing_sys_tree, | 481 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, |
| 499 | testing_tree = testing_paths.testing_tree, | 482 | testing_tree = test_env.testing_paths.testing_tree, |
| 500 | testing_server = testing_paths.testing_server, | 483 | testing_server = test_env.testing_paths.testing_server, |
| 501 | testing_cache = testing_paths.testing_cache | 484 | testing_cache = test_env.testing_paths.testing_cache |
| 502 | }) | 485 | }) |
| 503 | 486 | ||
| 504 | create_config(testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") | 487 | write_file(test_env.testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") |
| 505 | create_config(testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content | 488 | write_file(test_env.testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content |
| 506 | .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") | 489 | .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") |
| 507 | 490 | ||
| 508 | -- testing_config_sftp.lua | 491 | -- testing_config_sftp.lua |
| @@ -521,12 +504,12 @@ function test_env.main(luaversion_full, env_type, env_clean) | |||
| 521 | } | 504 | } |
| 522 | ]], { | 505 | ]], { |
| 523 | user = os.getenv("USER"), | 506 | user = os.getenv("USER"), |
| 524 | testing_sys_tree = testing_paths.testing_sys_tree, | 507 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, |
| 525 | testing_tree = testing_paths.testing_tree, | 508 | testing_tree = test_env.testing_paths.testing_tree, |
| 526 | testing_cache = testing_paths.testing_cache | 509 | testing_cache = test_env.testing_paths.testing_cache |
| 527 | }) | 510 | }) |
| 528 | 511 | ||
| 529 | create_config(testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) | 512 | write_file(test_env.testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) |
| 530 | 513 | ||
| 531 | -- luacov.config | 514 | -- luacov.config |
| 532 | config_content = substitute([[ | 515 | config_content = substitute([[ |
| @@ -542,10 +525,33 @@ function test_env.main(luaversion_full, env_type, env_clean) | |||
| 542 | } | 525 | } |
| 543 | } | 526 | } |
| 544 | ]], { | 527 | ]], { |
| 545 | testing_dir = testing_paths.testing_dir | 528 | testing_dir = test_env.testing_paths.testing_dir |
| 546 | }) | 529 | }) |
| 547 | 530 | ||
| 548 | create_config(testing_paths.testing_dir .. "/luacov.config", config_content) | 531 | write_file(test_env.testing_paths.testing_dir .. "/luacov.config", config_content) |
| 532 | end | ||
| 533 | |||
| 534 | --- | ||
| 535 | -- Main function to create config files and testing environment | ||
| 536 | function test_env.main(luaversion_full, env_type, env_clean) | ||
| 537 | luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V | ||
| 538 | local testing_paths = create_paths(luaversion_full) | ||
| 539 | |||
| 540 | env_clean = env_clean or test_env.TEST_ENV_CLEAN | ||
| 541 | if env_clean then | ||
| 542 | print("Cleaning testing directory...") | ||
| 543 | test_env.remove_dir(testing_paths.luarocks_tmp) | ||
| 544 | test_env.remove_dir_pattern(testing_paths.testing_dir, "testing_") | ||
| 545 | test_env.remove_dir_pattern(testing_paths.testing_dir, "testing-") | ||
| 546 | test_env.remove_files(testing_paths.testing_dir, "testing_") | ||
| 547 | test_env.remove_files(testing_paths.testing_dir, "luacov") | ||
| 548 | print("Cleaning done!") | ||
| 549 | end | ||
| 550 | |||
| 551 | lfs.mkdir(testing_paths.testing_cache) | ||
| 552 | lfs.mkdir(testing_paths.luarocks_tmp) | ||
| 553 | |||
| 554 | create_configs() | ||
| 549 | 555 | ||
| 550 | -- Create environment variables for configuration | 556 | -- Create environment variables for configuration |
| 551 | local temp_env_variables = {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config.lua",LUA_PATH="",LUA_CPATH=""} | 557 | local temp_env_variables = {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config.lua",LUA_PATH="",LUA_CPATH=""} |
