]> git.lizzy.rs Git - rust.git/commitdiff
Shuffle around check-lexer conditions
authorCorey Richardson <corey@octayn.net>
Mon, 21 Jul 2014 20:04:35 +0000 (13:04 -0700)
committerCorey Richardson <corey@octayn.net>
Tue, 22 Jul 2014 01:38:40 +0000 (18:38 -0700)
Makefile.in
mk/grammar.mk
mk/tests.mk
src/grammar/check.sh
src/grammar/verify.rs

index 2612761cef951b201f9e3e6d070c1e25476fb742..5683eb7ba06af964def14409de5347f4872ffe3c 100644 (file)
@@ -216,6 +216,7 @@ ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
                $(findstring tidy,$(MAKECMDGOALS))),)
   CFG_INFO := $(info cfg: including test rules)
   include $(CFG_SRC_DIR)mk/tests.mk
+  include $(CFG_SRC_DIR)mk/grammar.mk
 endif
 
 # Performance and benchmarking
@@ -252,19 +253,6 @@ ifneq ($(findstring clean,$(MAKECMDGOALS)),)
   include $(CFG_SRC_DIR)mk/clean.mk
 endif
 
-# Grammar tests
-
-ifneq ($(findstring lexer,$(MAKECMDGOALS)),)
-  ifdef CFG_JAVAC
-       ifdef CFG_ANTLR4
-         ifdef CFG_GRUN
-           CFG_INFO := $(info cfg: including grammar tests)
-           include $(CFG_SRC_DIR)mk/grammar.mk
-         endif
-       endif
-  endif
-endif
-
 # CTAGS building
 ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
                $(findstring TAGS.vi,$(MAKECMDGOALS))),)
index 03e253c7278cc0bbd024e28ad18c67e4518b2aeb..c0afa3eb769461853346cc7b031c4fa4b2c7d59b 100644 (file)
@@ -38,6 +38,18 @@ $(BG)verify: $(SG)verify.rs rustc-stage2-H-$(CFG_BUILD) $(LD)stamp.regex_macros
        $(Q)$(RUSTC) -O --out-dir $(BG) -L $(L) $(SG)verify.rs
 
 check-lexer: $(BG) $(BG)RustLexer.class $(BG)verify
+ifdef CFG_JAVAC
+ifdef CFG_ANTLR4
+ifdef CFG_GRUN
        $(info Verifying libsyntax against the reference lexer ...)
-       $(Q)find $(S) -iname '*.rs' -exec "$(SG)check.sh" {} "$(BG)" \
-      "$(CFG_GRUN)" "$(BG)verify" "$(BG)RustLexer.tokens" "$(VERBOSE)" \;
+       $(Q)$(SG)check.sh $(S) "$(BG)" \
+               "$(CFG_GRUN)" "$(BG)verify" "$(BG)RustLexer.tokens"
+else
+$(info grun not available, skipping lexer test...)
+endif
+else
+$(info antlr4 not available, skipping lexer test...)
+endif
+else
+$(info javac not available, skipping lexer test...)
+endif
index d2e4388521ecd7730a30f169d2795994ebe219a2..6068af8f7f463cd5343a7f46ee9b4e8f054d0730 100644 (file)
@@ -171,7 +171,7 @@ endif
 # Main test targets
 ######################################################################
 
-check: cleantmptestlogs cleantestlibs check-notidy tidy
+check: cleantmptestlogs cleantestlibs check-notidy tidy check-syntax
 
 check-notidy: cleantmptestlogs cleantestlibs all check-stage2
        $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
@@ -192,6 +192,8 @@ check-docs: cleantestlibs cleantmptestlogs check-stage2-docs
 # NOTE: Remove after reprogramming windows bots
 check-fast: check-lite
 
+check-syntax: check-lexer
+
 .PHONY: cleantmptestlogs cleantestlibs
 
 cleantmptestlogs:
index 3ddbb8a34c81258b5e31c9a2c3414e2c77510657..69ec490a08a3fa258b7a271ec23d39770b72b157 100755 (executable)
@@ -2,20 +2,33 @@
 
 # Run the reference lexer against libsyntax and compare the tokens and spans.
 # If "// ignore-lexer-test" is present in the file, it will be ignored.
