~ubuntu-branches/ubuntu/wily/phabricator/wily

« back to all changes in this revision

Viewing changes to src/parser/__tests__/ArcanistBaseCommitParserTestCase.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2014-11-01 23:20:06 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: package-import@ubuntu.com-20141101232006-mvlnp0cil67tsboe
Tags: upstream-0~git20141101/arcanist
Import upstream version 0~git20141101, component arcanist

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
final class ArcanistBaseCommitParserTestCase extends ArcanistTestCase {
 
4
 
 
5
  public function testBasics() {
 
6
    // Verify that the very basics of base commit resolution work.
 
7
    $this->assertCommit(
 
8
      'Empty Rules',
 
9
      null,
 
10
      array(
 
11
      ));
 
12
 
 
13
    $this->assertCommit(
 
14
      'Literal',
 
15
      'xyz',
 
16
      array(
 
17
        'runtime' => 'literal:xyz',
 
18
      ));
 
19
  }
 
20
 
 
21
  public function testResolutionOrder() {
 
22
    // Rules should be resolved in order: args, local, project, global. These
 
23
    // test cases intentionally scramble argument order to test that resolution
 
24
    // order is independent of argument order.
 
25
    $this->assertCommit(
 
26
      'Order: Args',
 
27
      'y',
 
28
      array(
 
29
        'local'   => 'literal:n',
 
30
        'project' => 'literal:n',
 
31
        'runtime' => 'literal:y',
 
32
        'user'    => 'literal:n',
 
33
      ));
 
34
 
 
35
    $this->assertCommit(
 
36
      'Order: Local',
 
37
      'y',
 
38
      array(
 
39
        'project' => 'literal:n',
 
40
        'local'   => 'literal:y',
 
41
        'user'    => 'literal:n',
 
42
      ));
 
43
 
 
44
    $this->assertCommit(
 
45
      'Order: Project',
 
46
      'y',
 
47
      array(
 
48
        'project' => 'literal:y',
 
49
        'user'    => 'literal:n',
 
50
      ));
 
51
 
 
52
    $this->assertCommit(
 
53
      'Order: Global',
 
54
      'y',
 
55
      array(
 
56
        'user' => 'literal:y',
 
57
      ));
 
58
  }
 
59
 
 
60
  public function testLegacyRule() {
 
61
    // 'global' should translate to 'user'
 
62
    $this->assertCommit(
 
63
      '"global" name',
 
64
      'y',
 
65
      array(
 
66
        'runtime' => 'arc:global, arc:halt',
 
67
        'local'   => 'arc:halt',
 
68
        'project' => 'arc:halt',
 
69
        'user'    => 'literal:y',
 
70
      ));
 
71
 
 
72
    // 'args' should translate to 'runtime'
 
73
    $this->assertCommit(
 
74
      '"args" name',
 
75
      'y',
 
76
      array(
 
77
        'runtime' => 'arc:project, literal:y',
 
78
        'local'   => 'arc:halt',
 
79
        'project' => 'arc:args',
 
80
        'user'    => 'arc:halt',
 
81
      ));
 
82
  }
 
83
 
 
84
  public function testHalt() {
 
85
    // 'arc:halt' should halt all processing.
 
86
    $this->assertCommit(
 
87
      'Halt',
 
88
      null,
 
89
      array(
 
90
        'runtime' => 'arc:halt',
 
91
        'local'   => 'literal:xyz',
 
92
      ));
 
93
  }
 
94
 
 
95
  public function testYield() {
 
96
    // 'arc:yield' should yield to other rulesets.
 
97
    $this->assertCommit(
 
98
      'Yield',
 
99
      'xyz',
 
100
      array(
 
101
        'runtime' => 'arc:yield, literal:abc',
 
102
        'local'   => 'literal:xyz',
 
103
      ));
 
104
 
 
105
    // This one should return to 'runtime' after exhausting 'local'.
 
106
    $this->assertCommit(
 
107
      'Yield + Return',
 
108
      'abc',
 
109
      array(
 
110
        'runtime' => 'arc:yield, literal:abc',
 
111
        'local'   => 'arc:skip',
 
112
      ));
 
113
  }
 
114
 
 
115
  public function testJump() {
 
116
    // This should resolve to 'abc' without hitting any of the halts.
 
117
    $this->assertCommit(
 
118
      'Jump',
 
119
      'abc',
 
120
      array(
 
121
        'runtime' => 'arc:project, arc:halt',
 
122
        'local'   => 'literal:abc',
 
123
        'project' => 'arc:user, arc:halt',
 
124
        'user'    => 'arc:local, arc:halt',
 
125
      ));
 
126
  }
 
127
 
 
128
  public function testJumpReturn() {
 
129
    // After jumping to project, we should return to 'runtime'.
 
130
    $this->assertCommit(
 
131
      'Jump Return',
 
132
      'xyz',
 
133
      array(
 
134
        'runtime' => 'arc:project, literal:xyz',
 
135
        'local'   => 'arc:halt',
 
136
        'project' => '',
 
137
        'user'    => 'arc:halt',
 
138
      ));
 
139
  }
 
140
 
 
141
  private function assertCommit($desc, $commit, $rules) {
 
142
    $parser = $this->buildParser();
 
143
    $result = $parser->resolveBaseCommit($rules);
 
144
    $this->assertEqual($commit, $result, $desc);
 
145
  }
 
146
 
 
147
  private function buildParser() {
 
148
    // TODO: This is a little hacky because we're using the Arcanist repository
 
149
    // itself to execute tests with, but it should be OK until we get proper
 
150
    // isolation for repository-oriented test cases.
 
151
 
 
152
    $root = dirname(phutil_get_library_root('arcanist'));
 
153
    $working_copy = ArcanistWorkingCopyIdentity::newFromPath($root);
 
154
    $configuration_manager = new ArcanistConfigurationManager();
 
155
    $configuration_manager->setWorkingCopyIdentity($working_copy);
 
156
    $repo = ArcanistRepositoryAPI::newAPIFromConfigurationManager(
 
157
      $configuration_manager);
 
158
 
 
159
    return new ArcanistBaseCommitParser($repo);
 
160
  }
 
161
 
 
162
}