From 31ca877242fcd9f787d6f11e3a12f89c6301a999 Mon Sep 17 00:00:00 2001
From: Bruce Dawson <brucedawson@chromium.org>
Date: Fri, 18 Nov 2022 17:03:14 +0000
Subject: [PATCH] Fix CheckLicense tests

A last minute change to the CheckLicense tests in crrev.com/c/4032366
used the _GetLicenseText function in the wrong place, thus neutering one
test and duplicating code in another. This fixes the tests so that they
minimize duplication and actually test the CSS/C style comments.

Change-Id: Ibbe880dec8d1e85416ed1b7ce94922c6f2c2a543
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4037103
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
---
 tests/presubmit_unittest.py | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py
index f1e831502..c77a41a26 100755
--- a/tests/presubmit_unittest.py
+++ b/tests/presubmit_unittest.py
@@ -2354,14 +2354,7 @@ the current line as well!
     self._LicenseCheck(text, license_text, True, None, accept_empty_files=True)
 
   def testCheckLicenseNewFilePass(self):
-    current_year = int(time.strftime('%Y'))
-    text = (
-        "#!/bin/python\n"
-        "# Copyright %d The Chromium Authors\n"
-        "# Use of this source code is governed by a BSD-style license that can "
-        "be\n"
-        "# found in the LICENSE file.\n"
-        "print('foo')\n" % current_year)
+    text = self._GetLicenseText(int(time.strftime('%Y')))
     license_text = None
     self._LicenseCheck(text, license_text, False, None, new_file=True)
 
@@ -2403,7 +2396,15 @@ the current line as well!
                        new_file=True)
 
   def testCheckLicenseNewCSSFilePass(self):
-    text = self._GetLicenseText(int(time.strftime('%Y')))
+    # Check that CSS-style comments in license text are supported.
+    current_year = int(time.strftime('%Y'))
+    text = (
+        "/* Copyright %d The Chromium Authors\n"
+        " * Use of this source code is governed by a BSD-style license that "
+        "can be\n"
+        "* found in the LICENSE file. */\n"
+        "\n"
+        "h1 {}\n" % current_year)
     license_text = None
     self._LicenseCheck(text, license_text, False, None, new_file=True)