Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1556)

Unified Diff: test/analyzer/gyptest-analyzer.new.py

Issue 420383002: Changes analyzer to search for targets (Closed) Base URL: http://gyp.googlecode.com/svn/trunk
Patch Set: cleanup Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pylib/gyp/generator/analyzer.py ('k') | test/analyzer/subdir/subdir.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/analyzer/gyptest-analyzer.new.py
diff --git a/test/analyzer/gyptest-analyzer.new.py b/test/analyzer/gyptest-analyzer.new.py
new file mode 100644
index 0000000000000000000000000000000000000000..e13327fa7fe860ae45076e9b0db4c57153c70d22
--- /dev/null
+++ b/test/analyzer/gyptest-analyzer.new.py
@@ -0,0 +1,170 @@
+#!/usr/bin/env python
+# Copyright (c) 2014 Google Inc. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Tests for analyzer
+"""
+
+import json
+import TestGyp
+
+# TODO(sky): when done migrating recipes rename to gyptest-analyzer and nuke
+# existing gyptest-analyzer.
+
+found = 'Found dependency'
+not_found = 'No dependencies'
+
+def _CreateTestFile(files, targets):
+ f = open('test_file', 'w')
+ to_write = {'files': files, 'targets': targets }
+ json.dump(to_write, f)
+ f.close()
+
+def _CreateBogusTestFile():
+ f = open('test_file','w')
+ f.write('bogus')
+ f.close()
+
+test = TestGyp.TestGypCustom(format='analyzer')
+
+def EnsureContains(test, targets=set(), matched=False):
+ """Verifies stdout for |test| contains |targets| and |direct_targets|."""
+ result = json.loads(test.stdout())
+ if result.get('error', None):
+ print 'unexpected error', result.get('error')
+ test.fail_test()
+
+ actual_targets = set(result['targets'])
+ if actual_targets != targets:
+ print 'actual targets:', actual_targets, '\nexpected targets:', targets
+ test.fail_test()
+
+ if matched and result['status'] != found:
+ print 'expected', found, 'got', result['status']
+ elif not matched and result['status'] != not_found:
+ print 'expected', not_found, 'got', result['status']
+
+def EnsureError(test, expected_error_string):
+ """Verifies stdout for |test| contains the error string."""
+ result = json.loads(test.stdout())
+ if result.get('error', '').find(expected_error_string) == -1:
+ print 'actual error:', result.get('error', ''), '\nexpected error:', \
+ expected_error_string
+ test.fail_test()
+
+# Verifies file_path must be specified.
+test.run_gyp('test.gyp',
+ stdout='Must specify files to analyze via file_path generator '
+ 'flag\n')
+
+# Verifies config_path must point to a valid file.
+test.run_gyp('test.gyp', '-Gconfig_path=bogus_file')
+EnsureError(test, 'Unable to open file bogus_file')
+
+# Verify get error when bad target is specified.
+_CreateTestFile(['exe2.c'], ['bad_target'])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureError(test, 'Unable to find all targets')
+
+# Verifies config_path must point to a valid json file.
+_CreateBogusTestFile()
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureError(test, 'Unable to parse config file test_file')
+
+# Trivial test of a source.
+_CreateTestFile(['foo.c'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=True)
+
+# Conditional source that is excluded.
+_CreateTestFile(['conditional_source.c'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=False)
+
+# Conditional source that is included by way of argument.
+_CreateTestFile(['conditional_source.c'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file', '-Dtest_variable=1')
+EnsureContains(test, matched=True)
+
+# Two unknown files.
+_CreateTestFile(['unknown1.c', 'unoknow2.cc'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test)
+
+# Two unknown files.
+_CreateTestFile(['unknown1.c', 'subdir/subdir_sourcex.c'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test)
+
+# Included dependency
+_CreateTestFile(['unknown1.c', 'subdir/subdir_source.c'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=True)
+
+# Included inputs to actions.
+_CreateTestFile(['action_input.c'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=True)
+
+# Don't consider outputs.
+_CreateTestFile(['action_output.c'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=False)
+
+# Rule inputs.
+_CreateTestFile(['rule_input.c'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=True)
+
+# Ignore path specified with PRODUCT_DIR.
+_CreateTestFile(['product_dir_input.c'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=False)
+
+# Path specified via a variable.
+_CreateTestFile(['subdir/subdir_source2.c'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=True)
+
+# Verifies paths with // are fixed up correctly.
+_CreateTestFile(['parent_source.c'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=True)
+
+# Verifies relative paths are resolved correctly.
+_CreateTestFile(['subdir/subdir_source.h'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=True)
+
+# Various permutations when passing in targets.
+_CreateTestFile(['exe2.c', 'subdir/subdir2b_source.c'], ['exe', 'exe3'])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=True, targets={'exe3'})
+
+_CreateTestFile(['exe2.c', 'subdir/subdir2b_source.c'], ['exe'])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=True)
+
+# Verifies duplicates are ignored.
+_CreateTestFile(['exe2.c', 'subdir/subdir2b_source.c'], ['exe', 'exe'])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=True)
+
+_CreateTestFile(['exe2.c'], ['exe'])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=True)
+
+_CreateTestFile(['exe2.c'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=True)
+
+_CreateTestFile(['subdir/subdir2b_source.c', 'exe2.c'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=True)
+
+_CreateTestFile(['exe2.c'], [])
+test.run_gyp('test.gyp', '-Gconfig_path=test_file')
+EnsureContains(test, matched=True)
+
+test.pass_test()
« no previous file with comments | « pylib/gyp/generator/analyzer.py ('k') | test/analyzer/subdir/subdir.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698