diff options
Diffstat (limited to 'spec/util/test_env.lua')
-rw-r--r-- | spec/util/test_env.lua | 87 |
1 files changed, 25 insertions, 62 deletions
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index 8ccb494b..be75b4ec 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua | |||
@@ -527,21 +527,6 @@ function test_env.write_file(pathname, str, finally) | |||
527 | end | 527 | end |
528 | end | 528 | end |
529 | 529 | ||
530 | --- Create md5sum of directory structure recursively, based on filename and size | ||
531 | -- @param path string: path to directory for generate md5sum | ||
532 | -- @return md5sum string: md5sum of directory | ||
533 | local function hash_environment(path) | ||
534 | if test_env.TEST_TARGET_OS == "linux" then | ||
535 | return execute_output(C("cd", path, "&& find . -printf \"%s %p\n\" | md5sum")) | ||
536 | elseif test_env.TEST_TARGET_OS == "osx" then | ||
537 | return execute_output(C("find", path, "-type f -exec stat -f \"%z %N\" {} \\; | md5")) | ||
538 | elseif test_env.TEST_TARGET_OS == "windows" then | ||
539 | return execute_output( | ||
540 | "\"" .. C(tool("find"), Q(path), "-printf", "\"%s %p\"") .. "\"" .. | ||
541 | " > temp_sum.txt && certUtil -hashfile temp_sum.txt && del temp_sum.txt") | ||
542 | end | ||
543 | end | ||
544 | |||
545 | --- Create environment variables needed for tests | 530 | --- Create environment variables needed for tests |
546 | -- @param testing_paths table: table with paths to testing directory | 531 | -- @param testing_paths table: table with paths to testing directory |
547 | -- @return env_variables table: table with created environment variables | 532 | -- @return env_variables table: table with created environment variables |
@@ -551,6 +536,7 @@ local function create_env(testing_paths) | |||
551 | local lrprefix = testing_paths.testing_lrprefix | 536 | local lrprefix = testing_paths.testing_lrprefix |
552 | local tree = testing_paths.testing_tree | 537 | local tree = testing_paths.testing_tree |
553 | local sys_tree = testing_paths.testing_sys_tree | 538 | local sys_tree = testing_paths.testing_sys_tree |
539 | local deps_tree = testing_paths.testing_deps_tree | ||
554 | 540 | ||
555 | if test_env.LUAJIT_V then | 541 | if test_env.LUAJIT_V then |
556 | lua_v="5.1" | 542 | lua_v="5.1" |
@@ -567,38 +553,31 @@ local function create_env(testing_paths) | |||
567 | else | 553 | else |
568 | table.insert(lua_path, dir_path(lrprefix, "share", "lua", lua_v, "?.lua")) | 554 | table.insert(lua_path, dir_path(lrprefix, "share", "lua", lua_v, "?.lua")) |
569 | end | 555 | end |
570 | table.insert(lua_path, dir_path(tree, "share", "lua", lua_v, "?.lua")) | 556 | table.insert(lua_path, dir_path(tree, "share", "lua", lua_v, "?.lua")) |
571 | table.insert(lua_path, dir_path(tree, "share", "lua", lua_v, "?", "init.lua")) | 557 | table.insert(lua_path, dir_path(tree, "share", "lua", lua_v, "?", "init.lua")) |
572 | table.insert(lua_path, dir_path(sys_tree, "share", "lua", lua_v, "?.lua")) | 558 | table.insert(lua_path, dir_path(sys_tree, "share", "lua", lua_v, "?.lua")) |
573 | table.insert(lua_path, dir_path(sys_tree, "share", "lua", lua_v, "?", "init.lua")) | 559 | table.insert(lua_path, dir_path(sys_tree, "share", "lua", lua_v, "?", "init.lua")) |
560 | table.insert(lua_path, dir_path(deps_tree, "share", "lua", lua_v, "?.lua")) | ||
561 | table.insert(lua_path, dir_path(deps_tree, "share", "lua", lua_v, "?", "init.lua")) | ||
574 | table.insert(lua_path, dir_path(testing_paths.src_dir, "?.lua")) | 562 | table.insert(lua_path, dir_path(testing_paths.src_dir, "?.lua")) |
575 | env_variables.LUA_PATH = table.concat(lua_path, ";") .. ";" | 563 | env_variables.LUA_PATH = table.concat(lua_path, ";") .. ";" |
576 | 564 | ||
577 | local lua_cpath = {} | 565 | local lua_cpath = {} |
578 | local lib_pattern = "?." .. test_env.lib_extension | 566 | local lib_pattern = "?." .. test_env.lib_extension |
579 | table.insert(lua_cpath, dir_path(tree, "lib", "lua", lua_v, lib_pattern)) | 567 | table.insert(lua_cpath, dir_path(tree, "lib", "lua", lua_v, lib_pattern)) |
580 | table.insert(lua_cpath, dir_path(sys_tree, "lib", "lua", lua_v, lib_pattern)) | 568 | table.insert(lua_cpath, dir_path(sys_tree, "lib", "lua", lua_v, lib_pattern)) |
569 | table.insert(lua_cpath, dir_path(deps_tree, "lib", "lua", lua_v, lib_pattern)) | ||
581 | env_variables.LUA_CPATH = table.concat(lua_cpath, ";") .. ";" | 570 | env_variables.LUA_CPATH = table.concat(lua_cpath, ";") .. ";" |
582 | 571 | ||
583 | local path = { os.getenv("PATH") } | 572 | local path = { os.getenv("PATH") } |
584 | table.insert(path, dir_path(tree, "bin")) | 573 | table.insert(path, dir_path(tree, "bin")) |
585 | table.insert(path, dir_path(sys_tree, "bin")) | 574 | table.insert(path, dir_path(sys_tree, "bin")) |
575 | table.insert(path, dir_path(deps_tree, "bin")) | ||
586 | env_variables.PATH = table.concat(path, test_env.TARGET_OS == "windows" and ";" or ":") | 576 | env_variables.PATH = table.concat(path, test_env.TARGET_OS == "windows" and ";" or ":") |
587 | 577 | ||
588 | return env_variables | 578 | return env_variables |
589 | end | 579 | end |
590 | 580 | ||
591 | --- Create md5sums of origin system and system-copy testing directory | ||
592 | -- @param testing_paths table: table with paths to testing directory | ||
593 | -- @return md5sums table: table of md5sums of system and system-copy testing directory | ||
594 | local function create_md5sums(testing_paths) | ||
595 | local md5sums = {} | ||
596 | md5sums.testing_tree_copy_md5 = hash_environment(testing_paths.testing_tree_copy) | ||
597 | md5sums.testing_sys_tree_copy_md5 = hash_environment(testing_paths.testing_sys_tree_copy) | ||
598 | |||
599 | return md5sums | ||
600 | end | ||
601 | |||
602 | local function make_run_function(cmd_name, exec_function, with_coverage, do_print) | 581 | local function make_run_function(cmd_name, exec_function, with_coverage, do_print) |
603 | local cmd_prefix = Q(test_env.testing_paths.lua) | 582 | local cmd_prefix = Q(test_env.testing_paths.lua) |
604 | local testrun_dir = test_env.testing_paths.testrun_dir | 583 | local testrun_dir = test_env.testing_paths.testrun_dir |
@@ -663,43 +642,23 @@ local function build_environment(rocks, env_variables) | |||
663 | local testing_paths = test_env.testing_paths | 642 | local testing_paths = test_env.testing_paths |
664 | test_env.remove_dir(testing_paths.testing_tree) | 643 | test_env.remove_dir(testing_paths.testing_tree) |
665 | test_env.remove_dir(testing_paths.testing_sys_tree) | 644 | test_env.remove_dir(testing_paths.testing_sys_tree) |
666 | test_env.remove_dir(testing_paths.testing_tree_copy) | ||
667 | test_env.remove_dir(testing_paths.testing_sys_tree_copy) | ||
668 | 645 | ||
669 | lfs.mkdir(testing_paths.testing_tree) | 646 | lfs.mkdir(testing_paths.testing_tree) |
670 | lfs.mkdir(testing_paths.testing_sys_tree) | 647 | lfs.mkdir(testing_paths.testing_sys_tree) |
648 | lfs.mkdir(testing_paths.testing_deps_tree) | ||
671 | 649 | ||
672 | test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_server))) | 650 | test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_server))) |
673 | test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_cache))) | 651 | test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_cache))) |
674 | 652 | ||
675 | for _, rock in ipairs(rocks) do | 653 | for _, rock in ipairs(rocks) do |
676 | local only_server = "--only-server=" .. testing_paths.testing_cache | 654 | local only_server = "--only-server=" .. testing_paths.testing_cache |
677 | local tree = "--tree=" .. testing_paths.testing_sys_tree | 655 | local tree = "--tree=" .. testing_paths.testing_deps_tree |
678 | if not test_env.run.luarocks_nocov(test_env.quiet(C("install", only_server, tree, Q(rock)), env_variables)) then | 656 | if not test_env.run.luarocks_nocov(test_env.quiet(C("install", only_server, tree, Q(rock)), env_variables)) then |
679 | assert(test_env.run.luarocks_nocov(C("build", tree, Q(rock)), env_variables)) | 657 | assert(test_env.run.luarocks_nocov(C("build", tree, Q(rock)), env_variables)) |
680 | assert(test_env.run.luarocks_nocov(C("pack", tree, Q(rock)), env_variables)) | 658 | assert(test_env.run.luarocks_nocov(C("pack", tree, Q(rock)), env_variables)) |
681 | move_file(rock .. "-*.rock", testing_paths.testing_cache) | 659 | move_file(rock .. "-*.rock", testing_paths.testing_cache) |
682 | end | 660 | end |
683 | end | 661 | end |
684 | |||
685 | test_env.copy_dir(testing_paths.testing_tree, testing_paths.testing_tree_copy) | ||
686 | test_env.copy_dir(testing_paths.testing_sys_tree, testing_paths.testing_sys_tree_copy) | ||
687 | end | ||
688 | |||
689 | --- Reset testing environment | ||
690 | local function reset_environment(testing_paths, md5sums) | ||
691 | local testing_tree_md5 = hash_environment(testing_paths.testing_tree) | ||
692 | local testing_sys_tree_md5 = hash_environment(testing_paths.testing_sys_tree) | ||
693 | |||
694 | if testing_tree_md5 ~= md5sums.testing_tree_copy_md5 then | ||
695 | test_env.remove_dir(testing_paths.testing_tree) | ||
696 | test_env.copy_dir(testing_paths.testing_tree_copy, testing_paths.testing_tree) | ||
697 | end | ||
698 | |||
699 | if testing_sys_tree_md5 ~= md5sums.testing_sys_tree_copy_md5 then | ||
700 | test_env.remove_dir(testing_paths.testing_sys_tree) | ||
701 | test_env.copy_dir(testing_paths.testing_sys_tree_copy, testing_paths.testing_sys_tree) | ||
702 | end | ||
703 | end | 662 | end |
704 | 663 | ||
705 | local function find_lua() | 664 | local function find_lua() |
@@ -765,15 +724,15 @@ local function create_testing_paths(suffix) | |||
765 | paths.testrun_dir = testrun_dir | 724 | paths.testrun_dir = testrun_dir |
766 | paths.testing_lrprefix = dir_path(testrun_dir, "testing_lrprefix-" .. suffix) | 725 | paths.testing_lrprefix = dir_path(testrun_dir, "testing_lrprefix-" .. suffix) |
767 | paths.testing_tree = dir_path(testrun_dir, "testing-" .. suffix) | 726 | paths.testing_tree = dir_path(testrun_dir, "testing-" .. suffix) |
768 | paths.testing_tree_copy = dir_path(testrun_dir, "testing_copy-" .. suffix) | ||
769 | paths.testing_sys_tree = dir_path(testrun_dir, "testing_sys-" .. suffix) | 727 | paths.testing_sys_tree = dir_path(testrun_dir, "testing_sys-" .. suffix) |
770 | paths.testing_sys_tree_copy = dir_path(testrun_dir, "testing_sys_copy-" .. suffix) | 728 | paths.testing_deps_tree = dir_path(testrun_dir, "testing_deps-" .. suffix) |
771 | paths.testing_cache = dir_path(testrun_dir, "testing_cache-" .. suffix) | 729 | paths.testing_cache = dir_path(testrun_dir, "testing_cache-" .. suffix) |
772 | paths.testing_server = dir_path(testrun_dir, "testing_server-" .. suffix) | 730 | paths.testing_server = dir_path(testrun_dir, "testing_server-" .. suffix) |
773 | 731 | ||
774 | local rocks_v = "rocks-" .. test_env.lua_version | 732 | local rocks_v = "rocks-" .. test_env.lua_version |
775 | paths.testing_rocks = dir_path(paths.testing_tree, "lib", "luarocks", rocks_v) | 733 | paths.testing_rocks = dir_path(paths.testing_tree, "lib", "luarocks", rocks_v) |
776 | paths.testing_sys_rocks = dir_path(paths.testing_sys_tree, "lib", "luarocks", rocks_v) | 734 | paths.testing_sys_rocks = dir_path(paths.testing_sys_tree, "lib", "luarocks", rocks_v) |
735 | paths.testing_deps_rocks = dir_path(paths.testing_deps_tree, "lib", "luarocks", rocks_v) | ||
777 | 736 | ||
778 | if test_env.TEST_TARGET_OS == "windows" then | 737 | if test_env.TEST_TARGET_OS == "windows" then |
779 | paths.luarocks_tmp = os.getenv("TEMP") | 738 | paths.luarocks_tmp = os.getenv("TEMP") |
@@ -853,7 +812,8 @@ local function create_configs() | |||
853 | -- testing_config_no_downloader.lua | 812 | -- testing_config_no_downloader.lua |
854 | local config_content = substitute([[ | 813 | local config_content = substitute([[ |
855 | rocks_trees = { | 814 | rocks_trees = { |
856 | "%{testing_tree}", | 815 | { name = "user", root = "%{testing_tree}" }, |
816 | { name = "deps", root = "%{testing_deps_tree}" }, | ||
857 | { name = "system", root = "%{testing_sys_tree}" }, | 817 | { name = "system", root = "%{testing_sys_tree}" }, |
858 | } | 818 | } |
859 | rocks_servers = { | 819 | rocks_servers = { |
@@ -870,6 +830,7 @@ local function create_configs() | |||
870 | ]], { | 830 | ]], { |
871 | user = "testuser", | 831 | user = "testuser", |
872 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, | 832 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, |
833 | testing_deps_tree = test_env.testing_paths.testing_deps_tree, | ||
873 | testing_tree = test_env.testing_paths.testing_tree, | 834 | testing_tree = test_env.testing_paths.testing_tree, |
874 | testing_server = test_env.testing_paths.testing_server, | 835 | testing_server = test_env.testing_paths.testing_server, |
875 | testing_cache = test_env.testing_paths.testing_cache | 836 | testing_cache = test_env.testing_paths.testing_cache |
@@ -885,6 +846,7 @@ local function create_configs() | |||
885 | config_content = substitute([[ | 846 | config_content = substitute([[ |
886 | rocks_trees = { | 847 | rocks_trees = { |
887 | "%{testing_tree}", | 848 | "%{testing_tree}", |
849 | "%{testing_deps_tree}", | ||
888 | "%{testing_sys_tree}", | 850 | "%{testing_sys_tree}", |
889 | } | 851 | } |
890 | local_cache = "%{testing_cache}" | 852 | local_cache = "%{testing_cache}" |
@@ -898,6 +860,7 @@ local function create_configs() | |||
898 | ]], { | 860 | ]], { |
899 | user = "testuser", | 861 | user = "testuser", |
900 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, | 862 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, |
863 | testing_deps_tree = test_env.testing_paths.testing_deps_tree, | ||
901 | testing_tree = test_env.testing_paths.testing_tree, | 864 | testing_tree = test_env.testing_paths.testing_tree, |
902 | testing_cache = test_env.testing_paths.testing_cache | 865 | testing_cache = test_env.testing_paths.testing_cache |
903 | }) | 866 | }) |
@@ -1140,7 +1103,7 @@ function test_env.main() | |||
1140 | build_environment(rocks, env_vars) | 1103 | build_environment(rocks, env_vars) |
1141 | end | 1104 | end |
1142 | 1105 | ||
1143 | --- Function for initial setup of environment, variables, md5sums for spec files | 1106 | --- Function for initial setup of environment and variables |
1144 | function test_env.setup_specs(extra_rocks, use_mock) | 1107 | function test_env.setup_specs(extra_rocks, use_mock) |
1145 | test_env.unload_luarocks() | 1108 | test_env.unload_luarocks() |
1146 | 1109 | ||
@@ -1169,7 +1132,6 @@ function test_env.setup_specs(extra_rocks, use_mock) | |||
1169 | 1132 | ||
1170 | test_env.platform = get_luarocks_platform(test_env.env_variables) | 1133 | test_env.platform = get_luarocks_platform(test_env.env_variables) |
1171 | test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or "" | 1134 | test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or "" |
1172 | test_env.md5sums = create_md5sums(test_env.testing_paths) | ||
1173 | test_env.setup_done = true | 1135 | test_env.setup_done = true |
1174 | title("RUNNING TESTS") | 1136 | title("RUNNING TESTS") |
1175 | end | 1137 | end |
@@ -1186,7 +1148,8 @@ function test_env.setup_specs(extra_rocks, use_mock) | |||
1186 | end | 1148 | end |
1187 | 1149 | ||
1188 | if test_env.RESET_ENV then | 1150 | if test_env.RESET_ENV then |
1189 | reset_environment(test_env.testing_paths, test_env.md5sums, variables) | 1151 | test_env.remove_dir(test_env.testing_paths.testing_tree) |
1152 | test_env.remove_dir(test_env.testing_paths.testing_sys_tree) | ||
1190 | end | 1153 | end |
1191 | 1154 | ||
1192 | lfs.chdir(testrun_dir) | 1155 | lfs.chdir(testrun_dir) |