Skip to content

Commit adddb0f

Browse files
author
Gilad Naaman
committed
libtest: Added UI tests for --format=json
libtest: Remove usage of jq libtest: Fixed UI tests - Now comparing to the right file. - A python script checks for validity of JSON documents
1 parent 8b3fd98 commit adddb0f

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-include ../tools.mk
2+
3+
# Test expected libtest's JSON output
4+
5+
OUTPUT_FILE := $(TMPDIR)/libtest-json-output.json
6+
7+
all:
8+
$(RUSTC) --test f.rs
9+
$(call RUN,f) -Z unstable-options --test-threads=1 --format=json > $(OUTPUT_FILE) || true
10+
11+
cat $(OUTPUT_FILE) | $(PYTHON) validate_json.py
12+
13+
# Compare to output file
14+
diff output.json $(OUTPUT_FILE)

src/test/run-make/libtest-json/f.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[test]
12+
fn a() {
13+
// Should pass
14+
}
15+
16+
#[test]
17+
fn b() {
18+
assert!(false)
19+
}
20+
21+
#[test]
22+
#[should_panic]
23+
fn c() {
24+
assert!(false);
25+
}
26+
27+
#[test]
28+
#[ignore]
29+
fn d() {
30+
assert!(false);
31+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{ "type": "suite", "event": "started", "test_count": "4" }
2+
{ "type": "test", "event": "started", "name": "a" }
3+
{ "type": "test", "name": "a", "event": "ok" }
4+
{ "type": "test", "event": "started", "name": "b" }
5+
{ "type": "test", "name": "b", "event": "failed", "stdout": "thread 'b' panicked at 'assertion failed: false', f.rs:18:4\nnote: Run with `RUST_BACKTRACE=1` for a backtrace.\n" }
6+
{ "type": "test", "event": "started", "name": "c" }
7+
{ "type": "test", "name": "c", "event": "ok" }
8+
{ "type": "test", "event": "started", "name": "d" }
9+
{ "type": "test", "name": "d", "event": "ignored" }
10+
{ "type": "suite", "event": "failed", "passed": 2, "failed": 1, "allowed_fail": 0, "ignored": 1, "measured": 0, "filtered_out": "0" }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import json
5+
6+
# Try to decode line in order to ensure it is a valid JSON document
7+
for line in sys.stdin:
8+
json.loads(line)

0 commit comments

Comments
 (0)