-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an error message for failures of analyzing dependencies
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import platform | ||
import textwrap | ||
import unittest | ||
from typing import * | ||
|
||
import onlinejudge_verify.languages.cplusplus as cplusplus | ||
import tests.utils | ||
|
||
|
||
class TestCPlusPlusListDependencies(unittest.TestCase): | ||
def test_success(self) -> None: | ||
files = { | ||
'main.cpp': textwrap.dedent("""\ | ||
#include "included.hpp" | ||
""").encode(), | ||
'included.hpp': textwrap.dedent("""\ | ||
int main() {} | ||
""").encode(), | ||
} | ||
|
||
with tests.utils.load_files(files) as tempdir: | ||
with tests.utils.chdir(tempdir): | ||
expected = sorted([tempdir / 'main.cpp', tempdir / 'included.hpp']) | ||
actual = sorted(cplusplus.CPlusPlusLanguage().list_dependencies(tempdir / 'main.cpp', basedir=tempdir)) | ||
self.assertEqual(actual, expected) | ||
|
||
@unittest.skipIf(platform.system() == 'Windows', "The path separator should be '/' for this test.") | ||
def test_failure_with_backslash(self) -> None: | ||
files = { | ||
'main.cpp': textwrap.dedent("""\ | ||
#include ".\included.hpp" | ||
""").encode(), | ||
'included.hpp': textwrap.dedent("""\ | ||
int main() {} | ||
""").encode(), | ||
} | ||
|
||
with tests.utils.load_files(files={}) as tempdir: | ||
with tests.utils.chdir(tempdir): | ||
self.assertRaises(Exception, lambda: cplusplus.CPlusPlusLanguage().list_dependencies(tempdir / 'main.cpp', basedir=tempdir)) | ||
|
||
@unittest.skipIf(platform.system() in ('Windows', 'Darwin'), "The filesystem should be case-sensitive for this test.") | ||
def test_failure_with_case_insensitive(self) -> None: | ||
files = { | ||
'main.cpp': textwrap.dedent("""\ | ||
#include "INCLUDED.HPP" | ||
""").encode(), | ||
'included.hpp': textwrap.dedent("""\ | ||
int main() {} | ||
""").encode(), | ||
} | ||
|
||
with tests.utils.load_files(files={}) as tempdir: | ||
with tests.utils.chdir(tempdir): | ||
self.assertRaises(Exception, lambda: cplusplus.CPlusPlusLanguage().list_dependencies(tempdir / 'main.cpp', basedir=tempdir)) |