diff options
| author | ruki <[email protected]> | 2017-05-20 00:42:05 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-05-20 00:42:05 +0800 |
| commit | ce27b8d4dfae08a01f473e7a5cfbb94f6e79c967 (patch) | |
| tree | 76cb0f63a16787f920c3dac016ad7b6f5c2d7250 | |
| parent | c6876982657c8bf65b7e2a05fc1206b3aacc0ff8 (diff) | |
improve test script
29 files changed, 300 insertions, 197 deletions
diff --git a/.travis.yml b/.travis.yml index 09cad854c..d3597c887 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,7 +38,7 @@ script: - cat xmake/core/_xmake_main.lua >> tmp - mv tmp xmake/core/_xmake_main.lua - cp core/build/xmake $(which xmake) || sudo cp core/build/xmake $(which xmake) - - tests/tests + - make test after_success: - luacov @@ -81,4 +81,8 @@ uninstall: @if [ -d $(prefix)/share/xmake ]; then rm -rf $(prefix)/share/xmake; fi @echo ok! +test: + @xmake lua tests/test.lua $(name) + @echo ok! + .PHONY: tip build install uninstall diff --git a/tests/build.lua b/tests/build.lua new file mode 100644 index 000000000..918b00133 --- /dev/null +++ b/tests/build.lua @@ -0,0 +1,30 @@ +-- main entry +function main(argv) + + -- generic? + os.exec("xmake m -b") + os.exec("xmake f -c") + os.exec("xmake") + os.exec("xmake p") + os.exec("xmake c") + os.exec("xmake f -m release") + os.exec("xmake -r -a -v --backtrace") + os.exec("xmake f --mode=debug --verbose --backtrace") + os.exec("xmake --rebuild --all --verbose --backtrace") + os.exec("xmake p --verbose --backtrace") + os.exec("xmake c --verbose --backtrace") + os.exec("xmake m -e buildtest") + os.exec("xmake m -l") + os.exec("xmake f --cc=gcc --cxx=g++") + os.exec("xmake m buildtest") + os.exec("xmake f --cc=clang --cxx=clang++ --ld=clang++ --verbose --backtrace") + os.exec("xmake m buildtest") + os.exec("xmake m -d buildtest") + + -- test iphoneos? + if argv and argv.iphoneos then + if os.host() == "macosx" then + os.exec("xmake m package -p iphoneos") + end + end +end diff --git a/tests/modules/hello/test.lua b/tests/modules/hello/test.lua new file mode 100755 index 000000000..431a82072 --- /dev/null +++ b/tests/modules/hello/test.lua @@ -0,0 +1,4 @@ +function main() + + print("hello") +end diff --git a/tests/modules/ping.lua b/tests/modules/ping.lua deleted file mode 100755 index 53ee0132a..000000000 --- a/tests/modules/ping.lua +++ /dev/null @@ -1,13 +0,0 @@ --- imports -import("core.tool.ping") - --- --- run tests: --- --- $ xmake l ./tests/modules/ping.lua --- -function main() - - -- send ping - table.dump(ping.send("www.tboox.org", "www.xmake.io", "www.github.com", "www.google.com", "unknown.invalid")) -end diff --git a/tests/modules/semver.lua b/tests/modules/semver.lua deleted file mode 100755 index 0db0c1718..000000000 --- a/tests/modules/semver.lua +++ /dev/null @@ -1,94 +0,0 @@ --- imports -import("core.base.semver") - --- select version -function _check_semver_select(results, required_ver, versions, tags, branches) - - -- select it - local version, source = semver.select(required_ver, versions or {}, tags or {}, branches or {}) - if (version.version or version) ~= results[1] or source ~= results[2] then - print("semver.select(\"%s\", {\"%s\"}, {\"%s\"}, {\"%s\"})" - , required_ver - , table.concat(versions or {}, "\", \"") - , table.concat(tags or {}, "\", \"") - , table.concat(branches or {}, "\", \"")) - raise("{\"%s\", \"%s\"} != {\"%s\", \"%s\"}", version.version or version, source or "", results[1] or "", results[2] or "") - end -end - --- test select version -function _test_semver_select() - - _check_semver_select({"1.5.1", "versions"} - , ">=1.5.0 <1.6.0" - , {"1.4.0", "1.5.0", "1.5.1"}) - - _check_semver_select({"1.5.1", "versions"} - , "^1.5.0" - ,{"1.4.0", "1.5.0", "1.5.1"}) - - _check_semver_select({"master", "branches"} - , "master" - , {"1.4.0", "1.5.0", "1.5.1"} - , {"v1.2.0", "v1.6.0"} - , {"master", "dev"}) - - print("semver.select: ok!") -end - --- parse version -function _check_semver_parse(version_str, major, minor, patch, prerelease, build) - - -- create it - local version = semver.parse(version_str) - - if version.major ~= major then - raise("major: \"%s\" != \"%s\"", version.major or "", major or "") - end - - if version.minor ~= minor then - raise("minor: \"%s\" != \"%s\"", version.minor or "", minor or "") - end - - if version.patch ~= patch then - raise("patch: \"%s\" != \"%s\"", version.patch or "", patch or "") - end - - if table.concat(version.prerelease or {}, ".") ~= table.concat(prerelease or {}, ".") then - raise("prerelease: \"%s\" != \"%s\"" - , table.concat(version.prerelease or {}, ".") or "" - , table.concat(prerelease or {}, ".") or "") - end - - if table.concat(version.build or {}, ".") ~= table.concat(build or {}, ".") then - raise("build: \"%s\" != \"%s\"" - , table.concat(version.build or {}, ".") or "" - , table.concat(build or {}, ".") or "") - end -end - --- test parse version -function _test_semver_parse() - - _check_semver_parse("1.2.3", 1, 2, 3) - _check_semver_parse("1.2.3-beta", 1, 2, 3, {"beta"}) - _check_semver_parse("1.2.3-beta+77", 1, 2, 3, {"beta"}, {"77"}) - _check_semver_parse("v1.2.3-alpha.1+77", 1, 2, 3, {"alpha", "1"}, {"77"}) - _check_semver_parse("v3.2.1-alpha.1+77.foo", 3, 2, 1, {"alpha", "1"}, {"77", "foo"}) - - print("semver.parse: ok!") -end - --- --- run tests: --- --- $ xmake l ./tests/modules/semver.lua --- -function main() - - -- test semver - _test_semver_parse() - - -- test select version - _test_semver_select() -end diff --git a/tests/projects/console_c++/test.lua b/tests/projects/console_c++/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/console_c++/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/console_c/test.lua b/tests/projects/console_c/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/console_c/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/console_dlang/test.lua b/tests/projects/console_dlang/test.lua new file mode 100644 index 000000000..82d2b61eb --- /dev/null +++ b/tests/projects/console_dlang/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build() + end +end diff --git a/tests/projects/console_go/test.lua b/tests/projects/console_go/test.lua new file mode 100644 index 000000000..82d2b61eb --- /dev/null +++ b/tests/projects/console_go/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build() + end +end diff --git a/tests/projects/console_objc++/test.lua b/tests/projects/console_objc++/test.lua new file mode 100644 index 000000000..be0449702 --- /dev/null +++ b/tests/projects/console_objc++/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build({iphoneos = true}) + end +end diff --git a/tests/projects/console_objc/test.lua b/tests/projects/console_objc/test.lua new file mode 100644 index 000000000..be0449702 --- /dev/null +++ b/tests/projects/console_objc/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build({iphoneos = true}) + end +end diff --git a/tests/projects/console_rust/test.lua b/tests/projects/console_rust/test.lua new file mode 100644 index 000000000..82d2b61eb --- /dev/null +++ b/tests/projects/console_rust/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build() + end +end diff --git a/tests/projects/console_swift/test.lua b/tests/projects/console_swift/test.lua new file mode 100644 index 000000000..be0449702 --- /dev/null +++ b/tests/projects/console_swift/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build({iphoneos = true}) + end +end diff --git a/tests/projects/merge_object/test.lua b/tests/projects/merge_object/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/merge_object/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/merge_static_library/test.lua b/tests/projects/merge_static_library/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/merge_static_library/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/shared_library_c++/test.lua b/tests/projects/shared_library_c++/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/shared_library_c++/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/shared_library_c/test.lua b/tests/projects/shared_library_c/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/shared_library_c/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/shared_library_dlang/test.lua b/tests/projects/shared_library_dlang/test.lua new file mode 100644 index 000000000..82d2b61eb --- /dev/null +++ b/tests/projects/shared_library_dlang/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build() + end +end diff --git a/tests/projects/static_library_c++/test.lua b/tests/projects/static_library_c++/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/static_library_c++/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/static_library_c/test.lua b/tests/projects/static_library_c/test.lua new file mode 100644 index 000000000..1ff9219ba --- /dev/null +++ b/tests/projects/static_library_c/test.lua @@ -0,0 +1,9 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + build() +end diff --git a/tests/projects/static_library_go/test.lua b/tests/projects/static_library_go/test.lua new file mode 100644 index 000000000..82d2b61eb --- /dev/null +++ b/tests/projects/static_library_go/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build() + end +end diff --git a/tests/projects/static_library_rust/test.lua b/tests/projects/static_library_rust/test.lua new file mode 100644 index 000000000..82d2b61eb --- /dev/null +++ b/tests/projects/static_library_rust/test.lua @@ -0,0 +1,11 @@ +-- imports +import("..build") + +-- main entry +function main() + + -- build project + if os.host() == "macosx" then + build() + end +end diff --git a/tests/test.lua b/tests/test.lua new file mode 100644 index 000000000..2f67ba416 --- /dev/null +++ b/tests/test.lua @@ -0,0 +1,45 @@ +-- imports +import("core.project.task") + +-- run test with the given name +function _run_test(name) + + -- find the test script + for _, script in ipairs(os.files(path.join(os.scriptdir(), "**", name, "test.lua"))) do + + -- trace + print("testing %s ...", script) + + -- enter script directory + os.cd(path.directory(script)) + + -- run test + task.run("lua", {script = path.filename(script)}) + break + end +end + +-- main entry +function main(name) + + -- run the given test + if name then + return _run_test(name) + end + + -- run all tests + for _, script in ipairs(os.files(path.join(os.scriptdir(), "**", "test.lua"))) do + + -- trace + print("testing %s ...", script) + + -- enter script directory + local oldir = os.cd(path.directory(script)) + + -- run test + task.run("lua", {script = path.filename(script)}) + + -- leave script directory + os.cd(oldir) + end +end diff --git a/tests/tests b/tests/tests deleted file mode 100755 index 32b8f9bd8..000000000 --- a/tests/tests +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash - -verbose=$1 -host=linux -if [ `uname` = "Darwin" ] || [ `uname | egrep -i darwin` ]; then - host=macosx -fi - -function exec() -{ - echo $1 - eval $1 $verbose - if [ $? -ne 0 ] - then exit -1 - fi - echo "" -} - -function build() -{ - # echo project name - echo "build $1" - - # build - exec "xmake f -c -P $1" - exec "xmake -P $1" - exec "xmake p -P $1" -} - -function build_for_iphoenos() -{ - # echo project name - echo "build $1" - - # package all archs for iphoneos - exec "xmake m -P $1 package -p iphoneos" -} - -# build for c -build "./tests/projects/console_c" -build "./tests/projects/static_library_c" -build "./tests/projects/shared_library_c" - -# build for c++ -build "./tests/projects/console_c++" -build "./tests/projects/static_library_c++" -build "./tests/projects/shared_library_c++" - -# merge object -build "./tests/projects/merge_object" - -# merge static library -build "./tests/projects/merge_static_library" - -# build for macosx -if [ $host = "macosx" ]; then - - # build for objc/c++ - build "./tests/projects/console_objc" - build "./tests/projects/console_objc++" - build_for_iphoenos "./tests/projects/console_objc" - build_for_iphoenos "./tests/projects/console_objc++" - - # build for swift - build "./tests/projects/console_swift" - build_for_iphoenos "./tests/projects/console_swift" - - # build for go - build "./tests/projects/console_go" - build "./tests/projects/static_library_go" - - # build for dlang - build "./tests/projects/console_dlang" - build "./tests/projects/static_library_dlang" - - # build for rust - build "./tests/projects/console_rust" - build "./tests/projects/static_library_rust" -fi - diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 5aad87d26..7827064e3 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -216,6 +216,11 @@ function os.match(pattern, mode) end end + -- remove "./" or '.\\' prefix + if pattern:sub(1, 2):find('%.[/\\]') then + pattern = pattern:sub(3) + end + -- get the root directory local rootdir = pattern local starpos = pattern:find("%*") diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index b7f5719a9..7e8438b8d 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -259,7 +259,7 @@ function table._dump(self, exclude, level) end io.write("}\n") else - io.write("<" .. tostring(v) .. ">") + io.write("<" .. tostring(self) .. ">") end end diff --git a/xmake/core/sandbox/modules/import.lua b/xmake/core/sandbox/modules/import.lua index c4011f7a4..921d3889a 100644 --- a/xmake/core/sandbox/modules/import.lua +++ b/xmake/core/sandbox/modules/import.lua @@ -51,6 +51,32 @@ function sandbox_import._modulename(name) return name end +-- get module path from name +function sandbox_import._modulepath(name) + + -- translate module path + -- + -- "package.module" => "package/module" + -- "..package.module" => "../../package/module" + -- + local startdots = true + local modulepath = name:gsub(".", function(c) + if c == '.' then + if startdots then + return ".." .. path.seperator() + else + return path.seperator() + end + else + startdots = false + return c + end + end) + + -- return module path + return modulepath +end + -- load module from file function sandbox_import._loadfile(filepath, instance) @@ -98,8 +124,8 @@ function sandbox_import._find(dir, name) -- check assert(dir and name) - -- replace "package.module" => "package/module" - name = (name:gsub("%.", "/")) + -- get module path + name = sandbox_import._modulepath(name) assert(name) -- load the single module? @@ -123,8 +149,8 @@ function sandbox_import._load(dir, name, instance) -- check assert(dir and name) - -- replace "package.module" => "package/module" - name = (name:gsub("%.", "/")) + -- get module path + name = sandbox_import._modulepath(name) assert(name) -- load the single module? @@ -233,6 +259,9 @@ end -- import("core.platform", {inherit = true}) -- => inherit the all interfaces of core.platform to the current scope -- +-- local test = import("test", {rootdir = "/tmp/xxx", anonymous = true}) +-- test() +-- -- @note the polymiorphism is not supported for import.inherit mode now. -- function sandbox_import.import(name, args) @@ -343,7 +372,9 @@ function sandbox_import.import(name, args) end -- import this module into the parent scope - scope_parent[imported_name] = module + if not args.anonymous then + scope_parent[imported_name] = module + end -- return it return module diff --git a/xmake/plugins/lua/xmake.lua b/xmake/plugins/lua/xmake.lua index 2789bf26a..78cd176ab 100644 --- a/xmake/plugins/lua/xmake.lua +++ b/xmake/plugins/lua/xmake.lua @@ -60,16 +60,16 @@ task("lua") if os.isfile(script) then -- run the given lua script file (xmake lua /tmp/script.lua) - import(path.basename(script), {rootdir = path.directory(script)})(unpack(option.get("arguments") or {})) + import(path.basename(script), {rootdir = path.directory(script), anonymous = true})(unpack(option.get("arguments") or {})) elseif os.isfile(path.join(os.scriptdir(), "scripts", script .. ".lua")) then -- run builtin lua script (xmake lua echo "hello xmake") - import("scripts." .. script)(unpack(option.get("arguments") or {})) + import("scripts." .. script, {anonymous = true})(unpack(option.get("arguments") or {})) else -- run modules (xmake lua core.xxx.xxx) - print(import(script)(unpack(option.get("arguments") or {}))) + print(import(script, {anonymous = true})(unpack(option.get("arguments") or {}))) end else -- enter interactive mode |
