1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 22:21:29 +00:00

Add unittest.testing() to make test building conditional

This commit is contained in:
dmiller
2014-03-06 17:15:05 +00:00
parent f8242124b8
commit 88146749f6
5 changed files with 33 additions and 2 deletions

View File

@@ -15,6 +15,9 @@
--
-- The library is driven by the unittest NSE script.
--
-- @args unittest.run Run tests. Causes <code>unittest.testing()</code> to
-- return true.
--
-- @copyright Same as Nmap--See http://nmap.org/book/man-legal.html
local stdnse = require "stdnse"
@@ -136,11 +139,22 @@ local libs = {
"xmpp",
}
local am_testing = stdnse.get_script_args('unittest.run')
---Check whether tests are being run
--
-- Libraries can use this function to avoid the overhead of creating tests if
-- the user hasn't chosen to run them.
-- @return true if unittests are being run, false otherwise.
function testing()
return am_testing
end
---
-- Run tests provided by NSE libraries
-- @param to_test A list (table) of libraries to test. If none is provided, all
-- libraries are tested.
run_tests = function(to_test)
am_testing = true
if to_test == nil then
to_test = libs
end
@@ -354,6 +368,11 @@ expected_failure = function(test)
end
end
if not testing() then
return _ENV
end
-- Self test
test_suite = TestSuite:new()