head	1.2;
access;
symbols
	perseant-exfatfs-base-20250801:1.2
	perseant-exfatfs-base-20240630:1.2
	perseant-exfatfs:1.2.0.24
	perseant-exfatfs-base:1.2
	cjep_sun2x:1.2.0.22
	cjep_sun2x-base:1.2
	cjep_staticlib_x-base1:1.2
	cjep_staticlib_x:1.2.0.20
	cjep_staticlib_x-base:1.2
	phil-wifi-20200421:1.2
	phil-wifi-20200411:1.2
	phil-wifi-20200406:1.2
	pgoyette-compat-merge-20190127:1.2
	pgoyette-compat-20190127:1.2
	pgoyette-compat-20190118:1.2
	pgoyette-compat-1226:1.2
	pgoyette-compat-1126:1.2
	pgoyette-compat-1020:1.2
	pgoyette-compat-0930:1.2
	pgoyette-compat-0906:1.2
	pgoyette-compat-0728:1.2
	pgoyette-compat-0625:1.2
	pgoyette-compat-0521:1.2
	pgoyette-compat-0502:1.2
	pgoyette-compat-0422:1.2
	pgoyette-compat-0415:1.2
	pgoyette-compat-0407:1.2
	pgoyette-compat-0330:1.2
	pgoyette-compat-0322:1.2
	pgoyette-compat-0315:1.2
	pgoyette-compat:1.2.0.18
	pgoyette-compat-base:1.2
	perseant-stdc-iso10646:1.2.0.16
	perseant-stdc-iso10646-base:1.2
	prg-localcount2-base3:1.2
	prg-localcount2-base2:1.2
	prg-localcount2-base1:1.2
	prg-localcount2:1.2.0.14
	prg-localcount2-base:1.2
	pgoyette-localcount-20170426:1.2
	bouyer-socketcan-base1:1.2
	pgoyette-localcount-20170320:1.2
	bouyer-socketcan:1.2.0.12
	bouyer-socketcan-base:1.2
	pgoyette-localcount-20170107:1.2
	pgoyette-localcount-20161104:1.2
	localcount-20160914:1.2
	pgoyette-localcount-20160806:1.2
	pgoyette-localcount-20160726:1.2
	pgoyette-localcount:1.2.0.10
	pgoyette-localcount-base:1.2
	yamt-pagecache-base9:1.2
	yamt-pagecache-tag8:1.2
	tls-earlyentropy:1.2.0.6
	tls-earlyentropy-base:1.2
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.2
	riastradh-drm2-base3:1.2
	agc-symver:1.2.0.8
	agc-symver-base:1.2
	tls-maxphys-base:1.2
	yamt-pagecache-base8:1.2
	yamt-pagecache-base7:1.2
	yamt-pagecache-base6:1.2
	yamt-pagecache-base5:1.2
	yamt-pagecache-base4:1.2
	yamt-pagecache-base3:1.2
	yamt-pagecache-base2:1.2
	yamt-pagecache:1.2.0.4
	yamt-pagecache-base:1.2
	bouyer-quota2-nbase:1.2
	bouyer-quota2:1.2.0.2
	bouyer-quota2-base:1.2
	atf-0-10:1.1.1.3
	atf-0-9:1.1.1.2
	atf-0-8:1.1.1.2
	atf-0-7:1.1.1.1
	matt-premerge-20091211:1.1.1.1
	jym-xensuspend-nbase:1.1.1.1
	jym-xensuspend:1.1.1.1.0.2
	jym-xensuspend-base:1.1.1.1
	atf-0-6:1.1.1.1
	TNF:1.1.1;
locks; strict;
comment	@// @;


1.2
date	2010.10.20.09.17.23;	author jmmv;	state dead;
branches;
next	1.1;

1.1
date	2009.01.19.07.11.51;	author jmmv;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2009.01.19.07.11.51;	author jmmv;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	2010.05.08.08.05.21;	author jmmv;	state Exp;
branches;
next	1.1.1.3;

