Repository: spack/spack

Issue:
Failure in the tests for false positives in Makefiles
I ran unit tests on `develop` at c0855d9bd54be07162435cec605a1ad5efe1e4d1 and two tests failed on my system.



### Steps to reproduce the issue

```console
$ spack test -k  test_negative_make_check
```

### Error Message

The error message I got is the following:
```console
$ spack test -k test_negative_make_check
============================================================== test session starts ===============================================================
platform linux2 -- Python 2.7.15rc1, pytest-3.2.5, py-1.4.34, pluggy-0.4.0
rootdir: /home/mculpo/PycharmProjects/spack/lib/spack/spack/test, inifile: pytest.ini
collected 1258 items                                                                                                                              

build_systems.py .FEFE
============================================================ short test summary info =============================================================
FAIL build_systems.py::test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/partial_match]
FAIL build_systems.py::test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/variable]
ERROR build_systems.py::test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/partial_match]
ERROR build_systems.py::test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/variable]

=========================================================== slowest 20 test durations ============================================================
0.17s call     build_systems.py::test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/no_makefile]
0.08s call     build_systems.py::test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/partial_match]
0.08s call     build_systems.py::test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/variable]
0.04s setup    build_systems.py::test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/no_makefile]
0.00s setup    build_systems.py::test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/variable]
0.00s setup    build_systems.py::test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/partial_match]
0.00s teardown build_systems.py::test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/partial_match]
0.00s teardown build_systems.py::test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/variable]
0.00s teardown build_systems.py::test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/no_makefile]
===================================================================== ERRORS =====================================================================
____ ERROR at teardown of test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/partial_match] _____

    @pytest.fixture(scope='function', autouse=True)
    def no_chdir():
        """Ensure that no test changes Spack's working dirctory.
    
        This prevents Spack tests (and therefore Spack commands) from
        changing the working directory and causing other tests to fail
        mysteriously. Tests should use ``working_dir`` or ``py.path``'s
        ``.as_cwd()`` instead of ``os.chdir`` to avoid failing this check.
    
        We assert that the working directory hasn't changed, unless the
        original wd somehow ceased to exist.
    
        """
        original_wd = os.getcwd()
        yield
        if os.path.isdir(original_wd):
>           assert os.getcwd() == original_wd
E           AssertionError: assert '/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/partial_match' == '/home/mculpo/PycharmProjects/spack/lib/spack/spack/test'
E            +  where '/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/partial_match' = <built-in function getcwd>()
E            +    where <built-in function getcwd> = os.getcwd

../../../../conftest.py:104: AssertionError
_______ ERROR at teardown of test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/variable] _______

    @pytest.fixture(scope='function', autouse=True)
    def no_chdir():
        """Ensure that no test changes Spack's working dirctory.
    
        This prevents Spack tests (and therefore Spack commands) from
        changing the working directory and causing other tests to fail
        mysteriously. Tests should use ``working_dir`` or ``py.path``'s
        ``.as_cwd()`` instead of ``os.chdir`` to avoid failing this check.
    
        We assert that the working directory hasn't changed, unless the
        original wd somehow ceased to exist.
    
        """
        original_wd = os.getcwd()
        yield
        if os.path.isdir(original_wd):
>           assert os.getcwd() == original_wd
E           AssertionError: assert '/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/variable' == '/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/partial_match'
E            +  where '/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/variable' = <built-in function getcwd>()
E            +    where <built-in function getcwd> = os.getcwd

../../../../conftest.py:104: AssertionError
==================================================================== FAILURES ====================================================================
_______________ test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/partial_match] _______________

directory = '/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/partial_match'
config = <spack.config.Configuration object at 0x7fa08e328b50>, mock_packages = None

    @pytest.mark.parametrize(
        'directory',
        glob.iglob(os.path.join(DATA_PATH, 'make', 'negative', '*'))
    )
    def test_negative_make_check(directory, config, mock_packages):
        """Tests that Spack correctly ignores false positives in a Makefile."""
    
        # Get a fake package
        s = Spec('mpich')
        s.concretize()
        pkg = spack.repo.get(s)
        setup_package(pkg, False)
    
        with working_dir(directory):
>           assert not pkg._has_make_target('check')
E           AssertionError: assert not True
E            +  where True = <bound method Mpich._has_make_target of <spack.pkg.builtin.mock.mpich.Mpich object at 0x7fa08e174510>>('check')
E            +    where <bound method Mpich._has_make_target of <spack.pkg.builtin.mock.mpich.Mpich object at 0x7fa08e174510>> = <spack.pkg.builtin.mock.mpich.Mpich object at 0x7fa08e174510>._has_make_target

../../../../build_systems.py:72: AssertionError
_________________ test_negative_make_check[/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/variable] __________________

directory = '/home/mculpo/PycharmProjects/spack/lib/spack/spack/test/data/make/negative/variable'
config = <spack.config.Configuration object at 0x7fa08e328b50>, mock_packages = None

    @pytest.mark.parametrize(
        'directory',
        glob.iglob(os.path.join(DATA_PATH, 'make', 'negative', '*'))
    )
    def test_negative_make_check(directory, config, mock_packages):
        """Tests that Spack correctly ignores false positives in a Makefile."""
    
        # Get a fake package
        s = Spec('mpich')
        s.concretize()
        pkg = spack.repo.get(s)
        setup_package(pkg, False)
    
        with working_dir(directory):
>           assert not pkg._has_make_target('check')
E           AssertionError: assert not True
E            +  where True = <bound method Mpich._has_make_target of <spack.pkg.builtin.mock.mpich.Mpich object at 0x7fa08e2bb190>>('check')
E            +    where <bound method Mpich._has_make_target of <spack.pkg.builtin.mock.mpich.Mpich object at 0x7fa08e2bb190>> = <spack.pkg.builtin.mock.mpich.Mpich object at 0x7fa08e2bb190>._has_make_target

../../../../build_systems.py:72: AssertionError
============================================================= 1255 tests deselected ==============================================================
========================================== 2 failed, 1 passed, 1255 deselected, 2 error in 1.46 seconds ==========================================
```
We have the same error on python 3.7 in Travis (see [here](https://travis-ci.org/spack/spack/jobs/418898260)). Looking into it it seems to be due to the string we are looking for, that in some cases uses the character `'` instead of the backtick.

### Information on your system

```console
$ lsb_release -a && echo && uname -a && echo && make --version
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.1 LTS
Release:	18.04
Codename:	bionic

Linux nuvolari 4.15.0-32-generic #35-Ubuntu SMP Fri Aug 10 17:58:07 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
```





Discussion:
@adamjstewart I'll try to submit a fix by today.

Resolving patch:
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py
--- a/lib/spack/spack/package.py
+++ b/lib/spack/spack/package.py
@@ -1166,11 +1166,13 @@ def _has_make_target(self, target):
         #
         # GNU Make:
         #     make: *** No rule to make target `test'.  Stop.
+        #           *** No rule to make target 'test'.  Stop.
         #
         # BSD Make:
         #     make: don't know how to make test. Stop
         missing_target_msgs = [
             "No rule to make target `{0}'.  Stop.",
+            "No rule to make target '{0}'.  Stop.",
             "don't know how to make {0}. Stop",
         ]
 


Test patch:
diff --git a/lib/spack/spack/test/build_systems.py b/lib/spack/spack/test/build_systems.py
--- a/lib/spack/spack/test/build_systems.py
+++ b/lib/spack/spack/test/build_systems.py
@@ -59,6 +59,7 @@ def test_affirmative_make_check(directory, config, mock_packages):
     'directory',
     glob.iglob(os.path.join(DATA_PATH, 'make', 'negative', '*'))
 )
+@pytest.mark.regression('9067')
 def test_negative_make_check(directory, config, mock_packages):
     """Tests that Spack correctly ignores false positives in a Makefile."""