diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-26 14:49:59 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-27 13:28:33 -0300 |
| commit | e0aa47df12c9b9beb05d380aac7d90a28a081a7b (patch) | |
| tree | 12278f86fbd8b8b8440f622893c31eb441132cdb | |
| parent | 58bc0833b0198306f62078a5d9e67c9f1e11d476 (diff) | |
| download | luarocks-e0aa47df12c9b9beb05d380aac7d90a28a081a7b.tar.gz luarocks-e0aa47df12c9b9beb05d380aac7d90a28a081a7b.tar.bz2 luarocks-e0aa47df12c9b9beb05d380aac7d90a28a081a7b.zip | |
tests(build): split unit and integration files
use restserver only in integration part
| -rw-r--r-- | spec/build_spec.lua | 352 | ||||
| -rw-r--r-- | spec/unit_build_spec.lua | 369 |
2 files changed, 369 insertions, 352 deletions
diff --git a/spec/build_spec.lua b/spec/build_spec.lua index 0a270ec4..9b34ec54 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua | |||
| @@ -5,7 +5,6 @@ local run = test_env.run | |||
| 5 | local testing_paths = test_env.testing_paths | 5 | local testing_paths = test_env.testing_paths |
| 6 | local write_file = test_env.write_file | 6 | local write_file = test_env.write_file |
| 7 | local git_repo = require("spec.util.git_repo") | 7 | local git_repo = require("spec.util.git_repo") |
| 8 | local P = test_env.P | ||
| 9 | 8 | ||
| 10 | test_env.unload_luarocks() | 9 | test_env.unload_luarocks() |
| 11 | local cfg = require("luarocks.core.cfg") | 10 | local cfg = require("luarocks.core.cfg") |
| @@ -511,355 +510,6 @@ describe("LuaRocks build #integration", function() | |||
| 511 | end) | 510 | end) |
| 512 | end) | 511 | end) |
| 513 | 512 | ||
| 514 | end) | ||
| 515 | |||
| 516 | test_env.unload_luarocks() | ||
| 517 | test_env.setup_specs() | ||
| 518 | local cfg = require("luarocks.core.cfg") | ||
| 519 | local deps = require("luarocks.deps") | ||
| 520 | local fs = require("luarocks.fs") | ||
| 521 | local path = require("luarocks.path") | ||
| 522 | local rockspecs = require("luarocks.rockspecs") | ||
| 523 | local build_builtin = require("luarocks.build.builtin") | ||
| 524 | |||
| 525 | describe("LuaRocks build #unit", function() | ||
| 526 | local runner | ||
| 527 | |||
| 528 | lazy_setup(function() | ||
| 529 | runner = require("luacov.runner") | ||
| 530 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | ||
| 531 | runner.tick = true | ||
| 532 | cfg.init() | ||
| 533 | fs.init() | ||
| 534 | deps.check_lua_incdir(cfg.variables) | ||
| 535 | deps.check_lua_libdir(cfg.variables) | ||
| 536 | end) | ||
| 537 | |||
| 538 | lazy_teardown(function() | ||
| 539 | runner.shutdown() | ||
| 540 | end) | ||
| 541 | |||
| 542 | describe("build.builtin", function() | ||
| 543 | it("builtin auto installs files in lua subdir", function() | ||
| 544 | test_env.run_in_tmp(function(tmpdir) | ||
| 545 | lfs.mkdir("lua") | ||
| 546 | write_file("lua_module-1.0-1.rockspec", [[ | ||
| 547 | package = "lua_module" | ||
| 548 | version = "1.0-1" | ||
| 549 | source = { | ||
| 550 | url = "http://example.com/lua_module" | ||
| 551 | } | ||
| 552 | build = { | ||
| 553 | type = "builtin", | ||
| 554 | modules = {} | ||
| 555 | } | ||
| 556 | ]], finally) | ||
| 557 | write_file("lua/lua_module.lua", "return 123", finally) | ||
| 558 | |||
| 559 | assert.is_true(run.luarocks_bool("build")) | ||
| 560 | assert.match("[\\/]lua_module%.lua", run.luarocks("show lua_module")) | ||
| 561 | end, finally) | ||
| 562 | end) | ||
| 563 | |||
| 564 | describe("builtin.autodetect_modules", function() | ||
| 565 | local tmpdir | ||
| 566 | local olddir | ||
| 567 | |||
| 568 | before_each(function() | ||
| 569 | tmpdir = get_tmp_path() | ||
| 570 | olddir = lfs.currentdir() | ||
| 571 | lfs.mkdir(tmpdir) | ||
| 572 | lfs.chdir(tmpdir) | ||
| 573 | fs.change_dir(tmpdir) | ||
| 574 | end) | ||
| 575 | |||
| 576 | after_each(function() | ||
| 577 | if olddir then | ||
| 578 | lfs.chdir(olddir) | ||
| 579 | fs.change_dir(olddir) | ||
| 580 | if tmpdir then | ||
| 581 | lfs.rmdir(tmpdir) | ||
| 582 | end | ||
| 583 | end | ||
| 584 | end) | ||
| 585 | |||
| 586 | local libs = { "foo1", "foo2" } | ||
| 587 | local incdirs = { "$(FOO1_INCDIR)", "$(FOO2_INCDIR)" } | ||
| 588 | local libdirs = { "$(FOO1_LIBDIR)", "$(FOO2_LIBDIR)" } | ||
| 589 | |||
| 590 | it("returns a table of the modules having as location the current directory", function() | ||
| 591 | write_file("module1.lua", "", finally) | ||
| 592 | write_file("module2.c", "", finally) | ||
| 593 | write_file("module3.c", "int luaopen_my_module()", finally) | ||
| 594 | write_file("test.lua", "", finally) | ||
| 595 | write_file("tests.lua", "", finally) | ||
| 596 | |||
| 597 | local modules = build_builtin.autodetect_modules(libs, incdirs, libdirs) | ||
| 598 | assert.same(modules, { | ||
| 599 | module1 = "module1.lua", | ||
| 600 | module2 = { | ||
| 601 | sources = "module2.c", | ||
| 602 | libraries = libs, | ||
| 603 | incdirs = incdirs, | ||
| 604 | libdirs = libdirs | ||
| 605 | }, | ||
| 606 | my_module = { | ||
| 607 | sources = "module3.c", | ||
| 608 | libraries = libs, | ||
| 609 | incdirs = incdirs, | ||
| 610 | libdirs = libdirs | ||
| 611 | } | ||
| 612 | }) | ||
| 613 | end) | ||
| 614 | |||
| 615 | local test_with_location = function(location) | ||
| 616 | lfs.mkdir(location) | ||
| 617 | lfs.mkdir(location .. "/dir1") | ||
| 618 | lfs.mkdir(location .. "/dir1/dir2") | ||
| 619 | |||
| 620 | write_file(location .. "/module1.lua", "", finally) | ||
| 621 | write_file(location .. "/dir1/module2.c", "", finally) | ||
| 622 | write_file(location .. "/dir1/dir2/module3.c", "int luaopen_my_module()", finally) | ||
| 623 | write_file(location .. "/test.lua", "", finally) | ||
| 624 | write_file(location .. "/tests.lua", "", finally) | ||
| 625 | |||
| 626 | local modules = build_builtin.autodetect_modules(libs, incdirs, libdirs) | ||
| 627 | assert.same(modules, { | ||
| 628 | module1 = location .. "/module1.lua", | ||
| 629 | ["dir1.module2"] = { | ||
| 630 | sources = location .. "/dir1/module2.c", | ||
| 631 | libraries = libs, | ||
| 632 | incdirs = incdirs, | ||
| 633 | libdirs = libdirs | ||
| 634 | }, | ||
| 635 | my_module = { | ||
| 636 | sources = location .. "/dir1/dir2/module3.c", | ||
| 637 | libraries = libs, | ||
| 638 | incdirs = incdirs, | ||
| 639 | libdirs = libdirs | ||
| 640 | } | ||
| 641 | }) | ||
| 642 | |||
| 643 | lfs.rmdir(location .. "/dir1/dir2") | ||
| 644 | lfs.rmdir(location .. "/dir1") | ||
| 645 | lfs.rmdir(location) | ||
| 646 | end | ||
| 647 | |||
| 648 | it("returns a table of the modules having as location the src directory", function() | ||
| 649 | test_with_location("src") | ||
| 650 | end) | ||
| 651 | |||
| 652 | it("returns a table of the modules having as location the lua directory", function() | ||
| 653 | test_with_location("lua") | ||
| 654 | end) | ||
| 655 | |||
| 656 | it("returns as second and third argument tables of the bin files and copy directories", function() | ||
| 657 | lfs.mkdir("doc") | ||
| 658 | lfs.mkdir("docs") | ||
| 659 | lfs.mkdir("samples") | ||
| 660 | lfs.mkdir("tests") | ||
| 661 | lfs.mkdir("bin") | ||
| 662 | write_file("bin/binfile", "", finally) | ||
| 663 | |||
| 664 | local _, install, copy_directories = build_builtin.autodetect_modules({}, {}, {}) | ||
| 665 | assert.same(install, { bin = { P"bin/binfile" } }) | ||
| 666 | assert.same(copy_directories, { "doc", "docs", "samples", "tests" }) | ||
| 667 | |||
| 668 | lfs.rmdir("doc") | ||
| 669 | lfs.rmdir("docs") | ||
| 670 | lfs.rmdir("samples") | ||
| 671 | lfs.rmdir("tests") | ||
| 672 | lfs.rmdir("bin") | ||
| 673 | end) | ||
| 674 | end) | ||
| 675 | |||
| 676 | describe("builtin.run", function() | ||
| 677 | local tmpdir | ||
| 678 | local olddir | ||
| 679 | |||
| 680 | before_each(function() | ||
| 681 | tmpdir = get_tmp_path() | ||
| 682 | olddir = lfs.currentdir() | ||
| 683 | lfs.mkdir(tmpdir) | ||
| 684 | lfs.chdir(tmpdir) | ||
| 685 | fs.change_dir(tmpdir) | ||
| 686 | path.use_tree(lfs.currentdir()) | ||
| 687 | end) | ||
| 688 | |||
| 689 | after_each(function() | ||
| 690 | if olddir then | ||
| 691 | lfs.chdir(olddir) | ||
| 692 | fs.change_dir(olddir) | ||
| 693 | if tmpdir then | ||
| 694 | lfs.rmdir(tmpdir) | ||
| 695 | end | ||
| 696 | end | ||
| 697 | end) | ||
| 698 | |||
| 699 | it("returns false if the rockspec has no build modules and its format does not support autoextraction", function() | ||
| 700 | local rockspec = { | ||
| 701 | package = "test", | ||
| 702 | version = "1.0-1", | ||
| 703 | source = { | ||
| 704 | url = "http://example.com/test" | ||
| 705 | }, | ||
| 706 | build = {} | ||
| 707 | } | ||
| 708 | |||
| 709 | rockspecs.from_persisted_table("test-1.0-1.rockspec", rockspec) | ||
| 710 | assert.falsy(build_builtin.run(rockspec)) | ||
| 711 | rockspec.rockspec_format = "1.0" | ||
| 712 | assert.falsy(build_builtin.run(rockspec)) | ||
| 713 | end) | ||
| 714 | |||
| 715 | it("returns false if lua.h could not be found", function() | ||
| 716 | local rockspec = { | ||
| 717 | package = "c_module", | ||
| 718 | version = "1.0-1", | ||
| 719 | source = { | ||
| 720 | url = "http://example.com/c_module" | ||
| 721 | }, | ||
| 722 | build = { | ||
| 723 | type = "builtin", | ||
| 724 | modules = { | ||
| 725 | c_module = "c_module.c" | ||
| 726 | } | ||
| 727 | } | ||
| 728 | } | ||
| 729 | write_file("c_module.c", c_module_source, finally) | ||
| 730 | |||
| 731 | rockspecs.from_persisted_table("c_module-1.0-1.rockspec", rockspec) | ||
| 732 | rockspec.variables = { LUA_INCDIR = "invalid" } | ||
| 733 | assert.falsy(build_builtin.run(rockspec)) | ||
| 734 | end) | ||
| 735 | |||
| 736 | it("returns false if the build fails", function() | ||
| 737 | local rockspec = { | ||
| 738 | package = "c_module", | ||
| 739 | version = "1.0-1", | ||
| 740 | source = { | ||
| 741 | url = "http://example.com/c_module" | ||
| 742 | }, | ||
| 743 | build = { | ||
| 744 | type = "builtin", | ||
| 745 | modules = { | ||
| 746 | c_module = "c_module.c" | ||
| 747 | } | ||
| 748 | } | ||
| 749 | } | ||
| 750 | write_file("c_module.c", c_module_source .. "invalid", finally) | ||
| 751 | |||
| 752 | rockspecs.from_persisted_table("c_module-1.0-1.rockspec", rockspec) | ||
| 753 | assert.falsy(build_builtin.run(rockspec)) | ||
| 754 | end) | ||
| 755 | |||
| 756 | it("returns true if the build succeeds with C module", function() | ||
| 757 | local rockspec = { | ||
| 758 | package = "c_module", | ||
| 759 | version = "1.0-1", | ||
| 760 | source = { | ||
| 761 | url = "http://example.com/c_module" | ||
| 762 | }, | ||
| 763 | build = { | ||
| 764 | type = "builtin", | ||
| 765 | modules = { | ||
| 766 | c_module = "c_module.c" | ||
| 767 | } | ||
| 768 | } | ||
| 769 | } | ||
| 770 | write_file("c_module.c", c_module_source, finally) | ||
| 771 | |||
| 772 | rockspecs.from_persisted_table("c_module-1.0-1.rockspec", rockspec) | ||
| 773 | assert.truthy(build_builtin.run(rockspec)) | ||
| 774 | assert.truthy(lfs.attributes("lib/luarocks/rocks-" .. test_env.lua_version .. "/c_module/1.0-1/lib/c_module." .. test_env.lib_extension)) | ||
| 775 | end) | ||
| 776 | |||
| 777 | it("returns true if the build succeeds with Lua module", function() | ||
| 778 | local rockspec = { | ||
| 779 | rockspec_format = "1.0", | ||
| 780 | package = "test", | ||
| 781 | version = "1.0-1", | ||
| 782 | source = { | ||
| 783 | url = "http://example.com/test" | ||
| 784 | }, | ||
| 785 | build = { | ||
| 786 | type = "builtin", | ||
| 787 | modules = { | ||
| 788 | test = "test.lua" | ||
| 789 | } | ||
| 790 | } | ||
| 791 | } | ||
| 792 | write_file("test.lua", "return {}", finally) | ||
| 793 | |||
| 794 | rockspecs.from_persisted_table("test-1.0-1.rockspec", rockspec) | ||
| 795 | assert.truthy(build_builtin.run(rockspec)) | ||
| 796 | assert.truthy(lfs.attributes("lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/lua/test.lua")) | ||
| 797 | end) | ||
| 798 | |||
| 799 | it("automatically extracts the modules and libraries if they are not given and builds against any external dependencies", function() | ||
| 800 | local fdir = testing_paths.fixtures_dir | ||
| 801 | if test_env.TEST_TARGET_OS == "windows" then | ||
| 802 | if test_env.MINGW then | ||
| 803 | os.execute("gcc -shared -o " .. fdir .. "/libfixturedep.dll -Wl,--out-implib," .. fdir .."/libfixturedep.a " .. fdir .. "/fixturedep.c") | ||
| 804 | else | ||
| 805 | os.execute("cl " .. fdir .. "\\fixturedep.c /link /export:fixturedep_fn /out:" .. fdir .. "\\fixturedep.dll /implib:" .. fdir .. "\\fixturedep.lib") | ||
| 806 | end | ||
| 807 | elseif test_env.TEST_TARGET_OS == "linux" then | ||
| 808 | os.execute("gcc -shared -o " .. fdir .. "/libfixturedep.so " .. fdir .. "/fixturedep.c") | ||
| 809 | elseif test_env.TEST_TARGET_OS == "osx" then | ||
| 810 | os.execute("cc -dynamiclib -o " .. fdir .. "/libfixturedep.dylib " .. fdir .. "/fixturedep.c") | ||
| 811 | end | ||
| 812 | |||
| 813 | local rockspec = { | ||
| 814 | rockspec_format = "3.0", | ||
| 815 | package = "c_module", | ||
| 816 | version = "1.0-1", | ||
| 817 | source = { | ||
| 818 | url = "http://example.com/c_module" | ||
| 819 | }, | ||
| 820 | external_dependencies = { | ||
| 821 | FIXTUREDEP = { | ||
| 822 | library = "fixturedep" | ||
| 823 | } | ||
| 824 | }, | ||
| 825 | build = { | ||
| 826 | type = "builtin" | ||
| 827 | } | ||
| 828 | } | ||
| 829 | write_file("c_module.c", c_module_source, finally) | ||
| 830 | |||
| 831 | rockspecs.from_persisted_table("c_module-1.0-1.rockspec", rockspec) | ||
| 832 | rockspec.variables["FIXTUREDEP_LIBDIR"] = testing_paths.fixtures_dir | ||
| 833 | assert.truthy(build_builtin.run(rockspec)) | ||
| 834 | end) | ||
| 835 | |||
| 836 | it("returns false if any external dependency is missing", function() | ||
| 837 | local rockspec = { | ||
| 838 | rockspec_format = "3.0", | ||
| 839 | package = "c_module", | ||
| 840 | version = "1.0-1", | ||
| 841 | source = { | ||
| 842 | url = "https://example.com/c_module" | ||
| 843 | }, | ||
| 844 | external_dependencies = { | ||
| 845 | EXTDEP = { | ||
| 846 | library = "missing" | ||
| 847 | } | ||
| 848 | }, | ||
| 849 | build = { | ||
| 850 | type = "builtin" | ||
| 851 | } | ||
| 852 | } | ||
| 853 | write_file("c_module.c", c_module_source, finally) | ||
| 854 | |||
| 855 | rockspecs.from_persisted_table("c_module-1.0-1.rockspec", rockspec) | ||
| 856 | rockspec.variables["EXTDEP_INCDIR"] = lfs.currentdir() | ||
| 857 | rockspec.variables["EXTDEP_LIBDIR"] = lfs.currentdir() | ||
| 858 | assert.falsy(build_builtin.run(rockspec)) | ||
| 859 | end) | ||
| 860 | end) | ||
| 861 | end) | ||
| 862 | |||
| 863 | describe("#unix build from #git", function() | 513 | describe("#unix build from #git", function() |
| 864 | local git | 514 | local git |
| 865 | 515 | ||
| @@ -886,6 +536,4 @@ describe("LuaRocks build #unit", function() | |||
| 886 | assert.is_true(run.luarocks_bool("build --branch test-branch ./my_branch-1.0-1.rockspec")) | 536 | assert.is_true(run.luarocks_bool("build --branch test-branch ./my_branch-1.0-1.rockspec")) |
| 887 | end) | 537 | end) |
| 888 | end) | 538 | end) |
| 889 | |||
| 890 | end) | 539 | end) |
| 891 | |||
diff --git a/spec/unit_build_spec.lua b/spec/unit_build_spec.lua new file mode 100644 index 00000000..6ab143c6 --- /dev/null +++ b/spec/unit_build_spec.lua | |||
| @@ -0,0 +1,369 @@ | |||
| 1 | local test_env = require("spec.util.test_env") | ||
| 2 | local lfs = require("lfs") | ||
| 3 | local get_tmp_path = test_env.get_tmp_path | ||
| 4 | local run = test_env.run | ||
| 5 | local testing_paths = test_env.testing_paths | ||
| 6 | local write_file = test_env.write_file | ||
| 7 | local P = test_env.P | ||
| 8 | |||
| 9 | test_env.unload_luarocks() | ||
| 10 | |||
| 11 | test_env.unload_luarocks() | ||
| 12 | test_env.setup_specs() | ||
| 13 | local cfg = require("luarocks.core.cfg") | ||
| 14 | local deps = require("luarocks.deps") | ||
| 15 | local fs = require("luarocks.fs") | ||
| 16 | local path = require("luarocks.path") | ||
| 17 | local rockspecs = require("luarocks.rockspecs") | ||
| 18 | local build_builtin = require("luarocks.build.builtin") | ||
| 19 | |||
| 20 | local c_module_source = [[ | ||
| 21 | #include <lua.h> | ||
| 22 | #include <lauxlib.h> | ||
| 23 | |||
| 24 | int luaopen_c_module(lua_State* L) { | ||
| 25 | lua_newtable(L); | ||
| 26 | lua_pushinteger(L, 1); | ||
| 27 | lua_setfield(L, -2, "c_module"); | ||
| 28 | return 1; | ||
| 29 | } | ||
| 30 | ]] | ||
| 31 | |||
| 32 | describe("LuaRocks build #unit", function() | ||
| 33 | local runner | ||
| 34 | |||
| 35 | lazy_setup(function() | ||
| 36 | runner = require("luacov.runner") | ||
| 37 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | ||
| 38 | runner.tick = true | ||
| 39 | cfg.init() | ||
| 40 | fs.init() | ||
| 41 | deps.check_lua_incdir(cfg.variables) | ||
| 42 | deps.check_lua_libdir(cfg.variables) | ||
| 43 | end) | ||
| 44 | |||
| 45 | lazy_teardown(function() | ||
| 46 | runner.shutdown() | ||
| 47 | end) | ||
| 48 | |||
| 49 | describe("build.builtin", function() | ||
| 50 | it("builtin auto installs files in lua subdir", function() | ||
| 51 | test_env.run_in_tmp(function(tmpdir) | ||
| 52 | lfs.mkdir("lua") | ||
| 53 | write_file("lua_module-1.0-1.rockspec", [[ | ||
| 54 | package = "lua_module" | ||
| 55 | version = "1.0-1" | ||
| 56 | source = { | ||
| 57 | url = "http://example.com/lua_module" | ||
| 58 | } | ||
| 59 | build = { | ||
| 60 | type = "builtin", | ||
| 61 | modules = {} | ||
| 62 | } | ||
| 63 | ]], finally) | ||
| 64 | write_file("lua/lua_module.lua", "return 123", finally) | ||
| 65 | |||
| 66 | assert.is_true(run.luarocks_bool("build")) | ||
| 67 | assert.match("[\\/]lua_module%.lua", run.luarocks("show lua_module")) | ||
| 68 | end, finally) | ||
| 69 | end) | ||
| 70 | |||
| 71 | describe("builtin.autodetect_modules", function() | ||
| 72 | local tmpdir | ||
| 73 | local olddir | ||
| 74 | |||
| 75 | before_each(function() | ||
| 76 | tmpdir = get_tmp_path() | ||
| 77 | olddir = lfs.currentdir() | ||
| 78 | lfs.mkdir(tmpdir) | ||
| 79 | lfs.chdir(tmpdir) | ||
| 80 | fs.change_dir(tmpdir) | ||
| 81 | end) | ||
| 82 | |||
| 83 | after_each(function() | ||
| 84 | if olddir then | ||
| 85 | lfs.chdir(olddir) | ||
| 86 | fs.change_dir(olddir) | ||
| 87 | if tmpdir then | ||
| 88 | lfs.rmdir(tmpdir) | ||
| 89 | end | ||
| 90 | end | ||
| 91 | end) | ||
| 92 | |||
| 93 | local libs = { "foo1", "foo2" } | ||
| 94 | local incdirs = { "$(FOO1_INCDIR)", "$(FOO2_INCDIR)" } | ||
| 95 | local libdirs = { "$(FOO1_LIBDIR)", "$(FOO2_LIBDIR)" } | ||
| 96 | |||
| 97 | it("returns a table of the modules having as location the current directory", function() | ||
| 98 | write_file("module1.lua", "", finally) | ||
| 99 | write_file("module2.c", "", finally) | ||
| 100 | write_file("module3.c", "int luaopen_my_module()", finally) | ||
| 101 | write_file("test.lua", "", finally) | ||
| 102 | write_file("tests.lua", "", finally) | ||
| 103 | |||
| 104 | local modules = build_builtin.autodetect_modules(libs, incdirs, libdirs) | ||
| 105 | assert.same(modules, { | ||
| 106 | module1 = "module1.lua", | ||
| 107 | module2 = { | ||
| 108 | sources = "module2.c", | ||
| 109 | libraries = libs, | ||
| 110 | incdirs = incdirs, | ||
| 111 | libdirs = libdirs | ||
| 112 | }, | ||
| 113 | my_module = { | ||
| 114 | sources = "module3.c", | ||
| 115 | libraries = libs, | ||
| 116 | incdirs = incdirs, | ||
| 117 | libdirs = libdirs | ||
| 118 | } | ||
| 119 | }) | ||
| 120 | end) | ||
| 121 | |||
| 122 | local test_with_location = function(location) | ||
| 123 | lfs.mkdir(location) | ||
| 124 | lfs.mkdir(location .. "/dir1") | ||
| 125 | lfs.mkdir(location .. "/dir1/dir2") | ||
| 126 | |||
| 127 | write_file(location .. "/module1.lua", "", finally) | ||
| 128 | write_file(location .. "/dir1/module2.c", "", finally) | ||
| 129 | write_file(location .. "/dir1/dir2/module3.c", "int luaopen_my_module()", finally) | ||
| 130 | write_file(location .. "/test.lua", "", finally) | ||
| 131 | write_file(location .. "/tests.lua", "", finally) | ||
| 132 | |||
| 133 | local modules = build_builtin.autodetect_modules(libs, incdirs, libdirs) | ||
| 134 | assert.same(modules, { | ||
| 135 | module1 = location .. "/module1.lua", | ||
| 136 | ["dir1.module2"] = { | ||
| 137 | sources = location .. "/dir1/module2.c", | ||
| 138 | libraries = libs, | ||
| 139 | incdirs = incdirs, | ||
| 140 | libdirs = libdirs | ||
| 141 | }, | ||
| 142 | my_module = { | ||
| 143 | sources = location .. "/dir1/dir2/module3.c", | ||
| 144 | libraries = libs, | ||
| 145 | incdirs = incdirs, | ||
| 146 | libdirs = libdirs | ||
| 147 | } | ||
| 148 | }) | ||
| 149 | |||
| 150 | lfs.rmdir(location .. "/dir1/dir2") | ||
| 151 | lfs.rmdir(location .. "/dir1") | ||
| 152 | lfs.rmdir(location) | ||
| 153 | end | ||
| 154 | |||
| 155 | it("returns a table of the modules having as location the src directory", function() | ||
| 156 | test_with_location("src") | ||
| 157 | end) | ||
| 158 | |||
| 159 | it("returns a table of the modules having as location the lua directory", function() | ||
| 160 | test_with_location("lua") | ||
| 161 | end) | ||
| 162 | |||
| 163 | it("returns as second and third argument tables of the bin files and copy directories", function() | ||
| 164 | lfs.mkdir("doc") | ||
| 165 | lfs.mkdir("docs") | ||
| 166 | lfs.mkdir("samples") | ||
| 167 | lfs.mkdir("tests") | ||
| 168 | lfs.mkdir("bin") | ||
| 169 | write_file("bin/binfile", "", finally) | ||
| 170 | |||
| 171 | local _, install, copy_directories = build_builtin.autodetect_modules({}, {}, {}) | ||
| 172 | assert.same(install, { bin = { P"bin/binfile" } }) | ||
| 173 | assert.same(copy_directories, { "doc", "docs", "samples", "tests" }) | ||
| 174 | |||
| 175 | lfs.rmdir("doc") | ||
| 176 | lfs.rmdir("docs") | ||
| 177 | lfs.rmdir("samples") | ||
| 178 | lfs.rmdir("tests") | ||
| 179 | lfs.rmdir("bin") | ||
| 180 | end) | ||
| 181 | end) | ||
| 182 | |||
| 183 | describe("builtin.run", function() | ||
| 184 | local tmpdir | ||
| 185 | local olddir | ||
| 186 | |||
| 187 | before_each(function() | ||
| 188 | tmpdir = get_tmp_path() | ||
| 189 | olddir = lfs.currentdir() | ||
| 190 | lfs.mkdir(tmpdir) | ||
| 191 | lfs.chdir(tmpdir) | ||
| 192 | fs.change_dir(tmpdir) | ||
| 193 | path.use_tree(lfs.currentdir()) | ||
| 194 | end) | ||
| 195 | |||
| 196 | after_each(function() | ||
| 197 | if olddir then | ||
| 198 | lfs.chdir(olddir) | ||
| 199 | fs.change_dir(olddir) | ||
| 200 | if tmpdir then | ||
| 201 | lfs.rmdir(tmpdir) | ||
| 202 | end | ||
| 203 | end | ||
| 204 | end) | ||
| 205 | |||
| 206 | it("returns false if the rockspec has no build modules and its format does not support autoextraction", function() | ||
| 207 | local rockspec = { | ||
| 208 | package = "test", | ||
| 209 | version = "1.0-1", | ||
| 210 | source = { | ||
| 211 | url = "http://example.com/test" | ||
| 212 | }, | ||
| 213 | build = {} | ||
| 214 | } | ||
| 215 | |||
| 216 | rockspecs.from_persisted_table("test-1.0-1.rockspec", rockspec) | ||
| 217 | assert.falsy(build_builtin.run(rockspec)) | ||
| 218 | rockspec.rockspec_format = "1.0" | ||
| 219 | assert.falsy(build_builtin.run(rockspec)) | ||
| 220 | end) | ||
| 221 | |||
| 222 | it("returns false if lua.h could not be found", function() | ||
| 223 | local rockspec = { | ||
| 224 | package = "c_module", | ||
| 225 | version = "1.0-1", | ||
| 226 | source = { | ||
| 227 | url = "http://example.com/c_module" | ||
| 228 | }, | ||
| 229 | build = { | ||
| 230 | type = "builtin", | ||
| 231 | modules = { | ||
| 232 | c_module = "c_module.c" | ||
| 233 | } | ||
| 234 | } | ||
| 235 | } | ||
| 236 | write_file("c_module.c", c_module_source, finally) | ||
| 237 | |||
| 238 | rockspecs.from_persisted_table("c_module-1.0-1.rockspec", rockspec) | ||
| 239 | rockspec.variables = { LUA_INCDIR = "invalid" } | ||
| 240 | assert.falsy(build_builtin.run(rockspec)) | ||
| 241 | end) | ||
| 242 | |||
| 243 | it("returns false if the build fails", function() | ||
| 244 | local rockspec = { | ||
| 245 | package = "c_module", | ||
| 246 | version = "1.0-1", | ||
| 247 | source = { | ||
| 248 | url = "http://example.com/c_module" | ||
| 249 | }, | ||
| 250 | build = { | ||
| 251 | type = "builtin", | ||
| 252 | modules = { | ||
| 253 | c_module = "c_module.c" | ||
| 254 | } | ||
| 255 | } | ||
| 256 | } | ||
| 257 | write_file("c_module.c", c_module_source .. "invalid", finally) | ||
| 258 | |||
| 259 | rockspecs.from_persisted_table("c_module-1.0-1.rockspec", rockspec) | ||
| 260 | assert.falsy(build_builtin.run(rockspec)) | ||
| 261 | end) | ||
| 262 | |||
| 263 | it("returns true if the build succeeds with C module", function() | ||
| 264 | local rockspec = { | ||
| 265 | package = "c_module", | ||
| 266 | version = "1.0-1", | ||
| 267 | source = { | ||
| 268 | url = "http://example.com/c_module" | ||
| 269 | }, | ||
| 270 | build = { | ||
| 271 | type = "builtin", | ||
| 272 | modules = { | ||
| 273 | c_module = "c_module.c" | ||
| 274 | } | ||
| 275 | } | ||
| 276 | } | ||
| 277 | write_file("c_module.c", c_module_source, finally) | ||
| 278 | |||
| 279 | rockspecs.from_persisted_table("c_module-1.0-1.rockspec", rockspec) | ||
| 280 | assert.truthy(build_builtin.run(rockspec)) | ||
| 281 | assert.truthy(lfs.attributes("lib/luarocks/rocks-" .. test_env.lua_version .. "/c_module/1.0-1/lib/c_module." .. test_env.lib_extension)) | ||
| 282 | end) | ||
| 283 | |||
| 284 | it("returns true if the build succeeds with Lua module", function() | ||
| 285 | local rockspec = { | ||
| 286 | rockspec_format = "1.0", | ||
| 287 | package = "test", | ||
| 288 | version = "1.0-1", | ||
| 289 | source = { | ||
| 290 | url = "http://example.com/test" | ||
| 291 | }, | ||
| 292 | build = { | ||
| 293 | type = "builtin", | ||
| 294 | modules = { | ||
| 295 | test = "test.lua" | ||
| 296 | } | ||
| 297 | } | ||
| 298 | } | ||
| 299 | write_file("test.lua", "return {}", finally) | ||
| 300 | |||
| 301 | rockspecs.from_persisted_table("test-1.0-1.rockspec", rockspec) | ||
| 302 | assert.truthy(build_builtin.run(rockspec)) | ||
| 303 | assert.truthy(lfs.attributes("lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/lua/test.lua")) | ||
| 304 | end) | ||
| 305 | |||
| 306 | it("automatically extracts the modules and libraries if they are not given and builds against any external dependencies", function() | ||
| 307 | local fdir = testing_paths.fixtures_dir | ||
| 308 | if test_env.TEST_TARGET_OS == "windows" then | ||
| 309 | if test_env.MINGW then | ||
| 310 | os.execute("gcc -shared -o " .. fdir .. "/libfixturedep.dll -Wl,--out-implib," .. fdir .."/libfixturedep.a " .. fdir .. "/fixturedep.c") | ||
| 311 | else | ||
| 312 | os.execute("cl " .. fdir .. "\\fixturedep.c /link /export:fixturedep_fn /out:" .. fdir .. "\\fixturedep.dll /implib:" .. fdir .. "\\fixturedep.lib") | ||
| 313 | end | ||
| 314 | elseif test_env.TEST_TARGET_OS == "linux" then | ||
| 315 | os.execute("gcc -shared -o " .. fdir .. "/libfixturedep.so " .. fdir .. "/fixturedep.c") | ||
| 316 | elseif test_env.TEST_TARGET_OS == "osx" then | ||
| 317 | os.execute("cc -dynamiclib -o " .. fdir .. "/libfixturedep.dylib " .. fdir .. "/fixturedep.c") | ||
| 318 | end | ||
| 319 | |||
| 320 | local rockspec = { | ||
| 321 | rockspec_format = "3.0", | ||
| 322 | package = "c_module", | ||
| 323 | version = "1.0-1", | ||
| 324 | source = { | ||
| 325 | url = "http://example.com/c_module" | ||
| 326 | }, | ||
| 327 | external_dependencies = { | ||
| 328 | FIXTUREDEP = { | ||
| 329 | library = "fixturedep" | ||
| 330 | } | ||
| 331 | }, | ||
| 332 | build = { | ||
| 333 | type = "builtin" | ||
| 334 | } | ||
| 335 | } | ||
| 336 | write_file("c_module.c", c_module_source, finally) | ||
| 337 | |||
| 338 | rockspecs.from_persisted_table("c_module-1.0-1.rockspec", rockspec) | ||
| 339 | rockspec.variables["FIXTUREDEP_LIBDIR"] = testing_paths.fixtures_dir | ||
| 340 | assert.truthy(build_builtin.run(rockspec)) | ||
| 341 | end) | ||
| 342 | |||
| 343 | it("returns false if any external dependency is missing", function() | ||
| 344 | local rockspec = { | ||
| 345 | rockspec_format = "3.0", | ||
| 346 | package = "c_module", | ||
| 347 | version = "1.0-1", | ||
| 348 | source = { | ||
| 349 | url = "https://example.com/c_module" | ||
| 350 | }, | ||
| 351 | external_dependencies = { | ||
| 352 | EXTDEP = { | ||
| 353 | library = "missing" | ||
| 354 | } | ||
| 355 | }, | ||
| 356 | build = { | ||
| 357 | type = "builtin" | ||
| 358 | } | ||
| 359 | } | ||
| 360 | write_file("c_module.c", c_module_source, finally) | ||
| 361 | |||
| 362 | rockspecs.from_persisted_table("c_module-1.0-1.rockspec", rockspec) | ||
| 363 | rockspec.variables["EXTDEP_INCDIR"] = lfs.currentdir() | ||
| 364 | rockspec.variables["EXTDEP_LIBDIR"] = lfs.currentdir() | ||
| 365 | assert.falsy(build_builtin.run(rockspec)) | ||
| 366 | end) | ||
| 367 | end) | ||
| 368 | end) | ||
| 369 | end) | ||