1.1.1.3
date	2010.07.03.08.04.50;	author jmmv;	state Exp;
branches;
next	;


desc
@@


1.2
log
@Resolve import conflicts.
@
text
@//
// Automated Testing Framework (atf)
//
// Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#if !defined(_ATF_CXX_PARSER_HPP_)
#define _ATF_CXX_PARSER_HPP_

#include <map>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>

namespace atf {
namespace parser {

// ------------------------------------------------------------------------
// The "parse_error" class.
// ------------------------------------------------------------------------

class parse_error : public std::runtime_error,
                    public std::pair< size_t, std::string > {
    mutable std::string m_msg;

public:
    parse_error(size_t, std::string);
    ~parse_error(void) throw();

    const char* what(void) const throw();
};

// ------------------------------------------------------------------------
// The "parse_errors" class.
// ------------------------------------------------------------------------

class parse_errors : public std::runtime_error,
                     public std::vector< parse_error > {
    std::vector< parse_error > m_errors;
    mutable std::string m_msg;

public:
    parse_errors(void);
    ~parse_errors(void) throw();

    const char* what(void) const throw();
};

// ------------------------------------------------------------------------
// The "token" class.
// ------------------------------------------------------------------------

typedef int token_type;

//!
//! \brief Representation of a read token.
//!
//! A pair that contains the information of a token read from a stream.
//! It contains the token's type and its associated data, if any.
//!
struct token {
    bool m_inited;
    size_t m_line;
    token_type m_type;
    std::string m_text;

public:
    token(void);
    token(size_t, const token_type&, const std::string& = "");

    size_t lineno(void) const;
    const token_type& type(void) const;
    const std::string& text(void) const;

    operator bool(void) const;
    bool operator!(void) const;
};

// ------------------------------------------------------------------------
// The "tokenizer" class.
// ------------------------------------------------------------------------

//!
//! \brief A stream tokenizer.
//!
//! This template implements an extremely simple, line-oriented stream
//! tokenizer.  It is only able to recognize one character-long delimiters,
//! random-length keywords, skip whitespace and, anything that does not
//! match these rules is supposed to be a word.
//!
//! Parameter IS: The input stream's type.
//!
template< class IS >
class tokenizer {
    IS& m_is;
    size_t m_lineno;
    token m_la;

    bool m_skipws;
    token_type m_eof_type, m_nl_type, m_text_type;

    std::map< char, token_type > m_delims_map;
    std::string m_delims_str;

    char m_quotech;
    token_type m_quotetype;

    std::map< std::string, token_type > m_keywords_map;

    token_type alloc_type(void);

    template< class TKZ >
    friend
    class parser;

public:
    tokenizer(IS&, bool, const token_type&, const token_type&,
              const token_type&, size_t = 1);

    size_t lineno(void) const;

    void add_delim(char, const token_type&);
    void add_keyword(const std::string&, const token_type&);
    void add_quote(char, const token_type&);

