diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_project.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/test_project.py b/tests/test_project.py new file mode 100644 index 00000000..1d9cde45 --- /dev/null +++ b/tests/test_project.py | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | # -*- coding:utf-8 -*- | ||
| 2 | # | ||
| 3 | # Copyright (C) 2019 The Android Open Source Project | ||
| 4 | # | ||
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 6 | # you may not use this file except in compliance with the License. | ||
| 7 | # You may obtain a copy of the License at | ||
| 8 | # | ||
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | # | ||
| 11 | # Unless required by applicable law or agreed to in writing, software | ||
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 14 | # See the License for the specific language governing permissions and | ||
| 15 | # limitations under the License. | ||
| 16 | |||
| 17 | import unittest | ||
| 18 | |||
| 19 | import project | ||
| 20 | |||
| 21 | |||
| 22 | class RepoHookShebang(unittest.TestCase): | ||
| 23 | """Check shebang parsing in RepoHook.""" | ||
| 24 | |||
| 25 | def test_no_shebang(self): | ||
| 26 | """Lines w/out shebangs should be rejected.""" | ||
| 27 | DATA = ( | ||
| 28 | '', | ||
| 29 | '# -*- coding:utf-8 -*-\n', | ||
| 30 | '#\n# foo\n', | ||
| 31 | '# Bad shebang in script\n#!/foo\n' | ||
| 32 | ) | ||
| 33 | for data in DATA: | ||
| 34 | self.assertIsNone(project.RepoHook._ExtractInterpFromShebang(data)) | ||
| 35 | |||
| 36 | def test_direct_interp(self): | ||
| 37 | """Lines whose shebang points directly to the interpreter.""" | ||
| 38 | DATA = ( | ||
| 39 | ('#!/foo', '/foo'), | ||
| 40 | ('#! /foo', '/foo'), | ||
| 41 | ('#!/bin/foo ', '/bin/foo'), | ||
| 42 | ('#! /usr/foo ', '/usr/foo'), | ||
| 43 | ('#! /usr/foo -args', '/usr/foo'), | ||
| 44 | ) | ||
| 45 | for shebang, interp in DATA: | ||
| 46 | self.assertEqual(project.RepoHook._ExtractInterpFromShebang(shebang), | ||
| 47 | interp) | ||
| 48 | |||
| 49 | def test_env_interp(self): | ||
| 50 | """Lines whose shebang launches through `env`.""" | ||
| 51 | DATA = ( | ||
| 52 | ('#!/usr/bin/env foo', 'foo'), | ||
| 53 | ('#!/bin/env foo', 'foo'), | ||
| 54 | ('#! /bin/env /bin/foo ', '/bin/foo'), | ||
| 55 | ) | ||
| 56 | for shebang, interp in DATA: | ||
| 57 | self.assertEqual(project.RepoHook._ExtractInterpFromShebang(shebang), | ||
| 58 | interp) | ||
