From b9dcc25ff5bdd4e9ffc4942064221845da2cc238 Mon Sep 17 00:00:00 2001
From: Egor Ivkov <e.o.ivkov@gmail.com>
Date: Wed, 23 Nov 2022 20:11:12 +0300
Subject: [PATCH 1/2] chore(tests): remove `test.sh`

---
 .gitlab-ci.yml        |  3 +--
 Makefile              |  4 ++--
 README.md             |  1 +
 tarantool/Cargo.toml  |  5 +++++
 tarantool/test/run.rs | 30 ++++++++++++++++++++++++++++++
 tests/test.sh         | 23 -----------------------
 6 files changed, 39 insertions(+), 27 deletions(-)
 create mode 100644 tarantool/test/run.rs
 delete mode 100755 tests/test.sh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a2a85e1b..bb79a1ac 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -135,7 +135,6 @@ build-base-image:
     - cargo clippy --features "${CARGO_FEATURES}" --workspace -- --deny warnings
     - cargo build --features "${CARGO_FEATURES}" --all
     - cargo test --features "${CARGO_FEATURES}"
-    - ./tests/test.sh
     - |
       # Save cache
       if [ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]; then
@@ -156,7 +155,7 @@ test-vanilla:
   variables:
     CACHE_ARCHIVE: /shared-storage/tarantool-module/vanilla-cache.tar
     DOCKER_IMAGE: ${VANILLA_DOCKER_IMAGE}
-    CARGO_FEATURES: ""
+    CARGO_FEATURES: default
 
 test-picodata:
   extends: .test
diff --git a/Makefile b/Makefile
index f13d188c..26e82f8f 100644
--- a/Makefile
+++ b/Makefile
@@ -3,11 +3,11 @@ all:
 
 test:
 	cargo build -p tarantool-module-test-runner
-	tests/test.sh
+	cargo test
 
 test-pd:
 	cargo build -p tarantool-module-test-runner --features=picodata
-	TARANTOOL_EXECUTABLE=tarantool-pd tests/test.sh
+	TARANTOOL_EXECUTABLE=tarantool-pd cargo test
 
 benchmark:
 	tests/run_benchmarks.lua
diff --git a/README.md b/README.md
index 8d28a218..9135d2b3 100644
--- a/README.md
+++ b/README.md
@@ -449,6 +449,7 @@ We use [SemVer](http://semver.org/) for versioning. For the versions available,
 - **Anton Melnikov**
 - **Dmitriy Koltsov**
 - **Georgy Moshkin**
+- **Egor Ivkov**
 
 © 2020-2022 Picodata.io https://git.picodata.io/picodata
 ## License
diff --git a/tarantool/Cargo.toml b/tarantool/Cargo.toml
index 4ac3d21e..089d61ba 100644
--- a/tarantool/Cargo.toml
+++ b/tarantool/Cargo.toml
@@ -56,3 +56,8 @@ defer = []
 picodata = []
 all = ["default", "schema", "defer"]
 tarantool_test = ["linkme", "tester"]
+
+[[test]]
+name = "run_tests"
+path = "test/run.rs"
+harness = false
diff --git a/tarantool/test/run.rs b/tarantool/test/run.rs
new file mode 100644
index 00000000..3da0a32b
--- /dev/null
+++ b/tarantool/test/run.rs
@@ -0,0 +1,30 @@
+use serde::{Deserialize, Serialize};
+use std::env;
+use std::process::Command;
+
+#[derive(Serialize, Deserialize)]
+struct Metadata {
+    workspace_root: String,
+}
+
+fn main() {
+    let filter = env::args().skip(1);
+    let tarantool_exec = if let Ok(path) = env::var("TARANTOOL_EXECUTABLE") {
+        path
+    } else {
+        "tarantool".to_owned()
+    };
+    let metadata = Command::new("cargo")
+        .arg("metadata")
+        .arg("--format-version=1")
+        .output()
+        .expect("Failed to get cargo metadata output");
+    let metadata: Metadata =
+        serde_json::from_slice(&metadata.stdout).expect("Failed to parse cargo metadata output");
+    let status = Command::new(tarantool_exec)
+        .arg(format!("{}/tests/run_tests.lua", metadata.workspace_root))
+        .args(filter)
+        .status()
+        .expect("Failed to run tarantool child process");
+    assert!(status.success())
+}
diff --git a/tests/test.sh b/tests/test.sh
deleted file mode 100755
index 18e7a768..00000000
--- a/tests/test.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-
-case "$1" in
-    -t | --tarantool )
-        TARANTOOL_EXECUTABLE="$2"
-        shift
-        shift
-        ;;
-esac
-
-FILTER="$1"
-
-TARANTOOL_EXECUTABLE=${TARANTOOL_EXECUTABLE:-tarantool}
-
-WORKSPACE_ROOT=$(
-    cargo metadata --format-version=1 |
-        $TARANTOOL_EXECUTABLE -e \
-            'print(require("json").decode(io.read("*l")).workspace_root)'
-)
-
-"${TARANTOOL_EXECUTABLE}" "${WORKSPACE_ROOT}/tests/run_tests.lua" "${FILTER}"
-- 
GitLab


From 4f9c061b2729a4e8f6ac31afa3ad85e612ce0116 Mon Sep 17 00:00:00 2001
From: Egor Ivkov <e.o.ivkov@gmail.com>
Date: Thu, 24 Nov 2022 16:53:10 +0300
Subject: [PATCH 2/2] Fix review comments: unwrap_or, lowercase errors

---
 tarantool/test/run.rs | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/tarantool/test/run.rs b/tarantool/test/run.rs
index 3da0a32b..8e6c4584 100644
--- a/tarantool/test/run.rs
+++ b/tarantool/test/run.rs
@@ -9,22 +9,19 @@ struct Metadata {
 
 fn main() {
     let filter = env::args().skip(1);
-    let tarantool_exec = if let Ok(path) = env::var("TARANTOOL_EXECUTABLE") {
-        path
-    } else {
-        "tarantool".to_owned()
-    };
+    let tarantool_exec =
+        env::var("TARANTOOL_EXECUTABLE").unwrap_or_else(|_| "tarantool".to_owned());
     let metadata = Command::new("cargo")
         .arg("metadata")
         .arg("--format-version=1")
         .output()
-        .expect("Failed to get cargo metadata output");
+        .expect("failed to get cargo metadata output");
     let metadata: Metadata =
-        serde_json::from_slice(&metadata.stdout).expect("Failed to parse cargo metadata output");
+        serde_json::from_slice(&metadata.stdout).expect("failed to parse cargo metadata output");
     let status = Command::new(tarantool_exec)
         .arg(format!("{}/tests/run_tests.lua", metadata.workspace_root))
         .args(filter)
         .status()
-        .expect("Failed to run tarantool child process");
+        .expect("failed to run tarantool child process");
     assert!(status.success())
 }
-- 
GitLab