mirror of
https://github.com/servo/servo.git
synced 2025-07-03 21:43:41 +01:00
Auto merge of #9835 - mskrzypkows:tidy_tests, r=Wafflespeanut
Initial tests for tidy.py #9152 I've created tests for spaces check and license. Tell me if it's good direction so I'll add more tests. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9835) <!-- Reviewable:end -->
This commit is contained in:
commit
72eae39679
12 changed files with 169 additions and 5 deletions
|
@ -4,7 +4,9 @@ matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
include:
|
include:
|
||||||
- sudo: false
|
- sudo: false
|
||||||
script: ./mach test-tidy --no-progress
|
script:
|
||||||
|
- ./mach test-tidy --self-test
|
||||||
|
- ./mach test-tidy --no-progress
|
||||||
cache: false
|
cache: false
|
||||||
- sudo: 9000
|
- sudo: 9000
|
||||||
dist: trusty
|
dist: trusty
|
||||||
|
|
|
@ -30,6 +30,7 @@ from servo.command_base import CommandBase, call, check_call
|
||||||
from wptrunner import wptcommandline
|
from wptrunner import wptcommandline
|
||||||
from update import updatecommandline
|
from update import updatecommandline
|
||||||
import tidy
|
import tidy
|
||||||
|
from tidy_self_test import tidy_self_test
|
||||||
|
|
||||||
SCRIPT_PATH = os.path.split(__file__)[0]
|
SCRIPT_PATH = os.path.split(__file__)[0]
|
||||||
PROJECT_TOPLEVEL_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..", ".."))
|
PROJECT_TOPLEVEL_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..", ".."))
|
||||||
|
@ -71,9 +72,12 @@ class MachCommands(CommandBase):
|
||||||
help="Only check changed files and skip the WPT lint in tidy")
|
help="Only check changed files and skip the WPT lint in tidy")
|
||||||
@CommandArgument('--no-progress', default=False, action="store_true",
|
@CommandArgument('--no-progress', default=False, action="store_true",
|
||||||
help="Don't show progress for tidy")
|
help="Don't show progress for tidy")
|
||||||
def test(self, params, render_mode=DEFAULT_RENDER_MODE, release=False, faster=False, no_progress=False):
|
@CommandArgument('--self-test', default=False, action="store_true",
|
||||||
|
help="Run unit tests for tidy")
|
||||||
|
def test(self, params, render_mode=DEFAULT_RENDER_MODE, release=False, faster=False, no_progress=False,
|
||||||
|
self_test=False):
|
||||||
suites = OrderedDict([
|
suites = OrderedDict([
|
||||||
("tidy", {"kwargs": {"faster": faster, "no_progress": no_progress},
|
("tidy", {"kwargs": {"faster": faster, "no_progress": no_progress, "self_test": self_test},
|
||||||
"include_arg": "include"}),
|
"include_arg": "include"}),
|
||||||
("wpt", {"kwargs": {"release": release},
|
("wpt", {"kwargs": {"release": release},
|
||||||
"paths": [path.abspath(path.join("tests", "wpt", "web-platform-tests")),
|
"paths": [path.abspath(path.join("tests", "wpt", "web-platform-tests")),
|
||||||
|
@ -271,7 +275,12 @@ class MachCommands(CommandBase):
|
||||||
"if there are no changes in the WPT files")
|
"if there are no changes in the WPT files")
|
||||||
@CommandArgument('--no-progress', default=False, action="store_true",
|
@CommandArgument('--no-progress', default=False, action="store_true",
|
||||||
help="Don't show progress for tidy")
|
help="Don't show progress for tidy")
|
||||||
def test_tidy(self, faster, no_progress):
|
@CommandArgument('--self-test', default=False, action="store_true",
|
||||||
|
help="Run unit tests for tidy")
|
||||||
|
def test_tidy(self, faster, no_progress, self_test):
|
||||||
|
if self_test:
|
||||||
|
return tidy_self_test.do_tests()
|
||||||
|
else:
|
||||||
return tidy.scan(faster, not no_progress)
|
return tidy.scan(faster, not no_progress)
|
||||||
|
|
||||||
@Command('test-webidl',
|
@Command('test-webidl',
|
||||||
|
|
|
@ -56,6 +56,7 @@ ignored_dirs = [
|
||||||
os.path.join(".", "tests", "wpt", "sync"),
|
os.path.join(".", "tests", "wpt", "sync"),
|
||||||
os.path.join(".", "tests", "wpt", "sync_css"),
|
os.path.join(".", "tests", "wpt", "sync_css"),
|
||||||
os.path.join(".", "python", "mach"),
|
os.path.join(".", "python", "mach"),
|
||||||
|
os.path.join(".", "python", "tidy_self_test"),
|
||||||
os.path.join(".", "components", "script", "dom", "bindings", "codegen", "parser"),
|
os.path.join(".", "components", "script", "dom", "bindings", "codegen", "parser"),
|
||||||
os.path.join(".", "components", "script", "dom", "bindings", "codegen", "ply"),
|
os.path.join(".", "components", "script", "dom", "bindings", "codegen", "ply"),
|
||||||
os.path.join(".", "python", "_virtualenv"),
|
os.path.join(".", "python", "_virtualenv"),
|
||||||
|
|
8
python/tidy_self_test/__init__.py
Normal file
8
python/tidy_self_test/__init__.py
Normal file
|
@ -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.
|
1
python/tidy_self_test/incorrect_license.rs
Normal file
1
python/tidy_self_test/incorrect_license.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/* Incorrect license here */
|
5
python/tidy_self_test/long_line.rs
Normal file
5
python/tidy_self_test/long_line.rs
Normal file
|
@ -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");
|
37
python/tidy_self_test/rust_tidy.rs
Normal file
37
python/tidy_self_test/rust_tidy.rs
Normal file
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
10
python/tidy_self_test/spec.webidl
Normal file
10
python/tidy_self_test/spec.webidl
Normal file
|
@ -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;
|
||||||
|
};
|
5
python/tidy_self_test/test.toml
Normal file
5
python/tidy_self_test/test.toml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
[package]
|
||||||
|
name = "test"
|
||||||
|
version = "*"
|
||||||
|
authors = ["The Servo Project Developers"]
|
||||||
|
publish = false
|
73
python/tidy_self_test/tidy_self_test.py
Normal file
73
python/tidy_self_test/tidy_self_test.py
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
# 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_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)
|
6
python/tidy_self_test/whatwg_link.rs
Normal file
6
python/tidy_self_test/whatwg_link.rs
Normal file
|
@ -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
|
7
python/tidy_self_test/wrong_space.rs
Normal file
7
python/tidy_self_test/wrong_space.rs
Normal file
|
@ -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,
);
|
Loading…
Add table
Add a link
Reference in a new issue