[Buildroot] [RFC 1/4] support/testing: add perl test

Ricardo Martincoski ricardo.martincoski at gmail.com
Thu Nov 22 02:39:23 UTC 2018


Hello,

On Wed, Nov 21, 2018 at 02:26 PM, François Perrad wrote:

> Le lun. 19 nov. 2018 à 02:11, Ricardo Martincoski <
> ricardo.martincoski at gmail.com> a écrit :
[snip]
>> > +        cmd = "perl -v"
>>
>> What about using this instead?
>>         cmd = "perl -v | grep 'This is perl 5'"
>>
> 
> As tester, I don't like this kind of code, because I never know which exit
> code is available, the one from perl or the one from grep.
> Code written for test must be obvious.
> See the following example:
> 
> #!/usr/bin/env python
> import unittest
> import subprocess
> 
> class DeveloperWay(unittest.TestCase):
>     def testPerl(self):
>         retcode = subprocess.call("perl -v | grep 'This is perl 5'",
> shell=True)
>         self.assertEqual(retcode, 0)
> 
> class TesterWay(unittest.TestCase):
>     def testPerl(self):
>         retcode = subprocess.call('perl -v', shell=True)
>         self.assertEqual(retcode, 0)
>         output = subprocess.check_output('perl -v', shell=True)
>         self.assert_('This is perl 5' in output)
> 
> unittest.main()

Sure. Much better to have an error message that makes obvious what failed.


Regards,
Ricardo


More information about the buildroot mailing list