Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Add tests related to SCM feature (scm_folder and SVN monorepo) #4193

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions conans/client/cmd/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from conans.search.search import search_recipes
from conans.util.files import is_dirty, load, mkdir, rmdir, save, set_dirty
from conans.util.log import logger
from conans.util.config_parser import get_bool_from_text


def export_alias(reference, target_reference, client_cache):
Expand Down Expand Up @@ -76,10 +77,11 @@ def _capture_export_scm_data(conanfile, conanfile_dir, destination_folder, outpu
captured_revision = scm_data.capture_revision

scm = SCM(scm_data, conanfile_dir, output)
if scm_data.capture_origin or scm_data.capture_revision:
# Generate the scm_folder.txt file pointing to the src_path
src_path = scm.get_repo_root()
save(scm_src_file, src_path.replace("\\", "/"))
if get_bool_from_text(os.environ.get("USE_SCM_FOLER", "True")):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are here just to be able to run tests without the scm_folder.txt file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USE_SCM_FOLER => USE_SCM_FOLDER?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ ...at least it was copy/pasted everywhere

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is only for testing I don't like it, but we could consider this a feature naming in properly: CONAN_USE_SCM_FOLDER. To discuss.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now it is only to make these tests possible. I want you all to review the tests, check the failing ones, they are showing some bugs that cannot be fixed without adding something else to the model.

if scm_data.capture_origin or scm_data.capture_revision:
# Generate the scm_folder.txt file pointing to the src_path
src_path = scm.get_repo_root()
save(scm_src_file, src_path.replace("\\", "/"))

if scm_data.url == "auto":
origin = scm.get_qualified_remote_url()
Expand Down
Empty file.
92 changes: 92 additions & 0 deletions conans/test/functional/scm_folder/git_checkout_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# coding=utf-8

import os
import textwrap
import unittest

from parameterized import parameterized

from conans.client.tools import environment_append
from conans.test.utils.tools import TestClient, create_local_git_repo


class SCMFolderGitTest(unittest.TestCase):
conanfile = textwrap.dedent("""\
import os
from conans import ConanFile, tools

class Pkg(ConanFile):
scm = {"type": "git",
"url": "auto",
"revision": "auto"}

def build(self):
content = tools.load(os.path.join(self.source_folder, "file.txt"))
self.output.info(">>>> I'm {}/{}@{}/{}".format(self.name, self.version,
self.user, self.channel))
self.output.info(">>>> content: {} ".format(content))
""")

def run(self, *args, **kwargs):
with environment_append({'CONAN_USERNAME': "user",
'CONAN_CHANNEL': "channel"}):
super(SCMFolderGitTest, self).run(*args, **kwargs)

def setUp(self):
self.lib1_ref = "lib1/version@user/channel"
self.url, _ = create_local_git_repo(files={'lib1/conanfile.py': self.conanfile,
'lib1/file.txt': self.lib1_ref})

def _run_local_test(self, t, working_dir, path_to_conanfile):
old_wd = t.current_folder
try:
t.current_folder = working_dir
t.run("install {} -if tmp".format(path_to_conanfile))
t.run("source {} -if tmp -sf src".format(path_to_conanfile))
t.run("build {} -if tmp -sf src -bf build".format(path_to_conanfile))
self.assertIn(">>>> I'm None/None@user/channel".format(self.lib1_ref), t.out)
self.assertIn(">>>> content: {}".format(self.lib1_ref), t.out)
finally:
t.current_folder = old_wd

@parameterized.expand([("True",), ("False",)])
def test_local_workflow_root_folder(self, use_scm_folder):
with environment_append({'USE_SCM_FOLER': use_scm_folder}):
t = TestClient(path_with_spaces=False)
t.runner('git clone "{}" .'.format(self.url), cwd=t.current_folder)

# Local workflow (from root folder)
self._run_local_test(t, t.current_folder, "lib1")

@parameterized.expand([("True",), ("False",)])
def test_local_workflow_inner_folder(self, use_scm_folder):
with environment_append({'USE_SCM_FOLER': use_scm_folder}):
t = TestClient(path_with_spaces=False)
t.runner('git clone "{}" .'.format(self.url), cwd=t.current_folder)

# Local workflow (from inner folder)
self._run_local_test(t, os.path.join(t.current_folder, "lib1"), ".")

def _run_remote_test(self, t, working_dir, path_to_conanfile):
old_wd = t.current_folder
try:
t.current_folder = working_dir
t.run("create {} {}".format(path_to_conanfile, self.lib1_ref))
self.assertIn(">>>> I'm {}".format(self.lib1_ref), t.out)
self.assertIn(">>>> content: {}".format(self.lib1_ref), t.out)
finally:
t.current_folder = old_wd

@parameterized.expand([("True",), ("False",)])
def test_remote_workflow(self, use_scm_folder):
with environment_append({"USE_SCM_FOLER": use_scm_folder}):
t = TestClient(path_with_spaces=False)
t.runner('git clone "{}" .'.format(self.url), cwd=t.current_folder)
self._run_remote_test(t, t.current_folder, "lib1")

@parameterized.expand([("True",), ("False",)])
def test_remote_workflow_chdir(self, use_scm_folder):
with environment_append({"USE_SCM_FOLER": use_scm_folder}):
t = TestClient(path_with_spaces=False)
t.runner('git clone "{}" .'.format(self.url), cwd=t.current_folder)
self._run_remote_test(t, os.path.join(t.current_folder, "lib1"), ".")
54 changes: 54 additions & 0 deletions conans/test/functional/scm_folder/obsolete_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# coding=utf-8

import textwrap
import unittest

from parameterized import parameterized
from conans.test.utils.tools import TestClient, create_local_git_repo
from conans.client.tools import environment_append


class SCMFolderObsoleteTest(unittest.TestCase):
conanfile = textwrap.dedent("""\
from conans import ConanFile, tools

class Pkg(ConanFile):
scm = {"type": "git",
"url": "auto",
"revision": "auto"}

def build(self):
content = tools.load("file.txt")
self.output.info(">>>> I'm {}/{}@{}/{}".format(self.name, self.version,
self.user, self.channel))
self.output.info(">>>> content: {} ".format(content))
""")

@parameterized.expand([("True", ), ("False", )])
def test_obsolete(self, use_scm_folder):
with environment_append({"USE_SCM_FOLER": use_scm_folder}):
reference = "pkg/v1@user/channel"
t = TestClient(path_with_spaces=False)

# Create pkg/v1
url, _ = create_local_git_repo(files={'conanfile.py': self.conanfile,
'file.txt': reference},
folder=t.current_folder)
t.runner('git remote add origin {}'.format(url), cwd=t.current_folder)
t.run("create . {}".format(reference))
self.assertIn(">>>> I'm {}".format(reference), t.out)
self.assertIn(">>>> content: {}".format(reference), t.out)

# Work on pkg to improve it ==> create pkg/v2
ref_v2 = "pkg/v2@user/channel"
t.save(files={'conanfile.py': self.conanfile,
'file.txt': ref_v2})
t.runner('git commit -a -m "up to v2"', cwd=t.current_folder)
t.run("create . {}".format(ref_v2))
self.assertIn(">>>> I'm {}".format(ref_v2), t.out)
self.assertIn(">>>> content: {}".format(ref_v2), t.out)

# Now, a consumer wants the pkg/v1 and builds it...
t.run("install {} --build".format(reference))
self.assertIn(">>>> I'm {}".format(reference), t.out)
self.assertIn(">>>> content: {}".format(reference), t.out)
117 changes: 117 additions & 0 deletions conans/test/functional/scm_folder/svn_checkout_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# coding=utf-8

import os
import textwrap

from nose.plugins.attrib import attr
from parameterized import parameterized

from conans.client.tools import environment_append
from conans.test.utils.tools import SVNLocalRepoTestCase
from conans.test.utils.tools import TestClient


@attr("svn")
class SCMFolderSVNCheckout(SVNLocalRepoTestCase):
conanfile = textwrap.dedent("""\
import os
from conans import ConanFile, tools

class Pkg(ConanFile):
scm = {"type": "svn",
"url": "auto",
"revision": "auto"}

def build(self):
content = tools.load(os.path.join(self.source_folder, "file.txt"))
self.output.info(">>>> I'm {}/{}@{}/{}".format(self.name, self.version,
self.user, self.channel))
self.output.info(">>>> content: {} ".format(content))
""")

def run(self, *args, **kwargs):
with environment_append({'CONAN_USERNAME': "user",
"CONAN_CHANNEL": "channel"}):
super(SCMFolderSVNCheckout, self).run(*args, **kwargs)

def setUp(self):
self.lib1_ref = "lib1/version@user/channel"
self.lib2_ref = "lib2/version@user/channel"
self.url, _ = self.create_project(files={'lib1/conanfile.py': self.conanfile,
'lib1/file.txt': self.lib1_ref})

def _run_local_test(self, t, working_dir, path_to_conanfile):
old_wd = t.current_folder
try:
t.current_folder = working_dir
t.run("install {} -if tmp".format(path_to_conanfile))
t.run("source {} -if tmp -sf src".format(path_to_conanfile))
t.run("build {} -if tmp -sf src -bf build".format(path_to_conanfile))
self.assertIn(">>>> I'm None/None@user/channel".format(self.lib1_ref), t.out)
self.assertIn(">>>> content: {}".format(self.lib1_ref), t.out)
finally:
t.current_folder = old_wd

@parameterized.expand([("True",), ("False",)])
def test_local_workflow_root_folder(self, use_scm_folder):
with environment_append({'USE_SCM_FOLDER': use_scm_folder}):
t = TestClient(path_with_spaces=False)
t.runner("svn co {}/lib1 .".format(self.url), cwd=t.current_folder)

# Local workflow (from root folder)
self._run_local_test(t, t.current_folder, ".")

@parameterized.expand([("True",), ("False",)])
def test_local_workflow_root_folder_monorepo(self, use_scm_folder):
with environment_append({'USE_SCM_FOLDER': use_scm_folder}):
t = TestClient(path_with_spaces=False)
t.runner("svn co {} .".format(self.url), cwd=t.current_folder)

# Local workflow (from root folder)
self._run_local_test(t, t.current_folder, "lib1")

@parameterized.expand([("True",), ("False",)])
def test_local_workflow_root_folder_monorepo_chdir(self, use_scm_folder):
with environment_append({'USE_SCM_FOLDER': use_scm_folder}):
t = TestClient(path_with_spaces=False)
t.runner("svn co {} .".format(self.url), cwd=t.current_folder)

# Local workflow (from inner folder)
self._run_local_test(t, os.path.join(t.current_folder, "lib1"), ".")

def _run_remote_test(self, t, working_dir, path_to_conanfile):
old_wd = t.current_folder
try:
t.current_folder = working_dir
t.run("create {} {}".format(path_to_conanfile, self.lib1_ref))
self.assertIn(">>>> I'm {}".format(self.lib1_ref), t.out)
self.assertIn(">>>> content: {}".format(self.lib1_ref), t.out)
finally:
t.current_folder = old_wd

@parameterized.expand([("True",), ("False",)])
def test_remote_workflow(self, use_scm_folder):
with environment_append({"USE_SCM_FOLER": use_scm_folder}):
t = TestClient(path_with_spaces=False)
t.runner("svn co {}/lib1 .".format(self.url), cwd=t.current_folder)

# Remote workflow
self._run_remote_test(t, t.current_folder, ".")

@parameterized.expand([("True",), ("False",)])
def test_remote_workflow_monorepo(self, use_scm_folder):
with environment_append({"USE_SCM_FOLER": use_scm_folder}):
t = TestClient(path_with_spaces=False)
t.runner("svn co {} .".format(self.url), cwd=t.current_folder)

# Remote workflow
self._run_remote_test(t, t.current_folder, "lib1")

@parameterized.expand([("True",), ("False",)])
def test_remote_workflow_monorepo_chdir(self, use_scm_folder):
with environment_append({"USE_SCM_FOLER": use_scm_folder}):
t = TestClient(path_with_spaces=False)
t.runner("svn co {} .".format(self.url), cwd=t.current_folder)

# Remote workflow
self._run_remote_test(t, os.path.join(t.current_folder, "lib1"), ".")