1# Copyright (C) 2010 Apple Inc. All rights reserved.
2#
3# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions
5# are met:
6# 1.  Redistributions of source code must retain the above copyright
7#     notice, this list of conditions and the following disclaimer.
8# 2.  Redistributions in binary form must reproduce the above copyright
9#     notice, this list of conditions and the following disclaimer in the
10#     documentation and/or other materials provided with the distribution.
11#
12# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
13# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
16# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
23import unittest
24
25from webkitpy.common.config import build
26
27
28class ShouldBuildTest(unittest.TestCase):
29    _should_build_tests = [
30        (["ChangeLog", "Source/WebCore/ChangeLog", "Source/WebKit2/ChangeLog-2011-02-11"], []),
31        (["GNUmakefile.am", "Source/WebCore/GNUmakefile.am"], ["gtk"]),
32        (["Websites/bugs.webkit.org/foo", "Source/WebCore/bar"], ["*"]),
33        (["Websites/bugs.webkit.org/foo"], []),
34        (["Source/JavaScriptCore/JavaScriptCore.xcodeproj/foo"], ["mac-leopard", "mac-snowleopard"]),
35        (["Source/JavaScriptCore/JavaScriptCore.vcproj/foo", "Source/WebKit2/win/WebKit2.vcproj", "Source/WebKit/win/WebKit.sln", "Tools/WebKitTestRunner/Configurations/WebKitTestRunnerCommon.vsprops"], ["win"]),
36        (["Source/JavaScriptGlue/foo", "Source/WebCore/bar"], ["*"]),
37        (["Source/JavaScriptGlue/foo"], ["mac-leopard", "mac-snowleopard"]),
38        (["LayoutTests/foo"], ["*"]),
39        (["LayoutTests/canvas/philip/tests/size.attributes.parse.exp-expected.txt", "LayoutTests/canvas/philip/tests/size.attributes.parse.exp.html"], ["*"]),
40        (["LayoutTests/platform/chromium-linux/foo"], ["chromium-linux"]),
41        (["LayoutTests/platform/chromium-win/fast/compact/001-expected.txt"], ["chromium-win"]),
42        (["LayoutTests/platform/mac-leopard/foo"], ["mac-leopard"]),
43        (["LayoutTests/platform/mac-snowleopard/foo"], ["mac-leopard", "mac-snowleopard", "win"]),
44        (["LayoutTests/platform/mac-wk2/Skipped"], ["mac-snowleopard", "win"]),
45        (["LayoutTests/platform/mac/foo"], ["mac-leopard", "mac-snowleopard", "win"]),
46        (["LayoutTests/platform/win-xp/foo"], ["win"]),
47        (["LayoutTests/platform/win-wk2/foo"], ["win"]),
48        (["LayoutTests/platform/win/foo"], ["win"]),
49        (["Source/WebCore.exp.in", "Source/WebKit/mac/WebKit.exp"], ["mac-leopard", "mac-snowleopard"]),
50        (["Source/WebCore/mac/foo"], ["chromium-mac", "mac-leopard", "mac-snowleopard"]),
51        (["Source/WebCore/win/foo"], ["chromium-win", "win"]),
52        (["Source/WebCore/platform/graphics/gpu/foo"], ["mac-leopard", "mac-snowleopard"]),
53        (["Source/WebCore/platform/wx/wxcode/win/foo"], []),
54        (["Source/WebCore/rendering/RenderThemeMac.mm", "Source/WebCore/rendering/RenderThemeMac.h"], ["mac-leopard", "mac-snowleopard"]),
55        (["Source/WebCore/rendering/RenderThemeChromiumLinux.h"], ["chromium-linux"]),
56        (["Source/WebCore/rendering/RenderThemeWinCE.h"], []),
57        (["Tools/BuildSlaveSupport/build.webkit.org-config/public_html/LeaksViewer/LeaksViewer.js"], []),
58    ]
59
60    def test_should_build(self):
61        for files, platforms in self._should_build_tests:
62            # FIXME: We should test more platforms here once
63            # build._should_file_trigger_build is implemented for them.
64            for platform in ["mac-leopard", "mac-snowleopard", "win"]:
65                should_build = platform in platforms or "*" in platforms
66                self.assertEqual(build.should_build(platform, files), should_build, "%s should%s have built but did%s (files: %s)" % (platform, "" if should_build else "n't", "n't" if should_build else "", str(files)))
67
68
69if __name__ == "__main__":
70    unittest.main()
71