Skip to content

Commit

Permalink
Hide cycle in testprojects
Browse files Browse the repository at this point in the history
Cycle detection is tested in `test_sort_targets.py`, but having a cycle existing directly in the repo breaks implementations of graph parsing that validate cycles early. While `testprojects` is explicitly for "broken" code, keeping it `./pants list`able seems important for maintaining it.

- Move cycle detection integration test into `test_build_graph_integration` with mangled BUILD file names.

Testing Done:
https://travis-ci.org/pantsbuild/pants/builds/118118736

Bugs closed: 3058, 3081

Reviewed at https://rbcommons.com/s/twitter/r/3600/
  • Loading branch information
stuhood committed Mar 24, 2016
1 parent ed0cd0c commit 5503041
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@ class JarDependencyManagementIntegrationTest(PantsRunIntegrationTest):

@contextmanager
def _testing_build_file(self):
test_name = os.path.join(self.project, 'TEST_BUILD')
real_name = os.path.join(self.project, 'BUILD')
try:
os.rename(test_name, real_name)
with self.file_renamed(self.project, 'TEST_BUILD', 'BUILD'):
yield
finally:
os.rename(real_name, test_name)

def _run_project(self, spec_name, default_target=None, conflict_strategy=None):
with self._testing_build_file():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@

class IvyResolveIntegrationTest(PantsRunIntegrationTest):

def test_ivy_resolve_gives_correct_exception_on_cycles(self):
with self.temporary_workdir() as workdir:
pants_run = self.run_pants_with_workdir([
'compile', 'testprojects/src/java/org/pantsbuild/testproject/cycle1'], workdir)
self.assert_failure(pants_run)
self.assertIn('Cycle detected', pants_run.stderr_data)

def test_java_compile_with_ivy_report(self):
# Ensure the ivy report file gets generated
with self.temporary_workdir() as workdir:
Expand Down
9 changes: 9 additions & 0 deletions tests/python/pants_test/build_graph/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ python_tests(
],
)

python_tests(
name = 'build_graph_integration',
sources = ['test_build_graph_integration.py'],
dependencies = [
'tests/python/pants_test:int-test',
],
tags = {'integration'},
)

python_tests(
name = 'source_mapper',
sources = ['test_source_mapper.py'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# coding=utf-8
# Copyright 2016 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

import os

from pants_test.pants_run_integration_test import PantsRunIntegrationTest


class BuildGraphIntegrationTest(PantsRunIntegrationTest):

def test_cycle(self):
prefix = 'testprojects/src/java/org/pantsbuild/testproject'
with self.file_renamed(os.path.join(prefix, 'cycle1'), 'TEST_BUILD', 'BUILD'):
with self.file_renamed(os.path.join(prefix, 'cycle2'), 'TEST_BUILD', 'BUILD'):
pants_run = self.run_pants(['compile', os.path.join(prefix, 'cycle1')])
self.assert_failure(pants_run)
self.assertIn('Cycle detected', pants_run.stderr_data)
10 changes: 10 additions & 0 deletions tests/python/pants_test/pants_run_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,13 @@ def indent(content):
def normalize(self, s):
"""Removes escape sequences (e.g. colored output) and all whitespace from string s."""
return ''.join(strip_color(s).split())

@contextmanager
def file_renamed(self, prefix, test_name, real_name):
real_path = os.path.join(prefix, real_name)
test_path = os.path.join(prefix, test_name)
try:
os.rename(test_path, real_path)
yield
finally:
os.rename(real_path, test_path)
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ def tests_testprojects(self):
'testprojects/src/antlr/pants/backend/python/test:antlr_failure',
'testprojects/src/java/org/pantsbuild/testproject/bundle:missing-files',
'testprojects/src/java/org/pantsbuild/testproject/compilation_warnings:fatal',
'testprojects/src/java/org/pantsbuild/testproject/cycle1',
'testprojects/src/java/org/pantsbuild/testproject/cycle2',
'testprojects/src/java/org/pantsbuild/testproject/dummies:compilation_failure_target',
'testprojects/src/java/org/pantsbuild/testproject/junit/beforeclassexception:tests',
'testprojects/src/java/org/pantsbuild/testproject/junit/failing/tests/org/pantsbuild/tmp/tests',
Expand Down

0 comments on commit 5503041

Please sign in to comment.