ATF-log archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

org.NetBSD.atf.src: 4c5ae69efbf41d2868d371d1f757a08eba45e170



#
#
# patch "NEWS"
#  from [fe1798c0ff9fcbf7ab5656ab8fcfa6947ce38724]
#    to [8f73a14e65b2ffcad313e096c3b813f443189e5c]
# 
# patch "atf-c/tp_main.c"
#  from [03288145cafc6219a527af62989365e93db3401d]
#    to [7e8b99921578b2760874d8171e33441bcf585efe]
# 
# patch "atf-c++/application.cpp"
#  from [2c4d2dd51fc10995b9f047e3218d81638e0c80e8]
#    to [4fc7536d8e0e2446a46d0d30e6d0e08db6885d95]
# 
# patch "atf-c++/application.hpp"
#  from [a7fcc692e824b76347e1c7bc64307a16b9bd7fef]
#    to [622c05ee1d6a19edbfe93521a3e86fbd0572676e]
# 
# patch "atf-c++/tests.cpp"
#  from [903346f542fa1a0b6058658b50bbed855c201ace]
#    to [8fb40dc2296578e5f0506d7f323a56a0ec164f81]
# 
# patch "atf-sh/libatf-sh.subr"
#  from [9648ab770cf9d0f9e35247871b553b7ea1bcc441]
#    to [a39080930e45121f79109ee975d07f2aa6a63634]
# 
# patch "doc/news.xml"
#  from [5223a164cc25a35a1c52c8f05a80522bd4852db2]
#    to [f2fd7d0d79bb3d151f10f1e9098e5efb40405fa1]
# 
# patch "tests/atf/test_programs/t_srcdir.sh"
#  from [9b7bbfa05ae8fd3842ee7ae3c35e7fc7afb3f82e]
#    to [4eb26db51547d671104704530b2974dfaab22483]
#
============================================================
--- NEWS        fe1798c0ff9fcbf7ab5656ab8fcfa6947ce38724
+++ NEWS        8f73a14e65b2ffcad313e096c3b813f443189e5c
@@ -33,6 +33,11 @@
 
      * Removed atf-compile in favour of atf-sh.
 
+     * Fixed test programs to get a sane default value for their source
+       directory. This means that it should not be necessary any more to pass
+       -s when running test programs that do not live in the current
+       directory.
+
                              Changes in version 0.8
 
    Experimental version released on May 7th, 2010.
