aboutsummaryrefslogtreecommitdiffstats
path: root/python/tidy/servo_tidy_tests
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-04-15 23:20:16 +0530
committerbors-servo <lbergstrom+bors@mozilla.com>2016-04-15 23:20:16 +0530
commitbfe54539d290cb287e59e8ba106a54a3fab6201a (patch)
treee1f8e2ebac52bd4a1f234c4452bebf9e379344b0 /python/tidy/servo_tidy_tests
parenta96b98f85b2e4dce88a48c844d251546ada8afdf (diff)
parentee433a030c306990f14a0dbbf91f1d4bf5e3003c (diff)
downloadservo-bfe54539d290cb287e59e8ba106a54a3fab6201a.tar.gz
servo-bfe54539d290cb287e59e8ba106a54a3fab6201a.zip
Auto merge of #10590 - edunham:package-tidy, r=larsbergstrom
Package tidy This fixes https://github.com/servo/servo/issues/861. @askeing, I've copied your work from https://github.com/askeing/servo_tidy and attributed the commit to you. My commit in this PR is Git housekeeping to preserve `tidy`'s history. If you'd like to make additional changes, I've given you and @shinglyu push access to my fork of Servo. Apologies if this is already familiar, but the workflow for pushing to my branch is: ``` $ git remote add edunham git@github.com:edunham/servo.git $ git checkout -b package-tidy $ git pull edunham package-tidy $ git push edunham package-tidy ``` Once this lands, I'll look at how to publish it to PyPI and automate that process. Please don't merge this yet; we still need to discuss how the change should work around https://github.com/servo/servo/blob/master/python/servo/testing_commands.py#L33 , as I've yet to figure out how to get the egg to actually expose its tests. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10590) <!-- Reviewable:end -->
Diffstat (limited to 'python/tidy/servo_tidy_tests')
-rw-r--r--python/tidy/servo_tidy_tests/__init__.py8
-rw-r--r--python/tidy/servo_tidy_tests/incorrect_license.rs1
-rw-r--r--python/tidy/servo_tidy_tests/long_line.rs5
-rw-r--r--python/tidy/servo_tidy_tests/rust_tidy.rs37
-rw-r--r--python/tidy/servo_tidy_tests/spec.webidl10
-rw-r--r--python/tidy/servo_tidy_tests/speclink.rs9
-rw-r--r--python/tidy/servo_tidy_tests/test.toml5
-rw-r--r--python/tidy/servo_tidy_tests/test_tidy.py75
-rw-r--r--python/tidy/servo_tidy_tests/tidy_self_test.py78
-rw-r--r--python/tidy/servo_tidy_tests/whatwg_link.rs6
-rw-r--r--python/tidy/servo_tidy_tests/wrong_space.rs7
11 files changed, 241 insertions, 0 deletions
diff --git a/python/tidy/servo_tidy_tests/__init__.py b/python/tidy/servo_tidy_tests/__init__.py
new file mode 100644
index 00000000000..6b6351ddd2b
--- /dev/null
+++ b/python/tidy/servo_tidy_tests/__init__.py
@@ -0,0 +1,8 @@
+# Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+# file at the top-level directory of this distribution.
+#
+# 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.
diff --git a/python/tidy/servo_tidy_tests/incorrect_license.rs b/python/tidy/servo_tidy_tests/incorrect_license.rs
new file mode 100644
index 00000000000..cf85f0e2623
--- /dev/null
+++ b/python/tidy/servo_tidy_tests/incorrect_license.rs
@@ -0,0 +1 @@
+/* Incorrect license here */
diff --git a/python/tidy/servo_tidy_tests/long_line.rs b/python/tidy/servo_tidy_tests/long_line.rs
new file mode 100644
index 00000000000..cdc0b2045bc
--- /dev/null
+++ b/python/tidy/servo_tidy_tests/long_line.rs
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+println!("really really loooooooooooooooooooooooooooooooooooooooooooong lineeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
diff --git a/python/tidy/servo_tidy_tests/rust_tidy.rs b/python/tidy/servo_tidy_tests/rust_tidy.rs
new file mode 100644
index 00000000000..680b527f679
--- /dev/null
+++ b/python/tidy/servo_tidy_tests/rust_tidy.rs
@@ -0,0 +1,37 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use app_units::Au;
+use azure::azure_hl::{AntialiasMode, Color,
+ColorPattern, CompositionOp};
+use euclid::size::Size2D;
+use azure::azure::AzIntSize;
+
+use std;
+
+mod paint_context;
+pub mod display_list;
+mod test::{
+};
+
+extern crate webrender_traits;
+extern crate style_traits;
+
+impl test {
+
+ fn test_fun(y:f32)->f32{
+ let x=5;
+ x = x-1;
+ x = x*x;
+ let z = match y {
+ 1 =>2,
+ 2 => 1,
+ };
+ let z = &Vec<T>;
+ }
+
+ fn test_fun2(y : &String, z : &Vec<f32>) -> f32 {
+ 1
+ }
+}
diff --git a/python/tidy/servo_tidy_tests/spec.webidl b/python/tidy/servo_tidy_tests/spec.webidl
new file mode 100644
index 00000000000..51993ea0d41
--- /dev/null
+++ b/python/tidy/servo_tidy_tests/spec.webidl
@@ -0,0 +1,10 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+interface Test {
+ [SameObject ]
+ readonly attribute Node root;
+};
diff --git a/python/tidy/servo_tidy_tests/speclink.rs b/python/tidy/servo_tidy_tests/speclink.rs
new file mode 100644
index 00000000000..6c27a70a7d0
--- /dev/null
+++ b/python/tidy/servo_tidy_tests/speclink.rs
@@ -0,0 +1,9 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+impl SpecLinkMethods for SpecLink {
+ fn Test(&self) -> f32 {
+ 0
+ }
+}
diff --git a/python/tidy/servo_tidy_tests/test.toml b/python/tidy/servo_tidy_tests/test.toml
new file mode 100644
index 00000000000..c979a5cbd34
--- /dev/null
+++ b/python/tidy/servo_tidy_tests/test.toml
@@ -0,0 +1,5 @@
+[package]
+name = "test"
+version = "*"
+authors = ["The Servo Project Developers"]
+publish = false
diff --git a/python/tidy/servo_tidy_tests/test_tidy.py b/python/tidy/servo_tidy_tests/test_tidy.py
new file mode 100644
index 00000000000..d0e19daafb1
--- /dev/null
+++ b/python/tidy/servo_tidy_tests/test_tidy.py
@@ -0,0 +1,75 @@
+# Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+# file at the top-level directory of this distribution.
+#
+# 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.
+
+import os
+import unittest
+from servo_tidy import tidy
+
+
+def iterFile(name):
+ path = 'servo_tidy_tests/' if os.path.exists('servo_tidy_tests/') else 'python/tidy/servo_tidy_tests/'
+ return iter([os.path.join(path, name)])
+
+
+class CheckTidiness(unittest.TestCase):
+ def test_spaces_correctnes(self):
+ errors = tidy.collect_errors_for_files(iterFile('wrong_space.rs'), [], [tidy.check_by_line])
+ self.assertEqual('trailing whitespace', errors.next()[2])
+ self.assertEqual('no newline at EOF', errors.next()[2])
+ self.assertEqual('tab on line', errors.next()[2])
+ self.assertEqual('CR on line', errors.next()[2])
+
+ def test_long_line(self):
+ errors = tidy.collect_errors_for_files(iterFile('long_line.rs'), [], [tidy.check_by_line])
+ self.assertEqual('Line is longer than 120 characters', errors.next()[2])
+
+ def test_whatwg_link(self):
+ errors = tidy.collect_errors_for_files(iterFile('whatwg_link.rs'), [], [tidy.check_by_line])
+ self.assertTrue('link to WHATWG may break in the future, use this format instead:' in errors.next()[2])
+ self.assertTrue('links to WHATWG single-page url, change to multi page:' in errors.next()[2])
+
+ def test_licence(self):
+ errors = tidy.collect_errors_for_files(iterFile('incorrect_license.rs'), [], [tidy.check_license])
+ self.assertEqual('incorrect license', errors.next()[2])
+
+ def test_rust(self):
+ errors = tidy.collect_errors_for_files(iterFile('rust_tidy.rs'), [], [tidy.check_rust])
+ self.assertEqual('use statement spans multiple lines', errors.next()[2])
+ self.assertEqual('missing space before }', errors.next()[2])
+ self.assertTrue('use statement is not in alphabetical order' in errors.next()[2])
+ self.assertEqual('encountered whitespace following a use statement', errors.next()[2])
+ self.assertTrue('mod declaration is not in alphabetical order' in errors.next()[2])
+ self.assertEqual('mod declaration spans multiple lines', errors.next()[2])
+ self.assertTrue('extern crate declaration is not in alphabetical order' in errors.next()[2])
+ self.assertEqual('missing space before ->', errors.next()[2])
+ self.assertEqual('missing space after ->', errors.next()[2])
+ self.assertEqual('missing space after :', errors.next()[2])
+ self.assertEqual('missing space before {', errors.next()[2])
+ self.assertEqual('missing space before =', errors.next()[2])
+ self.assertEqual('missing space after =', errors.next()[2])
+ self.assertEqual('missing space before -', errors.next()[2])
+ self.assertEqual('missing space before *', errors.next()[2])
+ self.assertEqual('missing space after =>', errors.next()[2])
+ self.assertEqual('extra space before :', errors.next()[2])
+ self.assertEqual('extra space before :', errors.next()[2])
+ self.assertEqual('use &[T] instead of &Vec<T>', errors.next()[2])
+ self.assertEqual('use &str instead of &String', errors.next()[2])
+
+ def test_webidl(self):
+ errors = tidy.collect_errors_for_files(iterFile('spec.webidl'), [tidy.check_webidl_spec], [])
+ self.assertEqual('No specification link found.', errors.next()[2])
+
+ def test_toml(self):
+ errors = tidy.collect_errors_for_files(iterFile('test.toml'), [tidy.check_toml], [])
+ self.assertEqual('found asterisk instead of minimum version number', errors.next()[2])
+
+
+def do_tests():
+ suite = unittest.TestLoader().loadTestsFromTestCase(CheckTidiness)
+ unittest.TextTestRunner(verbosity=2).run(suite)
diff --git a/python/tidy/servo_tidy_tests/tidy_self_test.py b/python/tidy/servo_tidy_tests/tidy_self_test.py
new file mode 100644
index 00000000000..e2a49f71a65
--- /dev/null
+++ b/python/tidy/servo_tidy_tests/tidy_self_test.py
@@ -0,0 +1,78 @@
+# Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+# file at the top-level directory of this distribution.
+#
+# 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.
+
+import unittest
+import tidy
+
+
+def iterFile(name):
+ return iter(['python/tidy_self_test/' + name])
+
+
+class CheckTidiness(unittest.TestCase):
+ def test_spaces_correctnes(self):
+ errors = tidy.collect_errors_for_files(iterFile('wrong_space.rs'), [], [tidy.check_by_line])
+ self.assertEqual('trailing whitespace', errors.next()[2])
+ self.assertEqual('no newline at EOF', errors.next()[2])
+ self.assertEqual('tab on line', errors.next()[2])
+ self.assertEqual('CR on line', errors.next()[2])
+
+ def test_long_line(self):
+ errors = tidy.collect_errors_for_files(iterFile('long_line.rs'), [], [tidy.check_by_line])
+ self.assertEqual('Line is longer than 120 characters', errors.next()[2])
+
+ def test_whatwg_link(self):
+ errors = tidy.collect_errors_for_files(iterFile('whatwg_link.rs'), [], [tidy.check_by_line])
+ self.assertTrue('link to WHATWG may break in the future, use this format instead:' in errors.next()[2])
+ self.assertTrue('links to WHATWG single-page url, change to multi page:' in errors.next()[2])
+
+ def test_licence(self):
+ errors = tidy.collect_errors_for_files(iterFile('incorrect_license.rs'), [], [tidy.check_license])
+ self.assertEqual('incorrect license', errors.next()[2])
+
+ def test_rust(self):
+ errors = tidy.collect_errors_for_files(iterFile('rust_tidy.rs'), [], [tidy.check_rust])
+ self.assertEqual('use statement spans multiple lines', errors.next()[2])
+ self.assertEqual('missing space before }', errors.next()[2])
+ self.assertTrue('use statement is not in alphabetical order' in errors.next()[2])
+ self.assertEqual('encountered whitespace following a use statement', errors.next()[2])
+ self.assertTrue('mod declaration is not in alphabetical order' in errors.next()[2])
+ self.assertEqual('mod declaration spans multiple lines', errors.next()[2])
+ self.assertTrue('extern crate declaration is not in alphabetical order' in errors.next()[2])
+ self.assertEqual('missing space before ->', errors.next()[2])
+ self.assertEqual('missing space after ->', errors.next()[2])
+ self.assertEqual('missing space after :', errors.next()[2])
+ self.assertEqual('missing space before {', errors.next()[2])
+ self.assertEqual('missing space before =', errors.next()[2])
+ self.assertEqual('missing space after =', errors.next()[2])
+ self.assertEqual('missing space before -', errors.next()[2])
+ self.assertEqual('missing space before *', errors.next()[2])
+ self.assertEqual('missing space after =>', errors.next()[2])
+ self.assertEqual('extra space before :', errors.next()[2])
+ self.assertEqual('extra space before :', errors.next()[2])
+ self.assertEqual('use &[T] instead of &Vec<T>', errors.next()[2])
+ self.assertEqual('use &str instead of &String', errors.next()[2])
+
+ def test_spec_link(self):
+ tidy.spec_base_path = "python/tidy_self_test/"
+ errors = tidy.collect_errors_for_files(iterFile('speclink.rs'), [], [tidy.check_spec])
+ self.assertEqual('method declared in webidl is missing a comment with a specification link', errors.next()[2])
+
+ def test_webidl(self):
+ errors = tidy.collect_errors_for_files(iterFile('spec.webidl'), [tidy.check_webidl_spec], [])
+ self.assertEqual('No specification link found.', errors.next()[2])
+
+ def test_toml(self):
+ errors = tidy.collect_errors_for_files(iterFile('test.toml'), [tidy.check_toml], [])
+ self.assertEqual('found asterisk instead of minimum version number', errors.next()[2])
+
+
+def do_tests():
+ suite = unittest.TestLoader().loadTestsFromTestCase(CheckTidiness)
+ unittest.TextTestRunner(verbosity=2).run(suite)
diff --git a/python/tidy/servo_tidy_tests/whatwg_link.rs b/python/tidy/servo_tidy_tests/whatwg_link.rs
new file mode 100644
index 00000000000..e8edfbace49
--- /dev/null
+++ b/python/tidy/servo_tidy_tests/whatwg_link.rs
@@ -0,0 +1,6 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// https://html.spec.whatwg.org/multipage/scripting.html#dom-context-2d-putimagedata
+// https://html.spec.whatwg.org/#typographic-conventions
diff --git a/python/tidy/servo_tidy_tests/wrong_space.rs b/python/tidy/servo_tidy_tests/wrong_space.rs
new file mode 100644
index 00000000000..50ee5de75b4
--- /dev/null
+++ b/python/tidy/servo_tidy_tests/wrong_space.rs
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+pub struct TestStruct(
+ pub testMember1: usize,
+ pub testMember2: bool, ); \ No newline at end of file