#!/usr/bin/perl -w
#
# Tests for error handling in k5start.
#
# Written by Russ Allbery <rra@stanford.edu>
# Copyright 2011
#     The Board of Trustees of the Leland Stanford Junior University
#
# See LICENSE for licensing terms.

use Test::More;

# The full path to the newly-built k5start client.
our $K5START = "$ENV{BUILD}/../k5start";

# Load our test utility programs.
require "$ENV{SOURCE}/libtest.pl";

# Don't overwrite the user's ticket cache.
$ENV{KRB5CCNAME} = 'krb5cc_test';

# Test invalid options.
our @OPTIONS = (
    [ [ qw/-H 0/        ], '-H limit argument 0 invalid' ],
    [ [ qw/-H -1/       ], '-H limit argument -1 invalid' ],
    [ [ qw/-H 4foo/     ], '-H limit argument 4foo invalid' ],
    [ [ qw/-K 4foo/     ], '-K interval argument 4foo invalid' ],
    [ [ qw/-H4 -Uf a a/ ], '-H option cannot be used with a command' ]
);

# Test plan.
plan tests => scalar (@OPTIONS) * 3;

# Run the invalid option tests.
for my $opt (@OPTIONS) {
    my ($out, $err, $status) = command ($K5START, @{ $opt->[0] });
    is ($status, 1, "k5start @{ $opt->[0] } fails");
    is ($out, '', ' with no output');
    is ($err, 'k5start: ' . $opt->[1] . "\n", ' and correct error');
}
