Projet

Général

Profil

Paste
Télécharger (6,07 ko) Statistiques
| Branche: | Révision:

root / .drush / drush_make / drush_make.test.inc @ a84ddea4

1
<?php
2
// $Id: drush_make.test.inc,v 1.1.2.19 2010/09/09 06:43:06 dmitrig01 Exp $
3

    
4
/**
5
 * Main drush make-test callback.
6
 */
7
function drush_make_test($test) {
8
  if (empty($test)) {
9
    $rows = array();
10
    $rows[] = array(dt('Command'), dt('Description'));
11
    $rows[] = array('-------', '-----------');
12
    foreach (drush_make_test_get_tests() as $id => $info) {
13
      $rows[] = array($id, $info['name']);
14
    }
15
    drush_print_table($rows, TRUE);
16
  }
17
  else if ($test === 'ALL') {
18
    foreach (array_keys(drush_make_test_get_tests()) as $id) {
19
      drush_make_test_run_test($id);
20
    }
21
  }
22
  else {
23
    drush_make_test_run_test($test);
24
  }
25
}
26

    
27
/**
28
 * Get an array of all tests.
29
 */
30
function drush_make_test_get_tests($id = NULL) {
31
  $tests = array(
32
    'cvs' => array(
33
      'name'     => 'CVS integration',
34
      'makefile' => 'tests/cvs.make',
35
      'build'    => TRUE,
36
      'messages' => array(
37
        'Build hash: f69d29c7ed065b42290bafb7ab9439f1',
38
      ),
39
      'options'  => array(),
40
    ),
41
    'get' => array(
42
      'name'     => 'Test GET retrieval of projects',
43
      'makefile' => 'tests/get.make',
44
      'build'    => TRUE,
45
      'messages' => array(
46
        'Build hash: de88b6acfca95f19ae5ae852bc6bbbe4',
47
      ),
48
      'options'  => array('no-core' => TRUE),
49
    ),
50
    'post' => array(
51
      'name'     => 'Test POST retrieval of projects',
52
      'makefile' => 'tests/post.make',
53
      'build'    => TRUE,
54
      'messages' => array(
55
        'Build hash: 175b3ba2031a30b31775a70e4c23522e',
56
      ),
57
      'options'  => array('no-core' => TRUE),
58
    ),
59
    'git' => array(
60
      'name'     => 'GIT integration',
61
      'makefile' => 'tests/git.make',
62
      'build'    => TRUE,
63
      'messages' => array(
64
        'Build hash: e5210b009b52d60d64ce5effd7e6cf83',
65
      ),
66
      'options'  => array('no-core' => TRUE),
67
    ),
68
    'no-patch-txt' => array(
69
      'name'     => 'Test --no-patch-txt option',
70
      'makefile' => 'tests/patches.make',
71
      'build'    => TRUE,
72
      'messages' => array(
73
        'Build hash: 24f14f6e28498678cebcab2cff3e1030',
74
      ),
75
      'options'  => array('no-core' => TRUE, 'no-patch-txt' => TRUE),
76
    ),
77
    'patch' => array(
78
      'name'     => 'Test patching and writing of PATCHES.txt file',
79
      'makefile' => 'tests/patches.make',
80
      'build'    => TRUE,
81
      'messages' => array(
82
        'Build hash: 173ae5e2120463e31ff2e2a9cc02491b',
83
      ),
84
      'options'  => array('no-core' => TRUE),
85
    ),
86
    'include' => array(
87
      'name'     => 'Including files',
88
      'makefile' => 'tests/include.make',
89
      'build'    => TRUE,
90
      'messages' => array(
91
        'Build hash: a20c3f4f4167c6577156fa616f542120',
92
      ),
93
      'options'  => array(),
94
    ),
95
    'recursion' => array(
96
      'name'     => 'Recursion',
97
      'makefile' => 'tests/recursion.make',
98
      'build'    => TRUE,
99
      'messages' => array(
100
        'Build hash: b4d0599c7c44566a7e3dc9086b870723',
101
      ),
102
      'options'  => array('no-core' => TRUE),
103
    ),
104
    'svn' => array(
105
      'name'     => 'SVN',
106
      'makefile' => 'tests/svn.make',
107
      'build'    => TRUE,
108
      'messages' => array(
109
        'Build hash: 0cb28a15958d7fc4bbf8bf6b00bc6514',
110
      ),
111
      'options'  => array('no-core' => TRUE),
112
    ),
113
    'bzr' => array(
114
      'name'     => 'Bzr',
115
      'makefile' => 'tests/bzr.make',
116
      'build'    => TRUE,
117
      'messages' => array(
118
        'Build hash: 272e2b9bb27794c54396f2f03c159725',
119
      ),
120
      'options'  => array(),
121
    ),
122
    'translations' => array(
123
      'name'     => 'Translation downloads',
124
      'makefile' => 'tests/translations.make',
125
      'build'    => TRUE,
126
      'messages' => array(
127
        'Build hash: 93272917b39388289075c4a6e2f5dd58',
128
      ),
129
      'options'  => array('translations' => 'es,pt-br'),
130
    ),
131
    'contrib-destination' => array(
132
      'name'     => 'Contrib-destination attribute',
133
      'makefile' => 'tests/contrib-destination.make',
134
      'build'    => TRUE,
135
      'messages' => array(
136
        'Build hash: d615d004adfa8ebfe44e91119b88389c',
137
      ),
138
      'options'  => array('no-core' => TRUE, 'contrib-destination' => '.'),
139
    ),
140
  );
141
  if (isset($id)) {
142
    return isset($tests[$id]) ? $tests[$id] : FALSE;
143
  }
144
  return $tests;
145
}
146

    
147
/**
148
 * Run a drush make test.
149
 */
