Skip to content
Snippets Groups Projects
Verified Commit 1619b412 authored by Yaroslav Dynnikov's avatar Yaroslav Dynnikov
Browse files

fix: mistake in inner tests runner

1. Fix PICOLIB_AUTORUN env var naming.
2. Add an assertion that it works as expected.
3. Show output if listing tests fails.
3. Run inner tests with listen port :0 to avoid
   "address already in use" errors.
parent 0d8678ab
No related branches found
No related tags found
1 merge request!33fix: mistake in inner tests runner (v2)
Pipeline #3486 passed
......@@ -41,10 +41,13 @@ impl Stash {
#[no_mangle]
pub extern "C" fn luaopen_picolib(l: *mut std::ffi::c_void) -> c_int {
if std::env::var("PICOLIB_NO_AUTORUN").is_ok() {
// Skip box.cfg and other initialization
// Used mostly for testing purposes
} else {
// Perform box.cfg and other initialization.
// It's disabled only for testing purposes.
if std::env::var("PICOLIB_AUTORUN")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(true)
{
main_run();
}
......
......@@ -10,7 +10,7 @@ fn positive() {
let mut cmd = Command::cargo_bin("picodata").unwrap();
cmd.current_dir(temp_path);
cmd.env("PICOLIB_NO_AUTORUN", "");
cmd.env("PICOLIB_AUTORUN", "false");
cmd.arg("run");
cmd.arg("-e").arg(
r#"
......@@ -57,7 +57,7 @@ fn broken_tarantool() {
#[test]
fn pass_arguments() {
let mut cmd = Command::cargo_bin("picodata").unwrap();
cmd.env("PICOLIB_NO_AUTORUN", "");
cmd.env("PICOLIB_AUTORUN", "false");
cmd.arg("run");
cmd.args(["-e", "error('xxx', 0)"]);
cmd.assert().failure().stderr(
......@@ -74,7 +74,7 @@ fn pass_environment() {
let mut cmd = Command::cargo_bin("picodata").unwrap();
cmd.current_dir(temp_path);
cmd.arg("run");
cmd.env("PICOLIB_NO_AUTORUN", "");
cmd.env("PICOLIB_AUTORUN", "false");
cmd.env("LUA_CPATH", "/dev/null/?");
cmd.env("CUSTOM_VAR", "keep me");
cmd.env("TARANTOOL_VAR", "purge me");
......@@ -88,6 +88,11 @@ fn pass_environment() {
cmd.args(["--peer", "i3"]);
cmd.arg("-e").arg(
r#"
assert(
type(box.cfg) == "function",
"Picodata shouldn't be running yet"
)
cpath = os.environ()['LUA_CPATH']
assert(cpath and cpath:endswith(';/dev/null/?'), cpath)
......@@ -125,7 +130,7 @@ fn precedence() {
let mut cmd = Command::cargo_bin("picodata").unwrap();
cmd.current_dir(temp_path);
cmd.arg("run");
cmd.env("PICOLIB_NO_AUTORUN", "");
cmd.env("PICOLIB_AUTORUN", "false");
cmd.env("PICODATA_DATA_DIR", "./somewhere");
cmd.env("PICODATA_LISTEN", "0.0.0.0:0");
cmd.arg("-e").arg(
......
......@@ -21,6 +21,10 @@ fn main() {
cmd.arg("run");
cmd.arg("-e").arg(
r#"
assert(
type(box.cfg) == "function",
"Picodata shouldn't be running yet"
)
log = require('log')
picolib = require('picolib')
for t, _ in pairs(picolib.test) do
......@@ -32,6 +36,14 @@ fn main() {
cmd.timeout(Duration::from_secs(1));
let result = cmd.output().unwrap();
if !result.status.success() {
println!(
"{}\nPicodata exit status: {}",
String::from_utf8(result.stderr).unwrap(),
result.status
);
std::process::exit(1);
}
let stdout = String::from_utf8(result.stdout).unwrap();
let mut cnt_passed = 0u32;
let mut cnt_failed = 0u32;
......@@ -81,11 +93,12 @@ impl From<std::string::FromUtf8Error> for TestError {
}
fn run_test(test_name: &str) -> Result<(), TestError> {
let temp = tempdir().unwrap();
let temp = tempdir()?;
let temp_path = temp.path();
let mut cmd = Command::cargo_bin("picodata").unwrap();
cmd.current_dir(temp_path);
cmd.env("PICODATA_LISTEN", "0.0.0.0:0");
cmd.arg("run");
cmd.arg("-e");
cmd.arg(format!("picolib.test.{}() os.exit(0)", test_name));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment