|
1
|
+import os
|
|
2
|
+import pytest
|
|
3
|
+
|
|
4
|
+from tests.testutils import cli_integration as cli
|
|
5
|
+from tests.testutils.integration import assert_contains
|
|
6
|
+from tests.testutils.site import IS_LINUX
|
|
7
|
+
|
|
8
|
+pytestmark = pytest.mark.integration
|
|
9
|
+
|
|
10
|
+DATA_DIR = os.path.join(
|
|
11
|
+ os.path.dirname(os.path.realpath(__file__)), '..', '..', 'doc', 'examples', 'junctions'
|
|
12
|
+)
|
|
13
|
+
|
|
14
|
+JUNCTION_IMPORT_PATH = os.path.join(
|
|
15
|
+ os.path.dirname(os.path.realpath(__file__)), '..', '..', 'doc', 'examples', 'autotools'
|
|
16
|
+)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+def ammend_juntion_path_paths(tmpdir):
|
|
20
|
+ # The junction element in the examples/junctions project uses a local source type.
|
|
21
|
+ # It's "path:" must specify a relative path from the project's root directory.
|
|
22
|
+ # For the hello-junction element to function during these tests, the copy of the junctions
|
|
23
|
+ # project made in the buildstream/tmp/directory, "path:" must be ammended to be the relative
|
|
24
|
+ # path to the autotools example from the temporary test directory.
|
|
25
|
+ junction_element = os.path.join(tmpdir, "elements", "hello-junction.bst")
|
|
26
|
+ junction_element_bst = ""
|
|
27
|
+ junction_relative_path = os.path.relpath(JUNCTION_IMPORT_PATH, tmpdir)
|
|
28
|
+ with open(junction_element, 'r') as f:
|
|
29
|
+ junction_element_bst = f.read()
|
|
30
|
+ ammended_element_bst = junction_element_bst.replace("../autotools", junction_relative_path)
|
|
31
|
+ with open(junction_element, 'w') as f:
|
|
32
|
+ f.write(ammended_element_bst)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+# Check that the autotools project is where the junctions example expects and
|
|
36
|
+# contains the hello.bst element.
|
|
37
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
38
|
+def test_autotools_example_is_present(datafiles):
|
|
39
|
+ autotools_path = JUNCTION_IMPORT_PATH
|
|
40
|
+ assert os.path.exists(autotools_path)
|
|
41
|
+ assert os.path.exists(os.path.join(autotools_path, "elements", "hello.bst"))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+# Test that the project builds successfully
|
|
45
|
+@pytest.mark.skipif(not IS_LINUX, reason='Only available on linux')
|
|
46
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
47
|
+def test_build(cli, tmpdir, datafiles):
|
|
48
|
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
49
|
+ ammend_juntion_path_paths(str(tmpdir))
|
|
50
|
+
|
|
51
|
+ result = cli.run(project=project, args=['build', 'callHello.bst'])
|
|
52
|
+ result.assert_success()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+# Test the callHello script works as expected.
|
|
56
|
+@pytest.mark.skipif(not IS_LINUX, reason='Only available on linux')
|
|
57
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
58
|
+def test_shell_call_hello(cli, tmpdir, datafiles):
|
|
59
|
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
60
|
+ ammend_juntion_path_paths(str(tmpdir))
|
|
61
|
+
|
|
62
|
+ result = cli.run(project=project, args=['build', 'callHello.bst'])
|
|
63
|
+ result.assert_success()
|
|
64
|
+
|
|
65
|
+ result = cli.run(project=project, args=['shell', 'callHello.bst', '--', '/bin/sh', 'callHello.sh'])
|
|
66
|
+ result.assert_success()
|
|
67
|
+ assert result.output == 'Calling hello:\nHello World!\nThis is amhello 1.0.\n'
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+# Test opening a cross-junction workspace
|
|
71
|
+@pytest.mark.skipif(not IS_LINUX, reason='Only available on linux')
|
|
72
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
73
|
+def test_open_cross_junction_workspace(cli, tmpdir, datafiles):
|
|
74
|
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
75
|
+ workspace_dir = os.path.join(str(tmpdir), "workspace_hello_junction")
|
|
76
|
+ ammend_juntion_path_paths(str(tmpdir))
|
|
77
|
+
|
|
78
|
+ result = cli.run(project=project,
|
|
79
|
+ args=['workspace', 'open', 'hello-junction.bst:hello.bst', workspace_dir])
|
|
80
|
+ result.assert_success()
|
|
81
|
+
|
|
82
|
+ result = cli.run(project=project,
|
|
83
|
+ args=['workspace', 'close', '--remove-dir', 'hello-junction.bst:hello.bst'])
|
|
84
|
+ result.assert_success()
|