1#!/usr/bin/env python
2
3# Copyright (c) 2012 Google Inc. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""
8Test that two targets with the same name generates an error.
9"""
10
11import os
12import sys
13
14import TestGyp
15import TestCmd
16
17# TODO(sbc): Remove the use of match_re below, done because scons
18# error messages were not consistent with other generators.
19# Also remove input.py:generator_wants_absolute_build_file_paths.
20
21test = TestGyp.TestGyp()
22
23stderr = ('gyp: Duplicate target definitions for '
24          '.*duplicate_targets.gyp:foo#target\n')
25test.run_gyp('duplicate_targets.gyp', status=1, stderr=stderr,
26             match=TestCmd.match_re)
27
28stderr = ('.*: Unable to find targets in build file .*missing_targets.gyp.*')
29test.run_gyp('missing_targets.gyp', status=1, stderr=stderr,
30             match=TestCmd.match_re_dotall)
31
32stderr = ('gyp: rule bar exists in duplicate, target '
33          '.*duplicate_rule.gyp:foo#target\n')
34test.run_gyp('duplicate_rule.gyp', status=1, stderr=stderr,
35             match=TestCmd.match_re)
36
37stderr = ("gyp: Key 'targets' repeated at level 1 with key path '' while "
38          "reading .*duplicate_node.gyp.*")
39test.run_gyp('duplicate_node.gyp', '--check', status=1, stderr=stderr,
40             match=TestCmd.match_re_dotall)
41
42stderr = 'gyp: Duplicate basenames in sources section, see list above\n'
43test.run_gyp('duplicate_basenames.gyp', status=1, stderr=stderr)
44
45# Check if '--no-duplicate-basename-check' works.
46if ((test.format == 'make' and sys.platform == 'darwin') or
47    (test.format == 'msvs' and
48        int(os.environ.get('GYP_MSVS_VERSION', 2010)) < 2010)):
49  stderr = 'gyp: Duplicate basenames in sources section, see list above\n'
50  test.run_gyp('duplicate_basenames.gyp', '--no-duplicate-basename-check',
51               status=1, stderr=stderr)
52else:
53  test.run_gyp('duplicate_basenames.gyp', '--no-duplicate-basename-check')
54
55stderr = ("gyp: Dependency '.*missing_dep.gyp:missing.gyp#target' not found "
56          "while trying to load target .*missing_dep.gyp:foo#target\n")
57test.run_gyp('missing_dep.gyp', status=1, stderr=stderr,
58             match=TestCmd.match_re)
59
60test.pass_test()
61