diff options
| author | Peter Melnichenko <mpeterval@gmail.com> | 2016-07-08 15:08:31 +0300 |
|---|---|---|
| committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-07-08 15:09:10 +0300 |
| commit | c4f2a8404130696c503414876cf335a82aab359f (patch) | |
| tree | 7c0e2fa56b113a0f81514f460ca4a5e5c43ecc24 /test/test_environment.lua | |
| parent | f5d35cf9cad5ad8cd9f6e201dda783657e4510a3 (diff) | |
| download | luarocks-c4f2a8404130696c503414876cf335a82aab359f.tar.gz luarocks-c4f2a8404130696c503414876cf335a82aab359f.tar.bz2 luarocks-c4f2a8404130696c503414876cf335a82aab359f.zip | |
Tests: refactor config creation
Diffstat (limited to 'test/test_environment.lua')
| -rw-r--r-- | test/test_environment.lua | 145 |
1 files changed, 81 insertions, 64 deletions
diff --git a/test/test_environment.lua b/test/test_environment.lua index d6561f68..4c1b13c8 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua | |||
| @@ -441,6 +441,14 @@ function test_env.need_luasocket(luarocks_nocov, testing_cache, platform) | |||
| 441 | return true | 441 | return true |
| 442 | end | 442 | end |
| 443 | 443 | ||
| 444 | --- For each key-value pair in replacements table | ||
| 445 | -- replace %{key} in given string with value. | ||
| 446 | local function substitute(str, replacements) | ||
| 447 | return (str:gsub("%%%b{}", function(marker) | ||
| 448 | return replacements[marker:sub(3, -2)] | ||
| 449 | end)) | ||
| 450 | end | ||
| 451 | |||
| 444 | --- | 452 | --- |
| 445 | -- Main function to create config files and testing environment | 453 | -- Main function to create config files and testing environment |
| 446 | function test_env.main(luaversion_full, env_type, env_clean) | 454 | function test_env.main(luaversion_full, env_type, env_clean) |
| @@ -461,78 +469,87 @@ function test_env.main(luaversion_full, env_type, env_clean) | |||
| 461 | lfs.mkdir(testing_paths.testing_cache) | 469 | lfs.mkdir(testing_paths.testing_cache) |
| 462 | lfs.mkdir(testing_paths.luarocks_tmp) | 470 | lfs.mkdir(testing_paths.luarocks_tmp) |
| 463 | 471 | ||
| 464 | --- CONFIG FILES | 472 | --- CONFIG FILES |
| 465 | -- testing_config.lua and testing_config_show_downloads.lua | 473 | -- testing_config.lua and testing_config_show_downloads.lua |
| 466 | local config_content = ([[rocks_trees = { | 474 | local config_content = substitute([[ |
| 467 | "%{testing_tree}", | 475 | rocks_trees = { |
| 468 | { name = "system", root = "%{testing_sys_tree}" }, | 476 | "%{testing_tree}", |
| 469 | } | 477 | { name = "system", root = "%{testing_sys_tree}" }, |
| 470 | rocks_servers = { | 478 | } |
| 471 | "%{testing_server}" | 479 | rocks_servers = { |
| 472 | } | 480 | "%{testing_server}" |
| 473 | local_cache = "%{testing_cache}" | 481 | } |
| 474 | upload_server = "testing" | 482 | local_cache = "%{testing_cache}" |
| 475 | upload_user = "%{user}" | 483 | upload_server = "testing" |
| 476 | upload_servers = { | 484 | upload_user = "%{user}" |
| 477 | testing = { | 485 | upload_servers = { |
| 478 | rsync = "localhost/tmp/luarocks_testing", | 486 | testing = { |
| 479 | }, | 487 | rsync = "localhost/tmp/luarocks_testing", |
| 480 | } | 488 | }, |
| 481 | external_deps_dirs = { | 489 | } |
| 482 | "/usr/local", | 490 | external_deps_dirs = { |
| 483 | "/usr", | 491 | "/usr/local", |
| 484 | -- These are used for a test that fails, so it | 492 | "/usr", |
| 485 | -- can point to invalid paths: | 493 | -- These are used for a test that fails, so it |
| 486 | { | 494 | -- can point to invalid paths: |
| 487 | prefix = "/opt", | 495 | { |
| 488 | bin = "bin", | 496 | prefix = "/opt", |
| 489 | include = "include", | 497 | bin = "bin", |
| 490 | lib = { "lib", "lib64" }, | 498 | include = "include", |
| 491 | } | 499 | lib = { "lib", "lib64" }, |
| 492 | }]]):gsub("%%%b{}", { | 500 | } |
| 493 | ["%{user}"] = os.getenv("USER"), | 501 | } |
| 494 | ["%{testing_sys_tree}"] = testing_paths.testing_sys_tree, | 502 | ]], { |
| 495 | ["%{testing_tree}"] = testing_paths.testing_tree, | 503 | user = os.getenv("USER"), |
| 496 | ["%{testing_server}"] = testing_paths.testing_server, | 504 | testing_sys_tree = testing_paths.testing_sys_tree, |
| 497 | ["%{testing_cache}"] = testing_paths.testing_cache}) | 505 | testing_tree = testing_paths.testing_tree, |
| 506 | testing_server = testing_paths.testing_server, | ||
| 507 | testing_cache = testing_paths.testing_cache | ||
| 508 | }) | ||
| 498 | 509 | ||
| 499 | create_config(testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") | 510 | create_config(testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") |
| 500 | create_config(testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content | 511 | create_config(testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content |
| 501 | .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") | 512 | .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") |
| 502 | 513 | ||
| 503 | -- testing_config_sftp.lua | 514 | -- testing_config_sftp.lua |
| 504 | config_content=([[rocks_trees = { | 515 | config_content = substitute([[ |
| 505 | "%{testing_tree}", | 516 | rocks_trees = { |
| 506 | "%{testing_sys_tree}", | 517 | "%{testing_tree}", |
| 507 | } | 518 | "%{testing_sys_tree}", |
| 508 | local_cache = "%{testing_cache}" | 519 | } |
| 509 | upload_server = "testing" | 520 | local_cache = "%{testing_cache}" |
| 510 | upload_user = "%{user}" | 521 | upload_server = "testing" |
| 511 | upload_servers = { | 522 | upload_user = "%{user}" |
| 512 | testing = { | 523 | upload_servers = { |
| 513 | sftp = "localhost/tmp/luarocks_testing", | 524 | testing = { |
| 514 | }, | 525 | sftp = "localhost/tmp/luarocks_testing", |
| 515 | }]]):gsub("%%%b{}", { | 526 | }, |
| 516 | ["%{user}"] = os.getenv("USER"), | 527 | } |
| 517 | ["%{testing_sys_tree}"] = testing_paths.testing_sys_tree, | 528 | ]], { |
| 518 | ["%{testing_tree}"] = testing_paths.testing_tree, | 529 | user = os.getenv("USER"), |
| 519 | ["%{testing_cache}"] = testing_paths.testing_cache}) | 530 | testing_sys_tree = testing_paths.testing_sys_tree, |
| 531 | testing_tree = testing_paths.testing_tree, | ||
| 532 | testing_cache = testing_paths.testing_cache | ||
| 533 | }) | ||
| 520 | 534 | ||
| 521 | create_config(testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) | 535 | create_config(testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) |
| 522 | 536 | ||
| 523 | -- luacov.config | 537 | -- luacov.config |
| 524 | config_content=([[return { | 538 | config_content = substitute([[ |
| 525 | statsfile = "%{testing_dir}/luacov.stats.out", | 539 | return { |
| 526 | reportfile = "%{testing_dir}/luacov.report.out", | 540 | statsfile = "%{testing_dir}/luacov.stats.out", |
| 527 | modules = { | 541 | reportfile = "%{testing_dir}/luacov.report.out", |
| 528 | ["luarocks"] = "src/bin/luarocks", | 542 | modules = { |
| 529 | ["luarocks-admin"] = "src/bin/luarocks-admin", | 543 | ["luarocks"] = "src/bin/luarocks", |
| 530 | ["luarocks.*"] = "src", | 544 | ["luarocks-admin"] = "src/bin/luarocks-admin", |
| 531 | ["luarocks.*.*"] = "src", | 545 | ["luarocks.*"] = "src", |
| 532 | ["luarocks.*.*.*"] = "src" | 546 | ["luarocks.*.*"] = "src", |
| 533 | } | 547 | ["luarocks.*.*.*"] = "src" |
| 534 | }]]):gsub("%%%b{}", { | 548 | } |
| 535 | ["%{testing_dir}"] = testing_paths.testing_dir}) | 549 | } |
| 550 | ]], { | ||
| 551 | testing_dir = testing_paths.testing_dir | ||
| 552 | }) | ||
| 536 | 553 | ||
| 537 | create_config(testing_paths.testing_dir .. "/luacov.config", config_content) | 554 | create_config(testing_paths.testing_dir .. "/luacov.config", config_content) |
| 538 | 555 | ||
