nstrftime, c-nstrftime tests: Avoid test failures on native Windows.
[gnulib.git] / tests / test-libtextstyle.c
blob67aaa7ca244b4ac39c3d092a98e1b82b76ccd175
1 /* Ad-hoc testing program for GNU libtextstyle.
2 Copyright (C) 2018-2024 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2018.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 #include <config.h>
20 #include <textstyle.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
27 int
28 main (int argc, char *argv[])
30 const char *program_name = argv[0];
31 int i;
33 /* Parse the command-line arguments. */
34 for (i = 1; i < argc; i++)
36 const char *arg = argv[i];
37 if (strncmp (arg, "--color=", 8) == 0)
38 handle_color_option (arg + 8);
39 else if (strncmp (arg, "--style=", 8) == 0)
40 handle_style_option (arg + 8);
41 else if (arg[0] == '-')
43 fprintf (stderr, "%s: invalid argument: %s\n", program_name, arg);
44 exit (1);
46 else
47 /* Handle non-option arguments here. */
51 /* Handle the --color=test special argument. */
52 if (color_test_mode)
54 print_color_test ();
55 exit (0);
58 #if HAVE_LIBTEXTSTYLE
59 if (color_mode == color_yes
60 || (color_mode == color_tty
61 && isatty (STDOUT_FILENO)
62 && getenv ("NO_COLOR") == NULL)
63 || color_mode == color_html)
65 /* If no style file is explicitly specified, use the default in the
66 source directory. */
67 if (style_file_name == NULL)
68 style_file_name = SRCDIR "test-libtextstyle-default.css";
70 else
71 /* No styling. */
72 style_file_name = NULL;
73 #endif
75 /* Create a terminal output stream that uses this style file. */
76 styled_ostream_t stream =
77 (color_mode == color_html
78 ? html_styled_ostream_create (file_ostream_create (stdout),
79 style_file_name)
80 : styled_ostream_create (STDOUT_FILENO, "(stdout)", TTYCTL_AUTO,
81 style_file_name));
83 ostream_write_str (stream, "Hello ");
85 /* Associate the entire full name in CSS class 'name'. */
86 styled_ostream_begin_use_class (stream, "name");
88 ostream_write_str (stream, "Dr. ");
89 styled_ostream_begin_use_class (stream, "boy-name");
90 ostream_write_str (stream, "Linus");
91 styled_ostream_end_use_class (stream, "boy-name");
92 ostream_write_str (stream, " Pauling");
94 /* Terminate the name. */
95 styled_ostream_end_use_class (stream, "name");
97 ostream_write_str (stream, "!\n");
99 /* Flush and close the terminal stream. */
100 styled_ostream_free (stream);
102 return 0;