From 8c86f8ff8c7cbbf0e87f0c7fe22e5596a4778bfc Mon Sep 17 00:00:00 2001
From: petrochenkov <vadim.petrochenkov@gmail.com>
Date: Sat, 30 May 2015 19:22:12 +0300
Subject: [PATCH 1/2] Warn if the test suite is run on Windows in console with
 non-UTF-8 code page

---
 mk/tests.mk                  | 11 ++++++-----
 src/etc/check-sanitycheck.py |  7 +++++++
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/mk/tests.mk b/mk/tests.mk
index 44c661c4e20..fa35bd383b2 100644
--- a/mk/tests.mk
+++ b/mk/tests.mk
@@ -172,23 +172,24 @@ check: check-sanitycheck cleantmptestlogs cleantestlibs all check-stage2 tidy
 	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
 
 # As above but don't bother running tidy.
-check-notidy: cleantmptestlogs cleantestlibs all check-stage2
+check-notidy: check-sanitycheck cleantmptestlogs cleantestlibs all check-stage2
 	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
 
 # A slightly smaller set of tests for smoke testing.
-check-lite: cleantestlibs cleantmptestlogs \
+check-lite: check-sanitycheck cleantestlibs cleantmptestlogs \
 	$(foreach crate,$(TEST_TARGET_CRATES),check-stage2-$(crate)) \
 	check-stage2-rpass check-stage2-rpass-valgrind \
 	check-stage2-rfail check-stage2-cfail check-stage2-pfail check-stage2-rmake
 	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
 
 # Only check the 'reference' tests: rpass/cfail/rfail/rmake.
-check-ref: cleantestlibs cleantmptestlogs check-stage2-rpass check-stage2-rpass-valgrind \
-	check-stage2-rfail check-stage2-cfail check-stage2-pfail check-stage2-rmake
+check-ref: check-sanitycheck cleantestlibs cleantmptestlogs check-stage2-rpass \
+	check-stage2-rpass-valgrind check-stage2-rfail check-stage2-cfail check-stage2-pfail \
+	check-stage2-rmake
 	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
 
 # Only check the docs.
-check-docs: cleantestlibs cleantmptestlogs check-stage2-docs
+check-docs: check-sanitycheck cleantestlibs cleantmptestlogs check-stage2-docs
 	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
 
 # Some less critical tests that are not prone to breakage.
diff --git a/src/etc/check-sanitycheck.py b/src/etc/check-sanitycheck.py
index fc8ed7b383e..b3dc290e36b 100644
--- a/src/etc/check-sanitycheck.py
+++ b/src/etc/check-sanitycheck.py
@@ -11,6 +11,7 @@
 # except according to those terms.
 
 import os
+import subprocess
 import sys
 import functools
 
@@ -45,8 +46,14 @@ will segfault many rustc's, creating many potentially large core files.
 set ALLOW_NONZERO_RLIMIT_CORE to ignore this warning
 """ % (soft))
 
+@only_on(('windows'))
+def check_console_code_page():
+    if "65001" not in subprocess.check_output(['cmd', '/c', 'chcp']):
+        sys.stderr.write('Warning: the console output code page is not UTF-8, \
+some tests may fail. Use `cmd /c "chcp 65001"` to setup UTF-8 code page.\n')
 
 def main():
+    check_console_code_page()
     check_rlimit_core()
 
 if __name__ == '__main__':

From a40bca29a818b4cbea072a295cb80aa9a4c43d52 Mon Sep 17 00:00:00 2001
From: petrochenkov <vadim.petrochenkov@gmail.com>
Date: Mon, 1 Jun 2015 20:50:35 +0300
Subject: [PATCH 2/2] Fix platform detection

---
 src/etc/check-sanitycheck.py | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/etc/check-sanitycheck.py b/src/etc/check-sanitycheck.py
index b3dc290e36b..0e103fbcffb 100644
--- a/src/etc/check-sanitycheck.py
+++ b/src/etc/check-sanitycheck.py
@@ -17,14 +17,12 @@ import functools
 
 STATUS = 0
 
-
 def error_unless_permitted(env_var, message):
     global STATUS
     if not os.getenv(env_var):
         sys.stderr.write(message)
         STATUS = 1
 
-
 def only_on(platforms):
     def decorator(func):
         @functools.wraps(func)
@@ -34,8 +32,7 @@ def only_on(platforms):
         return inner
     return decorator
 
-
-@only_on(('linux', 'darwin', 'freebsd', 'openbsd'))
+@only_on(['linux', 'darwin', 'freebsd', 'openbsd'])
 def check_rlimit_core():
     import resource
     soft, hard = resource.getrlimit(resource.RLIMIT_CORE)
@@ -46,9 +43,9 @@ will segfault many rustc's, creating many potentially large core files.
 set ALLOW_NONZERO_RLIMIT_CORE to ignore this warning
 """ % (soft))
 
-@only_on(('windows'))
+@only_on(['win32'])
 def check_console_code_page():
-    if "65001" not in subprocess.check_output(['cmd', '/c', 'chcp']):
+    if '65001' not in subprocess.check_output(['cmd', '/c', 'chcp']):
         sys.stderr.write('Warning: the console output code page is not UTF-8, \
 some tests may fail. Use `cmd /c "chcp 65001"` to setup UTF-8 code page.\n')