150
function drush_make_test_run_test($id) {
151
  if ($test = drush_make_test_get_tests($id)) {
152
    $makefile = dirname(__FILE__) .'/'. $test['makefile'];
153
    $options = $test['options'] + array('test' => TRUE, 'md5' => TRUE);
154

    
155
    // Log the test command.
156
    $debug_command = 'drush make';
157
    foreach ($options as $k => $v) {
158
      $debug_command .= _drush_escape_option($k, $v);
159
    }
160
    $debug_command .= " {$makefile}";
161
    drush_log(dt('Test command: @debug.', array('@debug' => $debug_command)), 'ok');
162

    
163
    $fail = FALSE;
164
    if ($data = drush_backend_invoke('make '. $makefile, $options)) {
165
      // Test build completion.
166
      if (isset($test['build'])) {
167
        if ($test['build'] && !empty($data['error_status'])) {
168
          $fail = TRUE;
169
          drush_log(dt('@testname: build failed.', array('@testname' => $test['name'])), 'error');
170
        }
171
        elseif (!$test['build'] && empty($data['error_status'])) {
172
          $fail = TRUE;
173
          drush_log(dt('@testname: build completed.', array('@testname' => $test['name'])), 'error');
174
        }
175
      }
176
      // Test for messages.
177
      if (isset($test['messages'])) {
178
        $messages = array();
179
        foreach ($data['log'] as $item) {
180
          $messages[] = $item['message'];
181
        }
182
        foreach ($test['messages'] as $message) {
183
          if (!in_array($message, $messages)) {
184
            $fail = TRUE;
185
            drush_log(dt('@testname: "@message" not found.', array('@testname' => $test['name'], '@message' => $message)), 'error');
186
          }
187
        }
188
      }
189
      if (!$fail) {
190
        drush_log(dt('Drush make test @testname passed.', array('@testname' => $test['name'])), 'ok');
191
        return TRUE;
192
      }
193
    }
194
    drush_log(dt('Drush make test @testname failed.', array('@testname' => $test['name'])), 'error');
195
    return FALSE;
196
  }
197
  drush_log(dt('Test @testname could not be found.', array('@testname' => $test['name'])), 'error');
198
  return FALSE;
199
}