7 # Make all the assert_* methods easily accessible.
8 include Test
::Unit::Assertions # rubocop:disable Style/MixinUsage
10 # Force UTF-8. Ruby will default to the system locale, and if it is
11 # non-UTF-8, String-methods will fail when operating on non-ASCII
13 Encoding
.default_external
= Encoding
::UTF_8
14 Encoding
.default_internal
= Encoding
::UTF_8
16 GIT_DIR
= `git rev-parse --show-toplevel`.freeze
18 0, $CHILD_STATUS.exitstatus
,
19 "Failed to find Tails' Git root; this command must be run " \
20 'inside Tails Git repo'
23 def rfc2822_date
?(date
)
24 !DateTime
.rfc2822(date
).nil?
29 def page_meta_date_is_ok
?(path
)
30 meta_date_post_re
= /^\[\[!meta\s+date="(?<date>.*)"\]\]$/
32 content_lines
= File
.new(path
).read
.split("\n")
33 matches
= content_lines
.grep(meta_date_post_re
)
35 warn
"#{path}: has #{matches.size} well-formed 'meta date' " \
36 'directives (must be 1)'
39 meta_date_line
= matches
.first
40 m
= meta_date_post_re
.match(meta_date_line
)
42 unless rfc2822_date
?(meta_date
)
43 warn
"#{path}: 'meta date' directive contains non-rfc2822 " \
51 def po_file_meta_date_is_ok
?(path
)
52 meta_date_po_re_str
= '\[\[!meta\s+date=\\\"(?<date>.*)\\\"\]\]\\\n'
54 content_lines
= File
.new(path
).read
.split("\n")
55 matches
= content_lines
.grep(Regexp
.new("^msgid \"#{meta_date_po_re_str}\"$"))
57 warn
"#{path}: has #{matches.size} 'meta date' msgid:s (must be 1)"
61 msgid_index
= content_lines
.find_index(msgid
)
62 msgstr_index
= msgid_index
+ 1
63 msgstr_line
= content_lines
[msgstr_index
]
64 m
= Regexp
.new("^msgstr \"(?:#{meta_date_po_re_str})?\"$")
67 warn
"#{path}: the 'meta date' msgid is not followed by a msgstr"
71 unless rfc2822_date
?(meta_date
)
72 warn
"#{path}: 'meta date' msgstr contains non-rfc2822 " \
85 meta_date_sorted_pages
=
86 Dir
.glob('wiki/src/{news,security,security/audits}/*.{mdwn,html}') - [
87 'wiki/src/security/audits.mdwn',
88 'wiki/src/security/fixed.mdwn',
91 meta_date_sorted_pages
.each
do |post_path
|
92 success
= false unless page_meta_date_is_ok
?(post_path
)
93 basename
= post_path
.sub(/.(html|mdwn)$/, '')
94 Dir
.glob("#{basename}.*.po").each
do |po_path
|
95 success
= false unless po_file_meta_date_is_ok
?(po_path
)