============================================================
--- atf-c/tp_main.c     03288145cafc6219a527af62989365e93db3401d
+++ atf-c/tp_main.c     7e8b99921578b2760874d8171e33441bcf585efe
@@ -179,7 +179,7 @@ struct params {
 struct params {
     bool m_do_list;
     bool m_do_usage;
-    const char *m_srcdir;
+    atf_fs_path_t m_srcdir;
     char *m_tcname;
     enum tc_part m_tcpart;
     atf_fs_path_t m_resfile;
@@ -188,23 +188,47 @@ atf_error_t
 
 static
 atf_error_t
-params_init(struct params *p)
+argv0_to_dir(const char *argv0, atf_fs_path_t *dir)
 {
     atf_error_t err;
+    atf_fs_path_t temp;
 
+    err = atf_fs_path_init_fmt(&temp, "%s", argv0);
+    if (atf_is_error(err))
+        goto out;
+
+    err = atf_fs_path_branch_path(&temp, dir);
+
+    atf_fs_path_fini(&temp);
+out:
+    return err;
+}
+
+static
+atf_error_t
+params_init(struct params *p, const char *argv0)
+{
+    atf_error_t err;
+
     p->m_do_list = false;
     p->m_do_usage = false;
-    p->m_srcdir = ".";
     p->m_tcname = NULL;
     p->m_tcpart = BODY;
 
-    err = atf_fs_path_init_fmt(&p->m_resfile, "resfile"); /* XXX Bad default */
+    err = argv0_to_dir(argv0, &p->m_srcdir);
     if (atf_is_error(err))
         return err;
 
+    err = atf_fs_path_init_fmt(&p->m_resfile, "resfile"); /* XXX Bad default */
+    if (atf_is_error(err)) {
+        atf_fs_path_fini(&p->m_srcdir);
+        return err;
+    }
+
     err = atf_map_init(&p->m_config);
     if (atf_is_error(err)) {
         atf_fs_path_fini(&p->m_resfile);
+        atf_fs_path_fini(&p->m_srcdir);
         return err;
     }
 
@@ -217,6 +241,7 @@ params_fini(struct params *p)
 {
     atf_map_fini(&p->m_config);
     atf_fs_path_fini(&p->m_resfile);
+    atf_fs_path_fini(&p->m_srcdir);
     if (p->m_tcname != NULL)
         free(p->m_tcname);
 }
@@ -243,6 +268,22 @@ out:
     return err;
 }
 
+static
+atf_error_t
+replace_path_param(atf_fs_path_t *param, const char *value)
+{
+    atf_error_t err;
+    atf_fs_path_t temp;
+
+    err = atf_fs_path_init_fmt(&temp, "%s", value);
+    if (!atf_is_error(err)) {
+        atf_fs_path_fini(param);
+        *param = temp;
+    }
+
+    return err;
+}
+
 /* ---------------------------------------------------------------------
  * Test case listing.
  * --------------------------------------------------------------------- */
@@ -352,7 +393,7 @@ process_params(int argc, char **argv, st
     atf_error_t err;
     int ch;
 
-    err = params_init(p);
+    err = params_init(p, argv[0]);
     if (atf_is_error(err))
         goto out;
 
@@ -369,18 +410,11 @@ process_params(int argc, char **argv, st
             break;
 
         case 'r':
-            {
-                atf_fs_path_t resfile;
-                err = atf_fs_path_init_fmt(&resfile, "%s", optarg);
-                if (!atf_is_error(err)) {
-                    atf_fs_path_fini(&p->m_resfile);
-                    p->m_resfile = resfile;
-                }
-            }
+            err = replace_path_param(&p->m_resfile, optarg);
             break;
 
         case 's':
-            p->m_srcdir = optarg;
+            err = replace_path_param(&p->m_srcdir, optarg);
             break;
 
         case 'v':
@@ -433,7 +467,7 @@ handle_srcdir(struct params *p)
     atf_fs_path_t exe, srcdir;
     bool b;
 
-    err = atf_fs_path_init_fmt(&srcdir, "%s", p->m_srcdir);
+    err = atf_fs_path_copy(&srcdir, &p->m_srcdir);
     if (atf_is_error(err))
         goto out;
 
============================================================
--- atf-c++/application.cpp     2c4d2dd51fc10995b9f047e3218d81638e0c80e8
+++ atf-c++/application.cpp     4fc7536d8e0e2446a46d0d30e6d0e08db6885d95
@@ -253,6 +253,8 @@ impl::app::run(int argc, char* const* ar
     m_argc = argc;
     m_argv = argv;
 
+    m_argv0 = m_argv[0];
+
     m_prog_name = std::strrchr(m_argv[0], '/');
     if (m_prog_name == NULL)
         m_prog_name = m_argv[0];
============================================================
--- atf-c++/application.hpp     a7fcc692e824b76347e1c7bc64307a16b9bd7fef
+++ atf-c++/application.hpp     622c05ee1d6a19edbfe93521a3e86fbd0572676e
@@ -1,7 +1,7 @@
 //
 // Automated Testing Framework (atf)
 //
-// Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
+// Copyright (c) 2007, 2008, 2010 The NetBSD Foundation, Inc.
 // All rights reserved.
 //
 // Redistribution and use in source and binary forms, with or without
@@ -87,6 +87,7 @@ protected:
     int m_argc;
     char* const* m_argv;
 
+    const char* m_argv0;
     const char* m_prog_name;
     std::string m_description;
     std::string m_manpage, m_global_manpage;
============================================================
--- atf-c++/tests.cpp   903346f542fa1a0b6058658b50bbed855c201ace
+++ atf-c++/tests.cpp   8fb40dc2296578e5f0506d7f323a56a0ec164f81
@@ -415,6 +415,7 @@ private:
 
     bool m_lflag;
     atf::fs::path m_resfile;
+    std::string m_srcdir_arg;
     atf::fs::path m_srcdir;
 
     atf::tests::vars_map m_vars;
@@ -507,7 +508,7 @@ tp::process_option(int ch, const char* a
         break;
 
     case 's':
-        m_srcdir = atf::fs::path(arg);
+        m_srcdir_arg = arg;
         break;
 
     case 'v':
@@ -540,6 +541,11 @@ tp::handle_srcdir(void)
 void
 tp::handle_srcdir(void)
 {
+    if (m_srcdir_arg.empty())
+        m_srcdir = atf::fs::path(m_argv0).branch_path();
+    else
+        m_srcdir = atf::fs::path(m_srcdir_arg);
+
     if (!atf::fs::exists(m_srcdir / m_prog_name))
         throw std::runtime_error("Cannot find the test program in the "
                                  "source directory `" + m_srcdir.str() + "'");
============================================================
--- atf-sh/libatf-sh.subr       9648ab770cf9d0f9e35247871b553b7ea1bcc441
+++ atf-sh/libatf-sh.subr       a39080930e45121f79109ee975d07f2aa6a63634
@@ -51,9 +51,8 @@ Results_File=resfile # XXX
 Results_File=resfile # XXX
 
 # The test program's source directory: i.e. where its auxiliary data files
-# and helper utilities can be found.  Defaults to the current directory
-# but can be overriden through the '-s' flag.
-Source_Dir=.
+# and helper utilities can be found.  Can be overriden through the '-s' flag.
+Source_Dir="$(dirname ${0})"
 
 # Indicates the test case we are currently processing.
 Test_Case=
============================================================
--- doc/news.xml        5223a164cc25a35a1c52c8f05a80522bd4852db2
+++ doc/news.xml        f2fd7d0d79bb3d151f10f1e9098e5efb40405fa1
@@ -31,6 +31,11 @@ the loading of the necessary ATF librari
 
 <listitem><para>Removed atf-compile in favour of atf-sh.</para></listitem>
 
+<listitem><para>Fixed test programs to get a sane default value for their
+source directory.  This means that it should not be necessary any more to
+pass <literal>-s</literal> when running test programs that do not live in
+the current directory.</para></listitem>
+
 </itemizedlist>
 
 </section>
============================================================
--- tests/atf/test_programs/t_srcdir.sh 9b7bbfa05ae8fd3842ee7ae3c35e7fc7afb3f82e
+++ tests/atf/test_programs/t_srcdir.sh 4eb26db51547d671104704530b2974dfaab22483
@@ -1,7 +1,7 @@
 #
 # Automated Testing Framework (atf)
 #
-# Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
+# Copyright (c) 2007, 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -48,9 +48,8 @@ default_body()
         cp ${hp} tmp
         atf_check -s eq:0 -o ignore -e ignore -x \
                   "cd tmp && ./${h} srcdir_exists"
-        atf_check -s eq:1 -o empty -e save:stderr "${hp}" srcdir_exists
-        atf_check -s eq:0 -o ignore -e empty \
-                  grep "Cannot.*find.*source.*directory" stderr
+        atf_check -s eq:1 -o empty -e empty "${hp}" -r res srcdir_exists
+        atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
     done
 }
 
@@ -70,9 +69,8 @@ sflag_body()
         atf_check -s eq:0 -o ignore -e ignore -x \
                   "cd tmp && ./${h} -s $(pwd)/tmp \
                    srcdir_exists"
-        atf_check -s eq:1 -o empty -e save:stderr "${hp}" srcdir_exists
-        atf_check -s eq:0 -o ignore -e empty \
-                  grep "Cannot.*find.*source.*directory" stderr
+        atf_check -s eq:1 -o empty -e save:stderr "${hp}" -r res srcdir_exists
+        atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
         atf_check -s eq:0 -o ignore -e ignore \
                   "${hp}" -s "$(pwd)"/tmp srcdir_exists
     done
@@ -98,9 +96,9 @@ relative_body()
 
             atf_check -s eq:0 -o ignore -e ignore \
                       "./tmp/${h}" -s "${p}" srcdir_exists
-            atf_check -s eq:1 -o empty -e save:stderr "${hp}" srcdir_exists
-            atf_check -s eq:0 -o ignore -e empty \
-                      grep "Cannot.*find.*source.*directory" stderr
+            atf_check -s eq:1 -o empty -e save:stderr "${hp}" -r res \
+                srcdir_exists
+            atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" 
res
             atf_check -s eq:0 -o ignore -e ignore \
                       "${hp}" -s "${p}" srcdir_exists
         done


Home | Main Index | Thread Index | Old Index