    token next(void);
    std::string rest_of_line(void);
};

template< class IS >
tokenizer< IS >::tokenizer(IS& p_is,
                           bool p_skipws,
                           const token_type& p_eof_type,
                           const token_type& p_nl_type,
                           const token_type& p_text_type,
                           size_t p_lineno) :
    m_is(p_is),
    m_lineno(p_lineno),
    m_skipws(p_skipws),
    m_eof_type(p_eof_type),
    m_nl_type(p_nl_type),
    m_text_type(p_text_type),
    m_quotech(-1)
{
}

template< class IS >
size_t
tokenizer< IS >::lineno(void)
    const
{
    return m_lineno;
}

template< class IS >
void
tokenizer< IS >::add_delim(char delim, const token_type& type)
{
    m_delims_map[delim] = type;
    m_delims_str += delim;
}

template< class IS >
void
tokenizer< IS >::add_keyword(const std::string& keyword,
                             const token_type& type)
{
    m_keywords_map[keyword] = type;
}

template< class IS >
void
tokenizer< IS >::add_quote(char ch, const token_type& type)
{
    m_quotech = ch;
    m_quotetype = type;
}

template< class IS >
token
tokenizer< IS >::next(void)
{
    if (m_la) {
        token t = m_la;
        m_la = token();
        if (t.type() == m_nl_type)
            m_lineno++;
        return t;
    }

    char ch;
    std::string text;

    bool done = false, quoted = false;
    token t(m_lineno, m_eof_type, "<<EOF>>");
    while (!done && m_is.get(ch).good()) {
        if (ch == m_quotech) {
            if (text.empty()) {
                bool escaped = false;
                while (!done && m_is.get(ch).good()) {
                    if (!escaped) {
                        if (ch == '\\')
                            escaped = true;
                        else if (ch == '\n') {
                            m_la = token(m_lineno, m_nl_type, "<<NEWLINE>>");
                            throw parse_error(t.lineno(),
                                              "Missing double quotes before "
                                              "end of line");
                        } else if (ch == m_quotech)
                            done = true;
                        else
                            text += ch;
                    } else {
                        text += ch;
                        escaped = false;
                    }
                }
                if (!m_is.good())
                    throw parse_error(t.lineno(),
                                      "Missing double quotes before "
                                      "end of file");
                t = token(m_lineno, m_text_type, text);
                quoted = true;
            } else {
                m_is.unget();
                done = true;
            }
        } else {
            typename std::map< char, token_type >::const_iterator idelim;
            idelim = m_delims_map.find(ch);
            if (idelim != m_delims_map.end()) {
                done = true;
                if (text.empty())
                    t = token(m_lineno, (*idelim).second,
                                   std::string("") + ch);
                else
                    m_is.unget();
            } else if (ch == '\n') {
                done = true;
                if (text.empty())
                    t = token(m_lineno, m_nl_type, "<<NEWLINE>>");
                else
                    m_is.unget();
            } else if (m_skipws && (ch == ' ' || ch == '\t')) {
                if (!text.empty())
                    done = true;
            } else
                text += ch;
        }
    }

    if (!quoted && !text.empty()) {
        typename std::map< std::string, token_type >::const_iterator ikw;
        ikw = m_keywords_map.find(text);
        if (ikw != m_keywords_map.end())
            t = token(m_lineno, (*ikw).second, text);
        else
            t = token(m_lineno, m_text_type, text);
    }

    if (t.type() == m_nl_type)
        m_lineno++;

    return t;
}

template< class IS >
std::string
tokenizer< IS >::rest_of_line(void)
{
    std::string str;
    while (m_is.good() && m_is.peek() != '\n')
        str += m_is.get();
    return str;
}

// ------------------------------------------------------------------------
// The "parser" class.
// ------------------------------------------------------------------------

template< class TKZ >
class parser {
    TKZ& m_tkz;
    token m_last;
    parse_errors m_errors;
    bool m_thrown;

public:
    parser(TKZ& tkz);
    ~parser(void);

    bool good(void) const;
    void add_error(const parse_error&);
    bool has_errors(void) const;

    token next(void);
    std::string rest_of_line(void);
    token reset(const token_type&);

    token
    expect(const token_type&,
           const std::string&);

    token
    expect(const token_type&,
           const token_type&,
           const std::string&);

    token
    expect(const token_type&,
           const token_type&,
           const token_type&,
           const std::string&);

    token
    expect(const token_type&,
           const token_type&,
           const token_type&,
           const token_type&,
           const std::string&);

