blob: 517ddd808c5c361b2e539d2eb7b8a255a0a223bd [file] [log] [blame] [edit]
"""Tests for ninja_utils."""
from __future__ import absolute_import
import os
import sys
import unittest
# Allow imports from cq/scripts folder
sys.path.insert(0, os.path.realpath(os.path.join(
os.path.dirname(__file__), os.pardir)))
from helpers import ninja_utils
class NinjaUtilsTest(unittest.TestCase):
def testSingleError(self):
"""Test the comments generated for a single error."""
ninja_output = (
'[1/230] CXX obj/test/test.o\n'
'FAILED: obj test/test.o\n'
'../prebuilt/toolchain/mips32r1/bin/mipsel-buildroot-linux-uclibc-g++'
' -MMD -MF obj/test/test1.o -DV8 -fno\n'
'In file included from ../../path/to/file:58:0,\n'
'This line is expected.\n'
'This line is also expected.\n'
'[2/230] CXX obj/test/test.o\n')
expected_comments = ['This line is expected.\nThis line is also expected.']
self.assertEqual(expected_comments,
ninja_utils.ninja_failure_to_comments(ninja_output))
def testMultipleErrors(self):
"""Test the comments generated from multiple different errors."""
ninja_output = (
'[1/230] CXX obj/test/test.o\n'
'FAILED: obj test/test1.o\n'
'../prebuilt/toolchain/mips32r1/bin/mipsel-buildroot-linux-uclibc-g++'
' -MMD -MF obj/test/test1.o -DV8 -fno\n'
'In file included from ../../path/to/file:58:0,\n'
'This line is expected.\n'
'This line is also expected.\n'
'[2/230] CXX obj/test/test.o\n'
'FAILED: obj test/test2.o\n'
'../prebuilt/toolchain/mips32r1/bin/mipsel-buildroot-linux-uclibc-g++'
' -MMD -MF obj/test/test1.o -DV8 -fno\n'
'In file included from ../../path/to/file:58:0,\n'
'This line is expected again.\n'
'This line is also expected again.\n'
'[3/230] CXX obj/test/test3.o\n')
expected_comments = [
'This line is expected.\nThis line is also expected.',
'This line is expected again.\nThis line is also expected again.'
]
self.assertEqual(
set(expected_comments),
set(ninja_utils.ninja_failure_to_comments(ninja_output)))
def testNoErrors(self):
"""Test that no comments are generated if there are no errors."""
ninja_output = (
'[1/230] CXX obj/test/test.o\n'
'[2/230] CXX obj/test/test.o\n'
'Unknown warming that is not handled.\n'
'file: error something failed\n')
expected_comments = []
self.assertEqual(expected_comments,
ninja_utils.ninja_failure_to_comments(ninja_output))
def testMaxErrors(self):
"""Test that max_errors limits the errors correctly."""
ninja_output = (
'FAILED: obj test/test1.o\n'
'This line might be in the comments.\n'
'[2/230] CXX obj/test/test.o\n'
'FAILED: obj test/test2.o\n'
'This line might be in the comments. (But not both lines!).\n'
'[3/230] CXX obj/test/test3.o\n')
# Note that the particular comments that are saved are random.
actual_comments = ninja_utils.ninja_failure_to_comments(ninja_output,
max_errors=1)
self.assertEqual(2, len(actual_comments))
self.assertEqual(ninja_utils.NINJA_TOO_MANY_ERRORS_MSG, actual_comments[-1])
if __name__ == '__main__':
unittest.main()