int general_socket;
static bool exit_upon_signal = false;
+static bool run_once = false;
cfg_t *cfg, *cfg_general, *cfg_section;
CFG_END()};
char *configfile = NULL;
- int o, option_index = 0;
+ int opt, option_index = 0;
struct option long_options[] = {
{"config", required_argument, 0, 'c'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
+ {"run-once", no_argument, 0, 0},
{0, 0, 0, 0}};
struct sigaction action;
if (setlocale(LC_ALL, "") == NULL)
die("Could not set locale. Please make sure all your LC_* / LANG settings are correct.");
- while ((o = getopt_long(argc, argv, "c:hv", long_options, &option_index)) != -1)
- if ((char)o == 'c')
- configfile = optarg;
- else if ((char)o == 'h') {
- printf("i3status " VERSION " © 2008 Michael Stapelberg and contributors\n"
- "Syntax: %s [-c <configfile>] [-h] [-v]\n",
- argv[0]);
- return 0;
- } else if ((char)o == 'v') {
- printf("i3status " VERSION " © 2008 Michael Stapelberg and contributors\n");
- return 0;
+ while ((opt = getopt_long(argc, argv, "c:hv", long_options, &option_index)) != -1) {
+ switch (opt) {
+ case 'c':
+ configfile = optarg;
+ break;
+ case 'h':
+ printf("i3status " VERSION " © 2008 Michael Stapelberg and contributors\n"
+ "Syntax: %s [-c <configfile>] [-h] [-v]\n",
+ argv[0]);
+ return 0;
+ break;
+ case 'v':
+ printf("i3status " VERSION " © 2008 Michael Stapelberg and contributors\n");
+ return 0;
+ break;
+ case 0:
+ if (strcmp(long_options[option_index].name, "run-once") == 0) {
+ run_once = true;
+ }
+ break;
}
+ }
if (configfile == NULL)
configfile = get_config_path();
printf("\n");
fflush(stdout);
+ if (run_once) {
+ break;
+ }
+
/* To provide updates on every full second (as good as possible)
* we don’t use sleep(interval) but we sleep until the next
* second (with microsecond precision) plus (interval-1)
--- /dev/null
+#!/usr/bin/env perl
+
+use v5.10;
+use strict;
+use warnings;
+use Term::ANSIColor qw(:constants);
+use File::Basename;
+
+sub TestCase {
+ my ($dir) = @_;
+ my $conf = "$dir/i3status.conf";
+ my $testres = `./i3status --run-once -c $conf`;
+ my $refres = "";
+
+ if ( -f "@_/expected_output.txt") {
+ $refres = `cat "@_/expected_output.txt"`;
+ } elsif ( -f "@_/expected_output.sh") {
+ $refres = `bash @_/expected_output.sh`;
+ }
+
+ if ( "$testres" eq "$refres" ) {
+ say "Testing test case '", basename($dir), "'… ", BOLD, GREEN, "OK", RESET;
+ return 1;
+ } else {
+ say "Testing test case '", basename($dir), "'… ", BOLD, RED, "Failed!", RESET;
+ return 0;
+ }
+}
+
+
+my $testcases = 'testcases';
+my $testresults = 1;
+
+opendir(my $dir, $testcases) or die "Could not open directory $testcases: $!";
+
+while (my $entry = readdir($dir)) {
+ next unless (-d "$testcases/$entry");
+ next if ($entry =~ m/^\./);
+ $testresults = $testresults && TestCase("$testcases/$entry");
+}
+closedir($dir);
+exit 0;