Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/xlint lint: ensure that '# line' directives in...



details:   https://anonhg.NetBSD.org/src/rev/e111b40e60ec
branches:  trunk
changeset: 952901:e111b40e60ec
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Feb 20 22:18:32 2021 +0000

description:
lint: ensure that '# line' directives in tests are correct

It's too easy to forget one of them when adding or removing some lines.
This would make it more difficult to locate the lines referenced in the
error messages.

diffstat:

 tests/usr.bin/xlint/check-expect.lua |  14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diffs (43 lines):

diff -r c6c311ceb895 -r e111b40e60ec tests/usr.bin/xlint/check-expect.lua
--- a/tests/usr.bin/xlint/check-expect.lua      Sat Feb 20 20:30:06 2021 +0000
+++ b/tests/usr.bin/xlint/check-expect.lua      Sat Feb 20 22:18:32 2021 +0000
@@ -1,5 +1,5 @@
 #!  /usr/bin/lua
--- $NetBSD: check-expect.lua,v 1.2 2021/01/16 15:02:11 rillig Exp $
+-- $NetBSD: check-expect.lua,v 1.3 2021/02/20 22:18:32 rillig Exp $
 
 --[[
 
@@ -25,7 +25,7 @@
   return lines
 end
 
-local function load_expect_comments_from_c(fname)
+local function load_expect_comments_from_c(fname, errors)
 
   local lines = load_lines(fname)
   if lines == nil then return nil end
@@ -41,6 +41,14 @@
       end
     end
     comments_by_line[lineno] = comments_in_line
+
+    local pp_lineno, pp_fname = line:match("^#%s*(%d+)%s+\"([^\"]+)\"")
+    if pp_lineno ~= nil then
+      if pp_fname == fname and tonumber(pp_lineno) ~= lineno + 1 then
+        errors:add("error: %s:%d: preprocessor line number must be %d",
+          fname, lineno, lineno + 1)
+      end
+    end
   end
 
   if seen_comment then return comments_by_line else return nil end
@@ -69,7 +77,7 @@
 
 local function check_test(c_fname, errors)
   local exp_fname = c_fname:gsub("%.c$", ".exp")
-  local comments = load_expect_comments_from_c(c_fname)
+  local comments = load_expect_comments_from_c(c_fname, errors)
   if comments == nil or #comments == 0 then return end
   local messages = load_actual_messages_from_exp(exp_fname)
   if messages == nil then return end



Home | Main Index | Thread Index | Old Index