Tests: Combined and converted DOM unit tests

- Eliminated dom.t.cpp and therefore dom.t
- Eliminated dom.2.t (perl)
- Created dom.t (python) combining the above
This commit is contained in:
Paul Beckingham 2015-06-14 22:15:33 -04:00
parent a6c99f3ba5
commit afa39de68b
5 changed files with 191 additions and 227 deletions

1
test/.gitignore vendored
View file

@ -11,7 +11,6 @@ color.t
config.t
date.t
dates.t
dom.t
duration.t
eval.t
fs.t

View file

@ -6,9 +6,9 @@ include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/test
${TASK_INCLUDE_DIRS})
set (test_SRCS autocomplete.t color.t config.t date.t dom.t fs.t i18n.t json.t
list.t msg.t nibbler.t rx.t t.t t2.t t3.t tdb2.t text.t utf8.t
util.t view.t json_test lexer.t iso8601d.t iso8601p.t duration.t
set (test_SRCS autocomplete.t color.t config.t date.t fs.t i18n.t json.t list.t
msg.t nibbler.t rx.t t.t t2.t t3.t tdb2.t text.t utf8.t util.t
view.t json_test lexer.t iso8601d.t iso8601p.t duration.t
variant_add.t variant_and.t variant_cast.t variant_divide.t
variant_equal.t variant_exp.t variant_gt.t variant_gte.t
variant_inequal.t variant_lt.t variant_lte.t variant_match.t

View file

@ -1,121 +0,0 @@
#! /usr/bin/env perl
################################################################################
##
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
use strict;
use warnings;
use Test::More tests => 20;
# Ensure environment has no influence.
delete $ENV{'TASKDATA'};
delete $ENV{'TASKRC'};
use File::Basename;
my $ut = basename ($0);
my $rc = $ut . '.rc';
# Create the rc file.
if (open my $fh, '>', $rc)
{
print $fh "data.location=.\n",
"dateformat=YMD\n",
"dateformat.info=YMD\n",
"confirmation=off\n";
close $fh;
}
# DOM reference to other task.
qx{../src/task rc:$rc add one due:20110901 2>&1};
qx{../src/task rc:$rc add two due:1.due 2>&1};
my $output = qx{../src/task rc:$rc 2 info 2>&1};
like ($output, qr/Due\s+20110901/, "$ut: Found due date duplicated via dom");
# DOM reference to the current task.
qx{../src/task rc:$rc add three due:20110901 wait:due +tag1 +tag2 2>&1};
$output = qx{../src/task rc:$rc 3 info 2>&1};
like ($output, qr/Waiting until\s+20110901/, "$ut: Found wait date duplicated from due date");
# ID <--> UUID <--> ID round trip via DOM.
$output = qx{../src/task rc:$rc _get 1.uuid 2>&1};
like ($output, qr/^.{36}$/, "$ut: DOM id --> uuid");
my $uuid = chomp $output;
$output = qx{../src/task rc:$rc _get ${uuid}.id 2>&1};
like ($output, qr/^1$/, "$ut: DOM uuid --> id");
# Failed DOM lookup returns blank.
$output = qx{../src/task rc:$rc _get 4.description 2>&1};
like ($output, qr/^$/, "DOM 4.description --> ''");
# Test extended DOM support (2.4.0)
$output = qx{../src/task rc:$rc _get 3.tags 2>&1};
like ($output, qr/^tag1,tag2$/, "$ut: <id>.<tags>");
$output = qx{../src/task rc:$rc _get 3.tags.tag1 2>&1};
like ($output, qr/^tag1$/, "$ut: <id>.tags.tag1");
$output = qx{../src/task rc:$rc _get 3.tags.OVERDUE 2>&1};
like ($output, qr/^OVERDUE$/, "$ut: <id>.tags.<tag>");
$output = qx{../src/task rc:$rc _get 3.due.year 2>&1};
like ($output, qr/^\d{4}$/, "$ut: <id>.due.year");
$output = qx{../src/task rc:$rc _get 3.due.month 2>&1};
like ($output, qr/^\d{1,2}$/, "$ut: <id>.due.month");
$output = qx{../src/task rc:$rc _get 3.due.day 2>&1};
like ($output, qr/^\d{1,2}$/, "$ut: <id>.due.day");
$output = qx{../src/task rc:$rc _get 3.due.week 2>&1};
like ($output, qr/^\d{1,2}$/, "$ut: <id>.due.week");
$output = qx{../src/task rc:$rc _get 3.due.weekday 2>&1};
like ($output, qr/^\d{1}$/, "$ut: <id>.due.weekday");
$output = qx{../src/task rc:$rc _get 3.due.hour 2>&1};
like ($output, qr/^\d{1,2}$/, "$ut: <id>.due.hour");
$output = qx{../src/task rc:$rc _get 3.due.minute 2>&1};
like ($output, qr/^\d{1,2}$/, "$ut: <id>.due.minute");
$output = qx{../src/task rc:$rc _get 3.due.second 2>&1};
like ($output, qr/^\d{1,2}$/, "$ut: <id>.due.second");
$output = qx{../src/task rc:$rc _get 3.due.year 2>&1};
like ($output, qr/^\d{4}$/, "$ut: <id>.due.year");
qx{../src/task rc:$rc 3 annotate note 2>&1};
ok ($? == 0, "$ut: add annotation");
$output = qx{../src/task rc:$rc _get 3.annotations.1.entry 2>&1};
like ($output, qr/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/, "$ut: <id>.annotations.1.entry");
$output = qx{../src/task rc:$rc _get 3.annotations.1.description 2>&1};
like ($output, qr/^note$/, "$ut: <id>.annotations.1.description");
# Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data), $rc;
exit 0;

188
test/dom.t Executable file
View file

@ -0,0 +1,188 @@
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
###############################################################################
#
# Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
#
###############################################################################
import sys
import os
import unittest
# Ensure python finds the local simpletap module
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from basetest import Task, TestCase
class TestDOM(TestCase):
@classmethod
def setUpClass(cls):
cls.t = Task()
cls.t.config("dateformat", "YMD")
cls.t(("add", "one", "due:20110901"))
cls.t(("add", "two", "due:1.due"))
cls.t(("add", "three", "due:20110901", "wait:due", "+tag1", "+tag2"))
cls.t(("3", "annotate", "note"))
def test_dom_task_ref(self):
""" DOM reference to other task """
code, out, err = self.t(("_get", "2.due"))
self.assertIn("2011-09-01T00:00:00", out)
def test_dom_cli_ref(self):
""" DOM reference to current command line """
code, out, err = self.t(("_get", "3.wait"))
self.assertIn("2011-09-01T00:00:00", out)
def test_dom_id_uuid_roundtrip(self):
""" DOM id/uuid roundtrip """
code, out, err = self.t(("_get", "1.uuid"))
uuid = out.strip()
code, out, err = self.t(("_get", uuid + ".id"))
self.assertEqual("1\n", out)
def test_dom_fail(self):
""" DOM lookup of missing item """
code, out, err = self.t(("_get", "4.description"))
self.assertEqual("\n", out)
def test_dom_tags(self):
""" DOM 3.tags """
code, out, err = self.t(("_get", "3.tags"))
self.assertEqual("tag1,tag2\n", out)
def test_dom_tags_tag1(self):
""" DOM 3.tags.tag1 """
code, out, err = self.t(("_get", "3.tags.tag1"))
self.assertEqual("tag1\n", out)
def test_dom_tags_OVERDUE(self):
""" DOM 3.tags.OVERDUE """
code, out, err = self.t(("_get", "3.tags.OVERDUE"))
self.assertEqual("OVERDUE\n", out)
def test_dom_due_year(self):
""" DOM 3.due.year """
code, out, err = self.t(("_get", "3.due.year"))
self.assertEqual("2011\n", out)
def test_dom_due_month(self):
""" DOM 3.due.month """
code, out, err = self.t(("_get", "3.due.month"))
self.assertEqual("9\n", out)
def test_dom_due_day(self):
""" DOM 3.due.day """
code, out, err = self.t(("_get", "3.due.day"))
self.assertEqual("1\n", out)
def test_dom_due_week(self):
""" DOM 3.due.week """
code, out, err = self.t(("_get", "3.due.week"))
self.assertEqual("36\n", out)
def test_dom_due_weekday(self):
""" DOM 3.due.weekday """
code, out, err = self.t(("_get", "3.due.weekday"))
self.assertEqual("4\n", out)
def test_dom_due_hour(self):
""" DOM 3.due.hour """
code, out, err = self.t(("_get", "3.due.hour"))
self.assertEqual("0\n", out)
def test_dom_due_minute(self):
""" DOM 3.due.minute """
code, out, err = self.t(("_get", "3.due.minute"))
self.assertEqual("0\n", out)
def test_dom_due_second(self):
""" DOM 3.due.second """
code, out, err = self.t(("_get", "3.due.second"))
self.assertEqual("0\n", out)
def test_dom_annotation_entry(self):
""" DOM 3.annotations.1.entry """
code, out, err = self.t(("_get", "3.annotations.1.entry"))
self.assertRegexpMatches(out, r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}")
def test_dom_annotation_description(self):
""" DOM 3.annotations.1.description """
code, out, err = self.t(("_get", "3.annotations.1.description"))
self.assertIn("note\n", out)
def test_dom_system_version(self):
""" DOM system.version """
code, out, err = self.t(("_get", "system.version"))
self.assertEqual(code, 0)
self.assertRegexpMatches(out, r"\d\.\d+\.\d+")
def test_dom_system_os(self):
""" DOM system.os """
code, out, err = self.t(("_get", "system.os"))
self.assertEqual(code, 0)
self.assertEqual(len(out) > 4, True)
self.assertNotIn("<unknown>", out)
def test_dom_context_program(self):
""" DOM context.program """
code, out, err = self.t(("_get", "context.program"))
self.assertEqual(code, 0)
self.assertIn("task", out)
def test_dom_context_args(self):
""" DOM context.args """
code, out, err = self.t(("_get", "context.args"))
self.assertEqual(code, 0)
self.assertIn("task _get context.args", out)
def test_dom_context_width(self):
""" DOM context.width """
code, out, err = self.t(("_get", "context.width"))
self.assertEqual(code, 0)
self.assertRegexpMatches(out, r"\d+")
def test_dom_context_height(self):
""" DOM context.height """
code, out, err = self.t(("_get", "context.height"))
self.assertEqual(code, 0)
self.assertRegexpMatches(out, r"\d+")
def test_dom_rc_name(self):
""" DOM rc.dateformat """
code, out, err = self.t(("_get", "rc.dateformat"))
self.assertEqual(code, 0)
self.assertIn("YMD", out)
def test_dom_rc_missing(self):
""" DOM rc.missing """
code, out, err = self.t.runError(("_get", "rc.missing"))
self.assertEqual(code, 1)
if __name__ == "__main__":
from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner())
# vim: ai sts=4 et sw=4

View file

@ -1,102 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// http://www.opensource.org/licenses/mit-license.php
//
////////////////////////////////////////////////////////////////////////////////
#include <cmake.h>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <DOM.h>
#include <main.h>
#include <test.h>
Context context;
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)
{
UnitTest t (17);
// Ensure environment has no influence.
unsetenv ("TASKDATA");
unsetenv ("TASKRC");
try
{
// Prime the pump.
const char* fake_argv[] = {"task"};
context.cli.initialize (1, fake_argv);
context.config.set ("name", "value");
DOM dom;
Variant result;
t.ok (dom.get ("system.version", result), "DOM system.version -> true");
t.is ((std::string) result, VERSION, "DOM system.version -> VERSION");
t.ok (dom.get ("system.os", result), "DOM system.os -> true");
t.ok ((std::string) result != "<unknown>", "DOM system.os -> != Unknown");
t.ok (dom.get ("context.program", result), "DOM context.program -> true");
t.is ((std::string) result, "task", "DOM context.program -> 'task'");
t.ok (dom.get ("context.args", result), "DOM context.args -> true");
t.is ((std::string) result, "task", "DOM context.args -> 'task'");
t.ok (dom.get ("context.width", result), "DOM context.width -> true");
t.ok (result.get_integer () != 0, "DOM context.width -> '0'");
t.ok (dom.get ("context.height", result), "DOM context.height -> true");
t.ok (result.get_integer () != 0, "DOM context.height -> '0'");
// dom.get rc.name
t.ok (dom.get ("rc.name", result), "DOM rc.name -> true");
t.is ((std::string) result, "value", "DOM rc.name -> value");
// dom.get rc.missing
t.notok (dom.get ("rc.missing", result), "DOM rc.missing -> false");
// dom.set rc.name
dom.set ("rc.new", Variant ("value"));
t.ok (dom.get ("rc.new", result), "DOM rc.new -> true");
t.is ((std::string) result, "value", "DOM rc.new -> value");
}
catch (const std::string& error)
{
t.diag (error);
return -1;
}
catch (...)
{
t.diag ("Unknown error.");
return -2;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////