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