    token
    expect(const token_type&,
           const token_type&,
           const token_type&,
           const token_type&,
           const token_type&,
           const token_type&,
           const token_type&,
           const std::string&);
};

template< class TKZ >
parser< TKZ >::parser(TKZ& tkz) :
    m_tkz(tkz),
    m_thrown(false)
{
}

template< class TKZ >
parser< TKZ >::~parser(void)
{
    if (!m_errors.empty() && !m_thrown)
        throw m_errors;
}

template< class TKZ >
bool
parser< TKZ >::good(void)
    const
{
    return m_tkz.m_is.good();
}

template< class TKZ >
void
parser< TKZ >::add_error(const parse_error& pe)
{
    m_errors.push_back(pe);
}

template< class TKZ >
bool
parser< TKZ >::has_errors(void)
    const
{
    return !m_errors.empty();
}

template< class TKZ >
token
parser< TKZ >::next(void)
{
    token t = m_tkz.next();

    m_last = t;

    if (t.type() == m_tkz.m_eof_type) {
        if (!m_errors.empty()) {
            m_thrown = true;
            throw m_errors;
        }
    }

    return t;
}

template< class TKZ >
std::string
parser< TKZ >::rest_of_line(void)
{
    return m_tkz.rest_of_line();
}

template< class TKZ >
token
parser< TKZ >::reset(const token_type& stop)
{
    token t = m_last;

    while (t.type() != m_tkz.m_eof_type && t.type() != stop)
        t = next();

    return t;
}

template< class TKZ >
token
parser< TKZ >::expect(const token_type& t1,
                      const std::string& textual)
{
    token t = next();

    if (t.type() != t1)
        throw parse_error(t.lineno(),
                          "Unexpected token `" + t.text() +
                          "'; expected " + textual);

    return t;
}

template< class TKZ >
token
parser< TKZ >::expect(const token_type& t1,
                      const token_type& t2,
                      const std::string& textual)
{
    token t = next();

    if (t.type() != t1 && t.type() != t2)
        throw parse_error(t.lineno(),
                          "Unexpected token `" + t.text() +
                          "'; expected " + textual);

    return t;
}

template< class TKZ >
token
parser< TKZ >::expect(const token_type& t1,
                      const token_type& t2,
                      const token_type& t3,
                      const std::string& textual)
{
    token t = next();

    if (t.type() != t1 && t.type() != t2 && t.type() != t3)
        throw parse_error(t.lineno(),
                          "Unexpected token `" + t.text() +
                          "'; expected " + textual);

    return t;
}

template< class TKZ >
token
parser< TKZ >::expect(const token_type& t1,
                      const token_type& t2,
                      const token_type& t3,
                      const token_type& t4,
                      const std::string& textual)
{
    token t = next();

    if (t.type() != t1 && t.type() != t2 && t.type() != t3 &&
        t.type() != t4)
        throw parse_error(t.lineno(),
                          "Unexpected token `" + t.text() +
                          "'; expected " + textual);

    return t;
}

template< class TKZ >
token
parser< TKZ >::expect(const token_type& t1,
                      const token_type& t2,
                      const token_type& t3,
                      const token_type& t4,
                      const token_type& t5,
                      const token_type& t6,
                      const token_type& t7,
                      const std::string& textual)
{
    token t = next();

    if (t.type() != t1 && t.type() != t2 && t.type() != t3 &&
        t.type() != t4 && t.type() != t5 && t.type() != t6 &&
        t.type() != t7)
        throw parse_error(t.lineno(),
                          "Unexpected token `" + t.text() +
                          "'; expected " + textual);

    return t;
}

} // namespace parser
} // namespace atf

#endif // !defined(_ATF_CXX_PARSER_HPP_)
@


1.1
log
@Initial revision
@
text
@@


1.1.1.1
log
@Import ATF 0.6.  Replaces the old ATF 0.5 that was in dist/atf.

Changes in this release:

* Make atf-exec be able to kill its child process after a certain period of
  time; this is controlled through the new -t option.

* Change atf-sh to use atf-exec's -t option to control the test case's
  timeouts, instead of doing it internally.  Same behavior as before, but
  noticeably faster.

* atf-exec's -g option and atf-killpg are gone due to the previous change.