-#
+
+
 # Argument $1 is the file to check, $2 is the classpath to use, $3 is the path
 # to the grun binary, $4 is the path to the verify binary, $5 is the path to
 # RustLexer.tokens
-
 if [ "${VERBOSE}" == "1" ]; then
     set -x
 fi
 
-grep -q "// ignore lexer-test" $1;
+check() {
+    grep --silent "// ignore-lexer-test" $1;
 
-if [ $? -eq 1 ]; then
-    cd $2 # This `cd` is so java will pick up RustLexer.class. I couldn't
-    # figure out how to wrangle the CLASSPATH, just adding build/grammr didn't
-    # seem to have anny effect.
-    $3 RustLexer tokens -tokens < $1 | $4 $1 $5
-fi
+    # if it's *not* found...
+    if [ $? -eq 1 ]; then
+        cd $2 # This `cd` is so java will pick up RustLexer.class. I couldn't
+        # figure out how to wrangle the CLASSPATH, just adding build/grammr didn't
+        # seem to have anny effect.
+        if $3 RustLexer tokens -tokens < $1 | $4 $1 $5; then
+            echo "pass: $1"
+        else
+            echo "fail: $1"
+        fi
+    else
+        echo "skip: $1"
+    fi
+}
+
+for file in $(find $1 -iname '*.rs' ! -path '*/test/compile-fail/*' ); do
+    check $file $2 $3 $4 $5
+done
index a6a1a75854d580300b8d2e2bb04fdbccc22f3abd..f2ae5a1ea4e518739a9c74ff5fbde65b4424d71e 100644 (file)
@@ -1,3 +1,13 @@
+// Copyright 2014 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.
+
 #![feature(globs, phase, macro_rules)]
 
 extern crate syntax;
@@ -158,7 +168,9 @@ fn count(lit: &str) -> uint {
 }
 
 fn parse_antlr_token(s: &str, tokens: &HashMap<String, Token>) -> TokenAndSpan {
-    let re = regex!(r"\[@(?P<seq>\d+),(?P<start>\d+):(?P<end>\d+)='(?P<content>.+?)',<(?P<toknum>-?\d+)>,\d+:\d+]");
+    let re = regex!(
+      r"\[@(?P<seq>\d+),(?P<start>\d+):(?P<end>\d+)='(?P<content>.+?)',<(?P<toknum>-?\d+)>,\d+:\d+]"
+    );
 
     let m = re.captures(s).expect(format!("The regex didn't match {}", s).as_slice());
     let start = m.name("start");
@@ -166,7 +178,8 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, Token>) -> TokenAndSpan {
     let toknum = m.name("toknum");
     let content = m.name("content");
 
-    let proto_tok = tokens.find_equiv(&toknum).expect(format!("didn't find token {} in the map", toknum).as_slice());
+    let proto_tok = tokens.find_equiv(&toknum).expect(format!("didn't find token {} in the map",
+                                                              toknum).as_slice());
 
     let nm = parse::token::intern(content);
 
@@ -229,7 +242,8 @@ fn next(r: &mut lexer::StringReader) -> TokenAndSpan {
     let token_map = parse_token_list(token_file.read_to_string().unwrap().as_slice());
 
     let mut stdin = std::io::stdin();
-    let mut antlr_tokens = stdin.lines().map(|l| parse_antlr_token(l.unwrap().as_slice().trim(), &token_map));
+    let mut antlr_tokens = stdin.lines().map(|l| parse_antlr_token(l.unwrap().as_slice().trim(),
+                                                                   &token_map));
 
     let code = File::open(&Path::new(args.get(1).as_slice())).unwrap().read_to_string().unwrap();
     let options = config::basic_options();
@@ -246,7 +260,8 @@ fn next(r: &mut lexer::StringReader) -> TokenAndSpan {
             continue
         }
 
-        assert!(rustc_tok.sp == antlr_tok.sp, "{} and {} have different spans", rustc_tok, antlr_tok);
+        assert!(rustc_tok.sp == antlr_tok.sp, "{} and {} have different spans", rustc_tok,
+                antlr_tok);
 
         macro_rules! matches (
             ( $($x:pat),+ ) => (