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 /spec/build_spec.lua | |
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
Diffstat (limited to 'spec/build_spec.lua')
-rw-r--r-- | spec/build_spec.lua | 352 |
1 files changed, 0 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 | |||