1#!/usr/bin/env python 2# Copyright (c) 2014 Google Inc. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6"""Tests for analyzer 7""" 8 9import TestGyp 10 11found = 'Found dependency\n' 12not_found = 'No dependencies\n' 13 14def __CreateTestFile(files): 15 f = open('test_file', 'w') 16 for file in files: 17 f.write(file + '\n') 18 f.close() 19 20test = TestGyp.TestGypCustom(format='analyzer') 21 22# Verifies file_path must be specified. 23test.run_gyp('test.gyp', 24 stdout='Must specify files to analyze via file_path generator ' 25 'flag\n') 26 27# Trivial test of a source. 28__CreateTestFile(['foo.c']) 29test.run_gyp('test.gyp', '-Gfile_path=test_file', stdout=found) 30 31# Conditional source that is excluded. 32__CreateTestFile(['conditional_source.c']) 33test.run_gyp('test.gyp', '-Gfile_path=test_file', stdout=not_found) 34 35# Conditional source that is included by way of argument. 36__CreateTestFile(['conditional_source.c']) 37test.run_gyp('test.gyp', '-Gfile_path=test_file', '-Dtest_variable=1', 38 stdout=found) 39 40# Two unknown files. 41__CreateTestFile(['unknown1.c', 'unoknow2.cc']) 42test.run_gyp('test.gyp', '-Gfile_path=test_file', stdout=not_found) 43 44# Two unknown files. 45__CreateTestFile(['unknown1.c', 'subdir/subdir_sourcex.c']) 46test.run_gyp('test.gyp', '-Gfile_path=test_file', stdout=not_found) 47 48# Included dependency 49__CreateTestFile(['unknown1.c', 'subdir/subdir_source.c']) 50test.run_gyp('test.gyp', '-Gfile_path=test_file', stdout=found) 51 52# Included inputs to actions. 53__CreateTestFile(['action_input.c']) 54test.run_gyp('test.gyp', '-Gfile_path=test_file', stdout=found) 55 56# Don't consider outputs. 57__CreateTestFile(['action_output.c']) 58test.run_gyp('test.gyp', '-Gfile_path=test_file', stdout=not_found) 59 60# Rule inputs. 61__CreateTestFile(['rule_input.c']) 62test.run_gyp('test.gyp', '-Gfile_path=test_file', stdout=found) 63 64# Ignore patch specified with PRODUCT_DIR. 65__CreateTestFile(['product_dir_input.c']) 66test.run_gyp('test.gyp', '-Gfile_path=test_file', stdout=not_found) 67 68# Path specified via a variable. 69__CreateTestFile(['subdir/subdir_source2.c']) 70test.run_gyp('test.gyp', '-Gfile_path=test_file', stdout=found) 71 72# Verifies paths with // are fixed up correctly. 73__CreateTestFile(['parent_source.c']) 74test.run_gyp('test.gyp', '-Gfile_path=test_file', stdout=found) 75 76test.pass_test() 77