File: gen_test_data.pl

package info (click to toggle)
liblocale-gettext-perl 1.07-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 140 kB
  • ctags: 21
  • sloc: perl: 248; makefile: 16
file content (67 lines) | stat: -rw-r--r-- 1,601 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use strict;

sub gen {
	my ($domain) = @_;

	my $messages;
	my $language;
	unless (open(LOCALE, "locale|")) {
		doskip();
	}
	while (<LOCALE>) {
		if (/^LC_MESSAGES=\"(.*)\"$/) {
			$messages = $1;
		} elsif (/^LC_MESSAGES=(.*)$/) {
			$messages = $1;
		} elsif (/^LANGUAGE=\"(.*)\"$/) {
			$language = $1;
		} elsif (/^LANGUAGE=(.*)$/) {
			$language = $1;
		}
	}
	close LOCALE;
	if ($? != 0) {
		doskip();
	}

	if (!defined($messages)) {
		skip("cannot run test without a locale set", 0);
		exit 0;
	}
	if ($messages eq 'C') {
		skip("cannot run test in the C locale", 0);
		exit 0;
	}
	if ($messages eq 'POSIX') {
		skip("cannot run test in the POSIX locale", 0);
		exit 0;
	}
	if (defined($language) && $language) {
		# In GNU gettext, $LANGUAGE overrides
		# all the other environment variables,
		# for message translations only.
		# https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html#The-LANGUAGE-variable
		# The library will look first for the first entry in
		# that list, so give it what it wants.
		$messages = (split(':', $language))[0];
	}

	mkdir "test_data/" . $messages, 0755 unless (-d "test_data/" . $messages);
	mkdir "test_data/" . $messages . "/LC_MESSAGES", 0755
		unless (-d "test_data/" . $messages . "/LC_MESSAGES");
	unless (-r ("test_data/" . $messages . "/LC_MESSAGES/" . $domain . ".mo")) {
		system "msgfmt", "-o", "test_data/" . $messages . "/LC_MESSAGES/" .
			$domain . ".mo",
			"test_data/" . $domain . ".po";
		if ($? != 0) {
			doskip();
		}
	}
}

sub doskip {
	skip("could not generate test data, skipping test", 0);
	exit 0;
}

1;