* Added the atf-check(1) tool, a program that executes a given command and
  checks its exit code against a known value and allows the management of
  stdout and stderr in multiple ways.  This replaces the previous atf_check
  function in the atf-sh library and exposes this functionality to both
  atf-c and atf-c++.

* Added the ATF_REQUIRE family of macros to the C interface.  These help
  in checking for fatal test conditions.  The old ATF_CHECK macros now
  perform non-fatal checks only.  I.e. by using ATF_CHECK, the test case
  can now continue its execution and the failures will not be reported
  until the end of the whole run.

* Extended the amount of ATF_CHECK_* C macros with new ones to provide more
  features to the developer.  These also have their corresponding
  counterparts in the ATF_REQUIRE_* family.  The new macros (listing the
  suffixes only) are: _EQ (replaces _EQUAL), _EQ_MSG, _STREQ and
  _STREQ_MSG.
@
text
@@


1.1.1.2
log
@Import atf 0.8.  Changes in this release:

* Test programs no longer run several test cases in a row. The execution
  of a test program now requires a test case name, and that single test
  case is executed. To execute several test cases, use the atf-run
  utility as usual.

* Test programs no longer fork a subprocess to isolate the execution of
  test cases. They run the test case code in-process, and a crash of the
  test case will result in a crash of the test program. This is to ease
  debugging of faulty test cases.

* Test programs no longer isolate their test cases. This means that they
  will not create temporary directories nor sanitize the environment any
  more. Yes: running a test case that depends on system state by hand
  will most likely yield different results depending on where (machine,
  directory, user environment, etc.) it is run. Isolation has been moved
  to atf-run.

* Test programs no longer print a cryptic format (application/X-atf-tcs)
  on a special file channel. They can now print whatever they want on
  the screen. Because test programs can now only run one test case every
  time, providing controlled output is not necessary any more.

* Test programs no longer write their status into a special file
  descriptor. Instead, they create a file with the results, which is
  later parsed by atf-run. This changes the semantics of the -r flag.

* atf-run has been adjusted to perform the test case isolation. As a
  result, there is now a single canonical place that implements the
  isolation of test caes. In previous releases, the three language
  bindings (C, C++ and shell) had to be kept in sync with each other
  (read: not a nice thing to do at all). As a side effect of this
  change, writing bindings for other languages will be much, much easier
  from now on.

* atf-run forks test programs on a test case basis, instead of on a test
  program basis as it did before. This is to provide the test case
  isolation that was before implemented by the test programs themselves.

* Removed the atf-exec tool. This was used to implement test case
  isolation in atf-sh, but it is now unnecessary.

* It is now optional to define the descr meta-data property. It has been
  proven to be mostly useless, because test cases often carry a
  descriptive name of their own.
@
text
@d4 1
a4 1
// Copyright (c) 2007, 2008, 2010 The NetBSD Foundation, Inc.
a54 2

    operator std::string(void) const;
@


1.1.1.3
log
@Import atf 0.10:

Miscellaneous features

* Added expected failures support to test cases and atf-run.  These
  include, for example, expected clean exits, expected reception of fatal
  signals, expected timeouts and expected errors in condition checks.
  These statuses can be used to denote test cases that are known to fail
  due to a bug in the code they are testing.  atf-report reports these
  tests separately but they do not count towards the failed test cases
  amount.

* Added the ATF_CHECK_ERRNO and ATF_REQUIRE_ERRNO to the C library to
  allow easy checking of call failures that update errno.

* Added the has.cleanup meta-data property to test caes that specifies
  whether the test case has a cleanup routine or not; its value is
  automatically set.  This property is read by atf-run to know if it has to
  run the cleanup routine; skipping this run for every test case
  significantly speeds up the run time of test suites.

* Reversed the order of the ATF_CHECK_THROW macro in the C++ binding to
  take the expected exception as the first argument and the statement to
  execute as the second argument.

