centralized ensure dir
This commit is contained in:
75
test.ce
75
test.ce
@@ -7,6 +7,7 @@ var time = use('time')
|
||||
var json = use('json')
|
||||
var blob = use('blob')
|
||||
var dbg = use('js')
|
||||
var testlib = use('internal/testlib')
|
||||
|
||||
// run gc with dbg.gc()
|
||||
|
||||
@@ -29,23 +30,8 @@ def ACTOR_TEST_TIMEOUT = 30000 // 30 seconds timeout for actor tests
|
||||
var pending_actor_tests = []
|
||||
var actor_test_results = []
|
||||
|
||||
// Check if current directory is a valid cell package
|
||||
function is_valid_package(dir) {
|
||||
var _dir = dir == null ? '.' : dir
|
||||
return fd.is_file(_dir + '/cell.toml')
|
||||
}
|
||||
|
||||
// Get current package name from cell.toml or null
|
||||
function get_current_package_name() {
|
||||
if (!is_valid_package('.')) return null
|
||||
var _load = function() {
|
||||
var config = pkg.load_config(null)
|
||||
return config.package || 'local'
|
||||
} disruption {
|
||||
return 'local'
|
||||
}
|
||||
return _load()
|
||||
}
|
||||
var is_valid_package = testlib.is_valid_package
|
||||
var get_current_package_name = testlib.get_current_package_name
|
||||
|
||||
// Parse arguments
|
||||
// Usage:
|
||||
@@ -192,32 +178,8 @@ if (diff_mode && !run_ast_noopt_fn) {
|
||||
return
|
||||
}
|
||||
|
||||
// Diff mode: deep comparison helper
|
||||
function values_equal(a, b) {
|
||||
var i = 0
|
||||
if (a == b) return true
|
||||
if (is_null(a) && is_null(b)) return true
|
||||
if (is_null(a) || is_null(b)) return false
|
||||
if (is_array(a) && is_array(b)) {
|
||||
if (length(a) != length(b)) return false
|
||||
i = 0
|
||||
while (i < length(a)) {
|
||||
if (!values_equal(a[i], b[i])) return false
|
||||
i = i + 1
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function describe(val) {
|
||||
if (is_null(val)) return "null"
|
||||
if (is_text(val)) return `"${val}"`
|
||||
if (is_number(val)) return text(val)
|
||||
if (is_logical(val)) return text(val)
|
||||
if (is_function(val)) return "<function>"
|
||||
return "<other>"
|
||||
}
|
||||
var values_equal = testlib.values_equal
|
||||
var describe = testlib.describe
|
||||
|
||||
// Diff mode: run a test function through noopt and compare
|
||||
var diff_mismatches = 0
|
||||
@@ -251,31 +213,8 @@ function diff_check(test_name, file_path, opt_fn, noopt_fn) {
|
||||
}
|
||||
}
|
||||
|
||||
function ensure_dir(path) {
|
||||
if (fd.is_dir(path)) return true
|
||||
|
||||
var parts = array(path, '/')
|
||||
var current = starts_with(path, '/') ? '/' : ''
|
||||
var i = 0
|
||||
for (i = 0; i < length(parts); i++) {
|
||||
if (parts[i] == '') continue
|
||||
current = current + parts[i] + '/'
|
||||
if (!fd.is_dir(current))
|
||||
fd.mkdir(current)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Get the directory for a package
|
||||
function get_pkg_dir(package_name) {
|
||||
if (!package_name) {
|
||||
return fd.realpath('.')
|
||||
}
|
||||
if (starts_with(package_name, '/')) {
|
||||
return package_name
|
||||
}
|
||||
return shop.get_package_dir(package_name)
|
||||
}
|
||||
var ensure_dir = fd.ensure_dir
|
||||
var get_pkg_dir = testlib.get_pkg_dir
|
||||
|
||||
// Collect .ce actor tests from a package
|
||||
function collect_actor_tests(package_name, specific_test) {
|
||||
|
||||
Reference in New Issue
Block a user