File: ui.rs

package info (click to toggle)
rust-garde 0.22.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 940 kB
  • sloc: makefile: 2
file content (38 lines) | stat: -rw-r--r-- 1,116 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std::path::{Path, PathBuf};

use glob::glob;

const COMPILE_FAIL_TESTS: &str =
    concat!(env!("CARGO_MANIFEST_DIR"), "/tests/ui/compile-fail/**/*.rs");
const COMPILE_PASS_TESTS: &str =
    concat!(env!("CARGO_MANIFEST_DIR"), "/tests/ui/compile-pass/**/*.rs");

fn matches(path: &Path, pat: &[String]) -> bool {
    pat.iter()
        .any(|pat| path.as_os_str().to_string_lossy().contains(pat))
}

fn get_filter() -> Vec<String> {
    std::env::var("EXCLUDE_UI_TESTS")
        .unwrap_or_default()
        .split(',')
        .map(|v| v.trim())
        .filter(|v| !v.is_empty())
        .map(String::from)
        .collect::<Vec<_>>()
}

fn get_tests<'a>(path_pattern: &str, filter: &'a [String]) -> impl Iterator<Item = PathBuf> + 'a {
    glob(path_pattern)
        .unwrap()
        .map(Result::unwrap)
        .filter(move |path| !matches(path, filter))
}

#[test]
fn ui() {
    let filter = get_filter();
    let t = trybuild::TestCases::new();
    get_tests(COMPILE_FAIL_TESTS, &filter).for_each(|test| t.compile_fail(test));
    get_tests(COMPILE_PASS_TESTS, &filter).for_each(|test| t.pass(test));
}