Changes in atf-check

* Changed atf-check to support negating the status and output checks by
  prefixing them with not- and added support to specify multiple checkers
  for stdout and stderr, not only one.

* Added the match output checker to atf-check to look for regular
  expressions in the stdout and stderr of commands.

* Modified the exit checks in atf-check to support checking for the
  reception of signals.

Code simplifications and cleanups

* Removed usage messages from test programs to simplify the
  implementation of every binding by a significant amount.  They just now
  refer the user to the appropriate manual page and do not attempt to wrap
  lines on terminal boundaries.  Test programs are not supposed to be run
  by users directly so this minor interface regression is not important.

* Removed the atf-format internal utility, which is unused after the
  change documented above.

* Removed the atf-cleanup internal utility.  It has been unused since the
  test case isolation was moved to atf-run in 0.8

* Splitted the Makefile.am into smaller files for easier maintenance and
  dropped the use of M4.  Only affects users building from the repository
  sources.

* Intermixed tests with the source files in the source tree to provide
  them more visibility and easier access.  The tests directory is gone from
  the source tree and tests are now suffixed by _test, not prefixed by t_.

* Simplifications to the atf-c library: removed the io, tcr and ui
  modules as they had become unnecessary after all simplifications
  introduced since the 0.8 release.

* Removed the application/X-atf-tcr format introduced in 0.8 release.
  Tests now print a much simplified format that is easy to parse and nicer
  to read by end users.  As a side effect, the default for test cases is
  now to print their results to stdout unless otherwise stated by providing
  the -r flag.

* Removed XML distribution documents and replaced them with plain-text
  documents.  They provided little value and introduced a lot of complexity
  to the build system.

* Simplified the output of atf-version by not attempting to print a
  revision number when building form a distfile.  Makes the build system
  easier to maintain.
@
text
@a32 1
#include <istream>
a33 1
#include <ostream>
a75 9
// The "format_error" class.
// ------------------------------------------------------------------------

class format_error : public std::runtime_error {
public:
    format_error(const std::string&);
};

// ------------------------------------------------------------------------
a356 11

    token
    expect(const token_type&,
           const token_type&,
           const token_type&,
           const token_type&,
           const token_type&,
           const token_type&,
           const token_type&,
           const token_type&,
           const std::string&);
a522 59
template< class TKZ >
token
parser< TKZ >::expect(const token_type& t1,
                      const token_type& t2,
                      const token_type& t3,
                      const token_type& t4,
                      const token_type& t5,
                      const token_type& t6,
                      const token_type& t7,
                      const token_type& t8,
                      const std::string& textual)
{
    token t = next();

    if (t.type() != t1 && t.type() != t2 && t.type() != t3 &&
        t.type() != t4 && t.type() != t5 && t.type() != t6 &&
        t.type() != t7 && t.type() != t8)
        throw parse_error(t.lineno(),
                          "Unexpected token `" + t.text() +
                          "'; expected " + textual);

    return t;
}

#define ATF_PARSER_CALLBACK(parser, func) \
    do { \
        if (!(parser).has_errors()) \
            func; \
    } while (false)

// ------------------------------------------------------------------------
// Header parsing.
// ------------------------------------------------------------------------

typedef std::map< std::string, std::string > attrs_map;

class header_entry {
    std::string m_name;
    std::string m_value;
    attrs_map m_attrs;

public:
    header_entry(void);
    header_entry(const std::string&, const std::string&,
                 attrs_map = attrs_map());

    const std::string& name(void) const;
    const std::string& value(void) const;
    const attrs_map& attrs(void) const;
    bool has_attr(const std::string&) const;
    const std::string& get_attr(const std::string&) const;
};

typedef std::map< std::string, header_entry > headers_map;

std::pair< size_t, headers_map > read_headers(std::istream&, size_t);
void write_headers(const headers_map&, std::ostream&);
void validate_content_type(const headers_map&, const std::string&, int);

@


