summary refs log tree commit diff
path: root/tests/run-make/libtest-json
diff options
context:
space:
mode:
authorJoshua Nelson <github@jyn.dev>2023-03-30 07:34:55 -0500
committerJoshua Nelson <github@jyn.dev>2023-03-30 07:34:55 -0500
commit433da1fc047bb39a263eefca4bdb2b1972f1d2ce (patch)
tree28540e78fdd5fdf158267e67495121ac64f0866a /tests/run-make/libtest-json
parentf2d9a3d0771504f1ae776226a5799dcb4408a91a (diff)
downloadrust-433da1fc047bb39a263eefca4bdb2b1972f1d2ce.tar.gz
rust-433da1fc047bb39a263eefca4bdb2b1972f1d2ce.zip
Move almost all run-make-fulldeps to run-make
They pass fine.
Diffstat (limited to 'tests/run-make/libtest-json')
-rw-r--r--tests/run-make/libtest-json/Makefile18
-rw-r--r--tests/run-make/libtest-json/f.rs22
-rw-r--r--tests/run-make/libtest-json/output-default.json10
-rw-r--r--tests/run-make/libtest-json/output-stdout-success.json10
-rwxr-xr-xtests/run-make/libtest-json/validate_json.py8
5 files changed, 68 insertions, 0 deletions
diff --git a/tests/run-make/libtest-json/Makefile b/tests/run-make/libtest-json/Makefile
new file mode 100644
index 00000000000..37b6cb9e2d4
--- /dev/null
+++ b/tests/run-make/libtest-json/Makefile
@@ -0,0 +1,18 @@
+include ../tools.mk
+
+# Test expected libtest's JSON output
+
+OUTPUT_FILE_DEFAULT := $(TMPDIR)/libtest-json-output-default.json
+OUTPUT_FILE_STDOUT_SUCCESS := $(TMPDIR)/libtest-json-output-stdout-success.json
+
+all: f.rs validate_json.py output-default.json output-stdout-success.json
+	$(RUSTC) --test f.rs
+	RUST_BACKTRACE=0 $(call RUN,f) -Z unstable-options --test-threads=1 --format=json > $(OUTPUT_FILE_DEFAULT) || true
+	RUST_BACKTRACE=0 $(call RUN,f) -Z unstable-options --test-threads=1 --format=json --show-output > $(OUTPUT_FILE_STDOUT_SUCCESS) || true
+
+	cat $(OUTPUT_FILE_DEFAULT) | "$(PYTHON)" validate_json.py
+	cat $(OUTPUT_FILE_STDOUT_SUCCESS) | "$(PYTHON)" validate_json.py
+
+	# Normalize the actual output and compare to expected output file
+	cat $(OUTPUT_FILE_DEFAULT) | sed 's/"exec_time": [0-9.]*/"exec_time": $$TIME/' | diff output-default.json -
+	cat $(OUTPUT_FILE_STDOUT_SUCCESS) | sed 's/"exec_time": [0-9.]*/"exec_time": $$TIME/' | diff output-stdout-success.json -
diff --git a/tests/run-make/libtest-json/f.rs b/tests/run-make/libtest-json/f.rs
new file mode 100644
index 00000000000..edfe25086ae
--- /dev/null
+++ b/tests/run-make/libtest-json/f.rs
@@ -0,0 +1,22 @@
+#[test]
+fn a() {
+    println!("print from successful test");
+    // Should pass
+}
+
+#[test]
+fn b() {
+    assert!(false);
+}
+
+#[test]
+#[should_panic]
+fn c() {
+    assert!(false);
+}
+
+#[test]
+#[ignore = "msg"]
+fn d() {
+    assert!(false);
+}
diff --git a/tests/run-make/libtest-json/output-default.json b/tests/run-make/libtest-json/output-default.json
new file mode 100644
index 00000000000..ad22b66eda6
--- /dev/null
+++ b/tests/run-make/libtest-json/output-default.json
@@ -0,0 +1,10 @@
+{ "type": "suite", "event": "started", "test_count": 4 }
+{ "type": "test", "event": "started", "name": "a" }
+{ "type": "test", "name": "a", "event": "ok" }
+{ "type": "test", "event": "started", "name": "b" }
+{ "type": "test", "name": "b", "event": "failed", "stdout": "thread 'b' panicked at 'assertion failed: false', f.rs:9:5\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n" }
+{ "type": "test", "event": "started", "name": "c" }
+{ "type": "test", "name": "c", "event": "ok" }
+{ "type": "test", "event": "started", "name": "d" }
+{ "type": "test", "name": "d", "event": "ignored", "message": "msg" }
+{ "type": "suite", "event": "failed", "passed": 2, "failed": 1, "ignored": 1, "measured": 0, "filtered_out": 0, "exec_time": $TIME }
diff --git a/tests/run-make/libtest-json/output-stdout-success.json b/tests/run-make/libtest-json/output-stdout-success.json
new file mode 100644
index 00000000000..ec98172eb1c
--- /dev/null
+++ b/tests/run-make/libtest-json/output-stdout-success.json
@@ -0,0 +1,10 @@
+{ "type": "suite", "event": "started", "test_count": 4 }
+{ "type": "test", "event": "started", "name": "a" }
+{ "type": "test", "name": "a", "event": "ok", "stdout": "print from successful test\n" }
+{ "type": "test", "event": "started", "name": "b" }
+{ "type": "test", "name": "b", "event": "failed", "stdout": "thread 'b' panicked at 'assertion failed: false', f.rs:9:5\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n" }
+{ "type": "test", "event": "started", "name": "c" }
+{ "type": "test", "name": "c", "event": "ok", "stdout": "thread 'c' panicked at 'assertion failed: false', f.rs:15:5\n" }
+{ "type": "test", "event": "started", "name": "d" }
+{ "type": "test", "name": "d", "event": "ignored", "message": "msg" }
+{ "type": "suite", "event": "failed", "passed": 2, "failed": 1, "ignored": 1, "measured": 0, "filtered_out": 0, "exec_time": $TIME }
diff --git a/tests/run-make/libtest-json/validate_json.py b/tests/run-make/libtest-json/validate_json.py
new file mode 100755
index 00000000000..657f732f2bf
--- /dev/null
+++ b/tests/run-make/libtest-json/validate_json.py
@@ -0,0 +1,8 @@
+#!/usr/bin/env python
+
+import sys
+import json
+
+# Try to decode line in order to ensure it is a valid JSON document
+for line in sys.stdin:
+    json.loads(line)