Add feature flags to test files.

Cranelift can be compiled with feature flags which can change its output. To
accomodate changes of output related to feature flags, test file can now include
`feature "..."` and `feature ! "..."` directives in the preamble of the test
file.

The test runner would skip the test if the flag does not match the expectation
of the test case.
This commit is contained in:
Nicolas B. Pierron
2019-08-27 14:25:21 +02:00
committed by Nicolas B. Pierron
parent 26efc696c6
commit 04b10b3fde
7 changed files with 130 additions and 7 deletions

View File

@@ -27,6 +27,7 @@ pub enum Token<'a> {
Dot, // '.'
Colon, // ':'
Equal, // '='
Not, // '!'
Arrow, // '->'
Float(&'a str), // Floating point immediate
Integer(&'a str), // Integer immediate
@@ -42,6 +43,7 @@ pub enum Token<'a> {
SigRef(u32), // sig2
UserRef(u32), // u345
Name(&'a str), // %9arbitrary_alphanum, %x3, %0, %function ...
String(&'a str), // "abritrary quoted string with no escape" ...
HexSequence(&'a str), // #89AF
Identifier(&'a str), // Unrecognized identifier (opcode, enumerator, ...)
SourceLoc(&'a str), // @00c7
@@ -401,6 +403,27 @@ impl<'a> Lexer<'a> {
token(Token::Name(&self.source[begin..end]), loc)
}
/// Scan for a multi-line quoted string with no escape character.
fn scan_string(&mut self) -> Result<LocatedToken<'a>, LocatedError> {
let loc = self.loc();
let begin = self.pos + 1;
assert_eq!(self.lookahead, Some('"'));
while let Some(c) = self.next_ch() {
if c == '"' {
break;
}
}
let end = self.pos;
if self.lookahead != Some('"') {
return error(LexError::InvalidChar, self.loc());
}
self.next_ch();
token(Token::String(&self.source[begin..end]), loc)
}
fn scan_hex_sequence(&mut self) -> Result<LocatedToken<'a>, LocatedError> {
let loc = self.loc();
let begin = self.pos + 1;
@@ -452,6 +475,7 @@ impl<'a> Lexer<'a> {
Some('.') => Some(self.scan_char(Token::Dot)),
Some(':') => Some(self.scan_char(Token::Colon)),
Some('=') => Some(self.scan_char(Token::Equal)),
Some('!') => Some(self.scan_char(Token::Not)),
Some('+') => Some(self.scan_number()),
Some('-') => {
if self.looking_at("->") {
@@ -463,6 +487,7 @@ impl<'a> Lexer<'a> {
Some(ch) if ch.is_digit(10) => Some(self.scan_number()),
Some(ch) if ch.is_alphabetic() => Some(self.scan_word()),
Some('%') => Some(self.scan_name()),
Some('"') => Some(self.scan_string()),
Some('#') => Some(self.scan_hex_sequence()),
Some('@') => Some(self.scan_srcloc()),
Some(ch) if ch.is_whitespace() => {
@@ -633,6 +658,33 @@ mod tests {
assert_eq!(lex.next(), token(Token::Name("_"), 1));
}
#[test]
fn lex_strings() {
let mut lex = Lexer::new(
r#""" "0" "x3""function" "123 abc" "\" "start
and end on
different lines" "#,
);
assert_eq!(lex.next(), token(Token::String(""), 1));
assert_eq!(lex.next(), token(Token::String("0"), 1));
assert_eq!(lex.next(), token(Token::String("x3"), 1));
assert_eq!(lex.next(), token(Token::String("function"), 1));
assert_eq!(lex.next(), token(Token::String("123 abc"), 1));
assert_eq!(lex.next(), token(Token::String(r#"\"#), 1));
assert_eq!(
lex.next(),
token(
Token::String(
r#"start
and end on
different lines"#
),
1
)
);
}
#[test]
fn lex_userrefs() {
let mut lex = Lexer::new("u0 u1 u234567890 u9:8765");