blob: 9b289e111e2bb44edb3d3395d0688a9a8441f773 [file] [log] [blame]
Mike Frysingerf7c51602019-06-18 17:23:39 -04001# -*- 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
Mike Frysinger87deaef2019-07-26 21:14:55 -040017"""Unittests for the project.py module."""
18
19from __future__ import print_function
20
Mike Frysingerf7c51602019-06-18 17:23:39 -040021import unittest
22
23import project
24
25
26class RepoHookShebang(unittest.TestCase):
27 """Check shebang parsing in RepoHook."""
28
29 def test_no_shebang(self):
30 """Lines w/out shebangs should be rejected."""
31 DATA = (
32 '',
33 '# -*- coding:utf-8 -*-\n',
34 '#\n# foo\n',
35 '# Bad shebang in script\n#!/foo\n'
36 )
37 for data in DATA:
38 self.assertIsNone(project.RepoHook._ExtractInterpFromShebang(data))
39
40 def test_direct_interp(self):
41 """Lines whose shebang points directly to the interpreter."""
42 DATA = (
43 ('#!/foo', '/foo'),
44 ('#! /foo', '/foo'),
45 ('#!/bin/foo ', '/bin/foo'),
46 ('#! /usr/foo ', '/usr/foo'),
47 ('#! /usr/foo -args', '/usr/foo'),
48 )
49 for shebang, interp in DATA:
50 self.assertEqual(project.RepoHook._ExtractInterpFromShebang(shebang),
51 interp)
52
53 def test_env_interp(self):
54 """Lines whose shebang launches through `env`."""
55 DATA = (
56 ('#!/usr/bin/env foo', 'foo'),
57 ('#!/bin/env foo', 'foo'),
58 ('#! /bin/env /bin/foo ', '/bin/foo'),
59 )
60 for shebang, interp in DATA:
61 self.assertEqual(project.RepoHook._ExtractInterpFromShebang(shebang),
62 interp)