Skip to content

Commit

Permalink
Unrot and re-enable parse-fail/qquote-{1,2}.rs
Browse files Browse the repository at this point in the history
FIXME: qquote-2.rs fails at runtime, rather than parse time, which is
bad.
  • Loading branch information
tamird committed Apr 23, 2015
1 parent e5afca4 commit d51df3d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 71 deletions.
67 changes: 29 additions & 38 deletions src/test/parse-fail/qquote-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,52 @@

// compile-flags: -Z parse-only

// ignore-test Can't use syntax crate here
// ignore-cross-compile

#![feature(quote)]
#![feature(quote, rustc_private)]

extern crate syntax;

use io::*;

use syntax::diagnostic;
use syntax::ast;
use syntax::codemap;
use syntax::parse::token;
use syntax::parse;
use syntax::print::*;


trait fake_ext_ctxt {
fn cfg() -> ast::CrateConfig;
fn parse_sess() -> parse::parse_sess;
fn call_site() -> span;
fn ident_of(st: &str) -> ast::ident;
use syntax::print::pprust;

trait FakeExtCtxt {
fn call_site(&self) -> codemap::Span;
fn cfg(&self) -> ast::CrateConfig;
fn ident_of(&self, st: &str) -> ast::Ident;
fn name_of(&self, st: &str) -> ast::Name;
fn parse_sess(&self) -> &parse::ParseSess;
}

type fake_session = parse::parse_sess;

impl fake_ext_ctxt for fake_session {
fn cfg() -> ast::CrateConfig { Vec::new() }
fn parse_sess() -> parse::parse_sess { self }
fn call_site() -> span {
codemap::span {
impl FakeExtCtxt for parse::ParseSess {
fn call_site(&self) -> codemap::Span {
codemap::Span {
lo: codemap::BytePos(0),
hi: codemap::BytePos(0),
expn_id: NO_EXPANSION
expn_id: codemap::NO_EXPANSION,
}
}
fn ident_of(st: &str) -> ast::ident {
self.interner.intern(st)
fn cfg(&self) -> ast::CrateConfig { Vec::new() }
fn ident_of(&self, st: &str) -> ast::Ident {
token::str_to_ident(st)
}
fn name_of(&self, st: &str) -> ast::Name {
token::intern(st)
}
fn parse_sess(&self) -> &parse::ParseSess { self }
}

fn mk_ctxt() -> fake_ext_ctxt {
parse::new_parse_sess(None) as fake_ext_ctxt
}



fn main() {
let cx = mk_ctxt();
let cx = parse::new_parse_sess();

let abc = quote_expr!(cx, 23);
check_pp(abc, pprust::print_expr, "23");

let expr3 = quote_expr!(cx, 2 - $abcd + 7); //~ ERROR unresolved name: abcd
check_pp(expr3, pprust::print_expr, "2 - 23 + 7");
}
quote_expr!(&cx, 23).and_then(|expr| {
assert_eq!(pprust::expr_to_string(&expr), "23")
});

fn check_pp<T>(expr: T, f: |pprust::ps, T|, expect: str) {
panic!();
quote_expr!(&cx, 2 - $abcd + 7).and_then(|expr| { //~ ERROR unresolved name: abcd
assert_eq!(pprust::expr_to_string(&expr), "2 - $abcd + 7")
});
}
60 changes: 27 additions & 33 deletions src/test/parse-fail/qquote-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,48 @@

// compile-flags: -Z parse-only

// ignore-test Can't use syntax crate here
// ignore-cross-compile

#![feature(quote)]
#![feature(quote, rustc_private)]

extern crate syntax;

use syntax::diagnostic;
use syntax::ast;
use syntax::codemap;
use syntax::parse::parser;
use syntax::print::*;

trait fake_ext_ctxt {
fn cfg() -> ast::CrateConfig;
fn parse_sess() -> parse::parse_sess;
fn call_site() -> span;
fn ident_of(st: &str) -> ast::ident;
use syntax::parse::token;
use syntax::parse;
use syntax::print::pprust;

trait FakeExtCtxt {
fn call_site(&self) -> codemap::Span;
fn cfg(&self) -> ast::CrateConfig;
fn ident_of(&self, st: &str) -> ast::Ident;
fn name_of(&self, st: &str) -> ast::Name;
fn parse_sess(&self) -> &parse::ParseSess;
}

type fake_session = parse::parse_sess;

impl fake_ext_ctxt for fake_session {
fn cfg() -> ast::CrateConfig { Vec::new() }
fn parse_sess() -> parse::parse_sess { self }
fn call_site() -> span {
codemap::span {
impl FakeExtCtxt for parse::ParseSess {
fn call_site(&self) -> codemap::Span {
codemap::Span {
lo: codemap::BytePos(0),
hi: codemap::BytePos(0),
expn_id: codemap::NO_EXPANSION
expn_id: codemap::NO_EXPANSION,
}
}
fn ident_of(st: &str) -> ast::ident {
self.interner.intern(st)
fn cfg(&self) -> ast::CrateConfig { Vec::new() }
fn ident_of(&self, st: &str) -> ast::Ident {
token::str_to_ident(st)
}
fn name_of(&self, st: &str) -> ast::Name {
token::intern(st)
}
fn parse_sess(&self) -> &parse::ParseSess { self }
}

fn mk_ctxt() -> fake_ext_ctxt {
parse::new_parse_sess(None) as fake_ext_ctxt
}


fn main() {
let cx = mk_ctxt();

let stmt = quote_stmt!(cx, let x isize = 20;); //~ ERROR expected end-of-string
check_pp(*stmt, pprust::print_stmt, "");
}
let cx = parse::new_parse_sess();

fn check_pp<T>(expr: T, f: |pprust::ps, T|, expect: str) {
panic!();
quote_expr!(&cx, let x isize = 20;).and_then(|expr| { //~ ERROR expected end-of-string
assert_eq!(pprust::expr_to_string(&expr), "let x isize = 20;")
});
}

0 comments on commit d51df3d

Please sign in to comment.