Merge pull request #3 from dtolnay/ui

Add ui tests
This commit is contained in:
Bodil Stokke 2018-11-19 16:48:31 +00:00 committed by GitHub
commit 445a3af904
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 204 additions and 1 deletions

View File

@ -3,5 +3,6 @@ members = [
"typed-html",
"macros",
"examples/wasm",
"examples/rocket"
"examples/rocket",
"ui",
]

14
ui/Cargo.toml Normal file
View File

@ -0,0 +1,14 @@
[package]
name = "typed-html-tests"
version = "0.0.0"
authors = ["Bodil Stokke <bodil@bodil.org>"]
publish = false
[[bin]]
name = "typed-html-tests"
path = "main.rs"
[dev-dependencies]
compiletest_rs = { version = "0.3", features = ["stable"] }
typed-html = { path = "../typed-html" }
typed-html-macros = { path = "../macros" }

View File

@ -0,0 +1,12 @@
#![feature(proc_macro_hygiene)]
extern crate typed_html;
use typed_html::html;
use typed_html::dom::DOMTree;
fn main() {
let _: DOMTree<String> = html!{
<@>
};
}

View File

@ -0,0 +1,8 @@
error: expected identifier
--> $DIR/expected-token.rs:10:10
|
10 | <@>
| ^
error: aborting due to previous error

View File

@ -0,0 +1,14 @@
#![feature(proc_macro_hygiene)]
extern crate typed_html;
use typed_html::html;
use typed_html::dom::DOMTree;
fn main() {
let _: DOMTree<String> = html!{
<html>
<head></head>
</html>
};
}

View File

@ -0,0 +1,21 @@
error: <html> requires 2 children but there are only 1
--> $DIR/not-enough-children.rs:10:10
|
10 | <html>
| ^^^^
error: proc macro panicked
--> $DIR/not-enough-children.rs:9:30
|
9 | let _: DOMTree<String> = html!{
| ______________________________^
10 | | <html>
11 | | <head></head>
12 | | </html>
13 | | };
| |_____^
|
= help: message: explicit panic
error: aborting due to 2 previous errors

12
ui/cases/tag-mismatch.rs Normal file
View File

@ -0,0 +1,12 @@
#![feature(proc_macro_hygiene)]
extern crate typed_html;
use typed_html::html;
use typed_html::dom::DOMTree;
fn main() {
let _: DOMTree<String> = html!{
<html></head>
};
}

View File

@ -0,0 +1,14 @@
error: expected closing tag '</html>', found '</head>'
--> $DIR/tag-mismatch.rs:10:17
|
10 | <html></head>
| ^^^^
|
help: opening tag is here:
--> $DIR/tag-mismatch.rs:10:10
|
10 | <html></head>
| ^^^^
error: aborting due to previous error

View File

@ -0,0 +1,12 @@
#![feature(proc_macro_hygiene)]
extern crate typed_html;
use typed_html::html;
use typed_html::dom::DOMTree;
fn main() {
let _: DOMTree<String> = html!{
<title>unquoted</title>
};
}

View File

@ -0,0 +1,10 @@
error: expected "<", code block or literal
--> $DIR/text-nodes-need-to-be-quoted.rs:10:16
|
10 | <title>unquoted</title>
| ^^^^^^^^
|
= help: text nodes need to be quoted, eg. <p>"Hello Joe!"</p>
error: aborting due to previous error

View File

@ -0,0 +1,12 @@
#![feature(proc_macro_hygiene)]
extern crate typed_html;
use typed_html::html;
use typed_html::dom::DOMTree;
fn main() {
let _: DOMTree<String> = html!{
<title>
};
}

View File

@ -0,0 +1,10 @@
error: unexpected end of macro
--> $DIR/unexpected-end-of-macro.rs:10:9
|
10 | <title>
| ^^^^^^^
|
= help: missing "<", code block or literal
error: aborting due to previous error

48
ui/cases/update-references.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
#
# Copyright 2015 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
# A script to update the references for particular tests. The idea is
# that you do a run, which will generate files in the build directory
# containing the (normalized) actual output of the compiler. This
# script will then copy that output and replace the "expected output"
# files. You can then commit the changes.
#
# If you find yourself manually editing a foo.stderr file, you're
# doing it wrong.
if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "" || "$2" == "" ]]; then
echo "usage: $0 <build-directory> <relative-path-to-rs-files>"
echo ""
echo "For example:"
echo " $0 ../../../build/x86_64-apple-darwin/test/ui *.rs */*.rs"
fi
MYDIR=$(dirname $0)
BUILD_DIR="$1"
shift
while [[ "$1" != "" ]]; do
STDERR_NAME="${1/%.rs/.stderr}"
STDOUT_NAME="${1/%.rs/.stdout}"
shift
if [ -f $BUILD_DIR/$STDOUT_NAME ] && \
! (diff $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME >& /dev/null); then
echo updating $MYDIR/$STDOUT_NAME
cp $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME
fi
if [ -f $BUILD_DIR/$STDERR_NAME ] && \
! (diff $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME >& /dev/null); then
echo updating $MYDIR/$STDERR_NAME
cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME
fi
done

15
ui/main.rs Normal file
View File

@ -0,0 +1,15 @@
#[test]
fn ui() {
extern crate compiletest_rs as compiletest;
let mut config = compiletest::Config {
mode: compiletest::common::Mode::Ui,
src_base: std::path::PathBuf::from("cases"),
..Default::default()
};
config.link_deps();
config.clean_rmeta();
compiletest::run_tests(&config);
}