FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
dashR.php
1 <?php
2 /*
3  Copyright (C) 2007 Hewlett-Packard Development Company, L.P.
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***********************************************************/
27 $archive_path = '/tmp/fossology';
28 
29 class TestCP2fossRecursion extends UnitTestCase
30 {
31  /*
32  * This function will use illegal archives, that is we have a file for
33  * input, but it is zero length.
34  */
35 
36  public $command = '/usr/local/bin/test.cp2foss';
37 
38  function TestDashRNoArchive()
39  {
40 
41  $error = exec("$this->command -p devnull -n fail -a /dev/null -d \"test should fail\" ",
42  $output, $retval);
43  //print_r($output);
44  $this->assertPattern('/Error, .* not greater than zero/', $output[0]);
45  //print_r($output);
46  $output = array();
47  $error = exec("$this->command -p stdin -n fail -a /dev/stdin -d 'stdin should fail'",
48  $output, $retval);
49  //print_r($output);
50  $this->assertPattern('/Stopping, can\'t process archive/', $output[1]);
51  }
52 
53  /*
54  * This test needs setup: need some dir tree to process.
55  *
56  * Tyically the fossology sources are used. Check them out to
57  * /tmp/fossology for this test to work.
58  *
59  * Consider adding setup and teardown methods. For now the install
60  * test script sets this up.
61  *
62  */
63 
64  function TestNoDashR()
65  {
66  /*
67  * Method: run a real cp2foss run, then examine the tar file created
68  * by it and compare to what was tar'ed up. If no differences,
69  * at least cp2foss worked as far as creating the archive to upload
70  * correctly. This test DOES NOT test if the upload worked.
71  */
72 
73  $last = exec(
74  "$this->command -p CP2fossTest/fldr1 -n fossology -a $archive_path -d 'no -R, only files saved' ", $output, $retval
75  );
76  echo "\$output Only files is:\n"; dump($output); echo "\n";
77 
78  /*
79  * $output[1] will always have the archive we are loading... in this
80  * case it will be a tar file....get only the files under fossology
81  *
82  * NOTE: this seems to be brittle.... sometimes it's 2?! and then
83  * this test breaks....
84  *
85  */
86 
87  $find = "find /tmp/fossology -maxdepth 1 -type f -print";
88  $last = exec($find, $findoutput, $retval);
89  $last = exec("tar -tf $output[1]", $tarout, $retval);
90  // get leaf names from find output
91  $basenames = array();
92  foreach ($findoutput as $path) {
93  $basenames[] = basename($path);
94  }
95  sort($tarout);
96  sort($basenames);
97  $diffs = array_diff($tarout, $basenames);
98  if (empty($diffs)) {
99  $this->pass();
100  } else {
101  $this->fail();
102  }
103  }
104 
105  function TestDashR()
106  {
107  /*
108  * Method: run a real cp2foss run, then examine the tar file created
109  * by it and compare to what was tar'ed up. If no differences,
110  * at least cp2foss worked as far as creating the archive to upload
111  * correctly. This test DOES NOT test if the upload worked.
112  */
113  $last = exec(
114  "$this->command -p CP2fossTest -n fossology -a $archive_path -R -d '-R all contents saved' ",
115  $output, $retval);
116  /*
117  * $output[1] will always have the archive we are loading... in this
118  * case it will be a tar file....get only the files under fossology
119  *
120  */
121 
122  echo "output All contents is:\n"; dump($output); echo "\n";
123  /*
124  * Tried using find and combos of ls etc... issue was getting the
125  * trailing / on directories without changing the format.
126  * Gave up, and will just retar the archive and then compare to the
127  * orginal tar.
128  */
129  $temp_tar = "/tmp/test.tar.bz2";
130  chdir($apath) or die("Can't cd to $apath, $php_errormsg\n");
131 
132  $tcmd = "tar -cjf $temp_tar --exclude='.svn' --exclude='.cvs' *";
133  $last = exec($tcmd, $Rtoutput, $retval);
134  $last = exec("tar -tf $output[1]", $tarout, $retval);
135  $last = exec("tar -tf $temp_tar", $Rtout, $retval);
136  foreach ($tarout as $p) {
137  //echo "tar path is:$p\n";
138  $tpaths[] = rtrim($p);
139  }
140  foreach ($Rtout as $path) {
141  $Rtpaths[] = rtrim($path);
142  }
143  sort($tpaths);
144  sort($Rtpaths);
145  $diffs = array_diff($tpaths, $Rtpaths);
146  if (empty($diffs)) {
147  $this->pass();
148  } else {
149  echo "diffs are:\n";
150  $this->dump($diffs);
151  $this->fail();
152  }
153  }
154 }
155