diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..47ba5c3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 2010 Michael Dvorkin. 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 AUTHORS "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 AUTHORS 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. + +The views and conclusions contained in the software and documentation +are those of the authors and contributors and should not be interpreted +as representing official policies, either expressed or implied, of +anybody else. diff --git a/src/action.c b/src/action.c index 836c3c8..2fc8b5c 100644 --- a/src/action.c +++ b/src/action.c @@ -1,3 +1,14 @@ +/* +** Copyright (c) 2010 Michael Dvorkin +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +*/ #include #include #include @@ -7,11 +18,11 @@ static void action_list() { pit_db_load(); if (actions->number_of_records > 0) { - PFormat pf = pit_pager_initialize(PAGER_ACTION, 0, actions->number_of_records); + PFormat pf = pit_format_initialize(FORMAT_ACTION, 0, actions->number_of_records); for_each_action(pa) { - pit_pager_print(pf, (char *)pa); + pit_format(pf, (char *)pa); } - pit_pager_flush(pf); + pit_format_flush(pf); } } diff --git a/src/args.c b/src/args.c index 7ef8328..d5a38a3 100644 --- a/src/args.c +++ b/src/args.c @@ -1,3 +1,14 @@ +/* +** Copyright (c) 2010 Michael Dvorkin +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +*/ #include #include #include @@ -14,7 +25,7 @@ int pit_arg_option(char **arg) if (pit_arg_is_option(arg)) { return *(*arg + 1); } else { - die("invalid option"); + die("invalid option: %s", *arg); return 0; } } @@ -95,7 +106,7 @@ time_t pit_arg_date(char **arg, char *required) if (required && (!*arg || pit_arg_is_option(arg))) { die("missing %s", required); - } else if (!strcmp(*arg, "none")) { /* Drop dat value */ + } else if (!strcmp(*arg, "none")) { /* Drop date value */ return -1; } else { bool alpha_date = isalpha(**arg); @@ -113,7 +124,7 @@ time_t pit_arg_date(char **arg, char *required) strcpy(format, "%m/%d/%Y %H:%M"); /* 10/10/1992 19:30 */ } } else { - if (strlen(*arg) >= 12) { + if (strlen(*arg) >= 12) { /* TODO: this is too simplistic... */ if (alpha_date) { strcpy(format, "%b %d, %Y %H"); /* Oct 10, 1992 19 */ } else { @@ -142,17 +153,17 @@ time_t pit_arg_date(char **arg, char *required) adjust_time(arg, format); /* Replace %H with %I%p for am/pm time */ /* Ready to roll :-) */ - // printf("format: %s\n", format); + /* printf("format: %s\n", format); */ if (strptime(*arg, format, &tm)) { - // printf("then: %s\n", asctime(&tm)); + /* printf("then: %s\n", asctime(&tm)); */ if (!tm.tm_mday) tm.tm_mday = ptm->tm_mday; if (!tm.tm_mon) tm.tm_mon = ptm->tm_mon; if (!tm.tm_year) tm.tm_year = ptm->tm_year; tm.tm_isdst = -1; - // printf(" now: %s\n", asctime(ptm)); - // printf(" adj: %s\n", asctime(&tm)); + /* printf(" now: %s\n", asctime(ptm)); */ + /* printf(" adj: %s\n", asctime(&tm)); */ seconds = mktime(&tm); - // printf("ctime: %s", ctime(&seconds)); + /* printf("ctime: %s", ctime(&seconds)); */ if (seconds == (time_t)-1) { perish("invalid date"); } diff --git a/src/db.c b/src/db.c index 646ec60..21e9734 100644 --- a/src/db.c +++ b/src/db.c @@ -1,3 +1,14 @@ +/* +** Copyright (c) 2010 Michael Dvorkin +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +*/ #include #include #include diff --git a/src/format.c b/src/format.c index 90de2cc..013b1e5 100644 --- a/src/format.c +++ b/src/format.c @@ -1,3 +1,14 @@ +/* +** Copyright (c) 2010 Michael Dvorkin +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +*/ #include #include #include @@ -144,11 +155,11 @@ static void print_tasks_with_date_and_time(PFormat pf) } } -PFormat pit_pager_initialize(int type, int indent, int number_of_entries) +PFormat pit_format_initialize(int type, int indent, int number_of_entries) { - PFormat pf = calloc(1, sizeof(Pager)); + PFormat pf = calloc(1, sizeof(Format)); - memset(pf, 0, sizeof(Pager)); + memset(pf, 0, sizeof(Format)); pf->type = type; pf->indent = indent; pf->entries = calloc(number_of_entries + 1, sizeof(char *)); @@ -156,7 +167,7 @@ PFormat pit_pager_initialize(int type, int indent, int number_of_entries) return pf; } -void pit_pager_print(PFormat pf, char *entry) +void pit_format(PFormat pf, char *entry) { char str[32]; @@ -165,14 +176,14 @@ void pit_pager_print(PFormat pf, char *entry) for_each_entry(pf, pentry) { switch(pf->type) { - case PAGER_PROJECT: + case FORMAT_PROJECT: sprintf(str, "%d", PROJECT(id)); pf->max.project.id = max(pf->max.project.id, strlen(str)); pf->max.project.username = max(pf->max.project.username, strlen(PROJECT(username))); pf->max.project.name = max(pf->max.project.name, strlen(PROJECT(name))); pf->max.project.status = max(pf->max.project.status, strlen(PROJECT(status))); break; - case PAGER_TASK: + case FORMAT_TASK: sprintf(str, "%d", TASK(id)); pf->max.task.id = max(pf->max.task.id, strlen(str)); pf->max.task.username = max(pf->max.task.username, strlen(TASK(username))); @@ -186,25 +197,25 @@ void pit_pager_print(PFormat pf, char *entry) pf->max.task.time = max(pf->max.task.time, strlen(format_time(TASK(time)))); } break; - case PAGER_NOTE: + case FORMAT_NOTE: sprintf(str, "%d", NOTE(id)); pf->max.note.id = max(pf->max.note.id, strlen(str)); pf->max.note.username = max(pf->max.note.username, strlen(NOTE(username))); break; - case PAGER_ACTION: + case FORMAT_ACTION: pf->max.action.username = max(pf->max.action.username, strlen(ACTION(username))); pf->max.action.message = max(pf->max.action.message, strlen(ACTION(message))); break; default: - die("invalid pager type: %d\n", pf->type); + die("invalid format: %d\n", pf->type); } } } -void pit_pager_flush(PFormat pf) +void pit_format_flush(PFormat pf) { switch(pf->type) { - case PAGER_TASK: + case FORMAT_TASK: if (!pf->max.task.date && !pf->max.task.time) { print_tasks(pf); /* Neither date nor time. */ } else if (pf->max.task.date) { @@ -218,26 +229,26 @@ void pit_pager_flush(PFormat pf) } break; - case PAGER_PROJECT: + case FORMAT_PROJECT: print_projects(pf); break; - case PAGER_ACTION: + case FORMAT_ACTION: print_actions(pf); break; - case PAGER_NOTE: + case FORMAT_NOTE: print_notes(pf); break; default: - pit_pager_free(pf); - die("invalid pager type: %d\n", pf->type); + pit_format_free(pf); + die("invalid format: %d\n", pf->type); } - pit_pager_free(pf); + pit_format_free(pf); } -void pit_pager_free(PFormat pf) +void pit_format_free(PFormat pf) { free(pf->entries); free(pf); diff --git a/src/format.h b/src/format.h index 10336cd..29f9fb6 100644 --- a/src/format.h +++ b/src/format.h @@ -1,12 +1,23 @@ -#if !defined(__PAGER_H__) -#define __PAGER_H__ +/* +** Copyright (c) 2010 Michael Dvorkin +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +*/ +#if !defined(__FORMAT_H__) +#define __FORMAT_H__ -#define PAGER_ACTION 1 -#define PAGER_PROJECT 2 -#define PAGER_TASK 4 -#define PAGER_NOTE 8 +#define FORMAT_ACTION 1 +#define FORMAT_PROJECT 2 +#define FORMAT_TASK 4 +#define FORMAT_NOTE 8 -typedef struct _Pager { +typedef struct _Format { int type; int indent; int number_of_entries; @@ -36,11 +47,11 @@ typedef struct _Pager { int username; } note; } max; -} Pager, *PFormat; +} Format, *PFormat; -PFormat pit_pager_initialize(int type, int indent, int number_of_entries); -void pit_pager_print(PFormat pf, char *entry); -void pit_pager_flush(PFormat pf); -void pit_pager_free(PFormat pf); +PFormat pit_format_initialize(int type, int indent, int number_of_entries); +void pit_format(PFormat pf, char *entry); +void pit_format_flush(PFormat pf); +void pit_format_free(PFormat pf); #endif \ No newline at end of file diff --git a/src/help.c b/src/help.c index 29b3fa9..7d241f9 100644 --- a/src/help.c +++ b/src/help.c @@ -1,3 +1,14 @@ +/* +** Copyright (c) 2010 Michael Dvorkin +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +*/ #include #include #include diff --git a/src/note.c b/src/note.c index cefb61c..59ad7e4 100644 --- a/src/note.c +++ b/src/note.c @@ -1,3 +1,14 @@ +/* +** Copyright (c) 2010 Michael Dvorkin +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +*/ #include #include #include @@ -115,14 +126,14 @@ void pit_note_list(PTask pt) if (!notes) pit_db_load(); if (notes->number_of_records > 0) { - PFormat pf = pit_pager_initialize(PAGER_NOTE, pt ? 4 : 0, notes->number_of_records); + PFormat pf = pit_format_initialize(FORMAT_NOTE, pt ? 4 : 0, notes->number_of_records); if (!pt) pt = (PTask)pit_table_current(tasks); for_each_note(pn) { if (pt && pn->task_id != pt->id) continue; - pit_pager_print(pf, (char *)pn); + pit_format(pf, (char *)pn); } - pit_pager_flush(pf); + pit_format_flush(pf); } } diff --git a/src/object.h b/src/object.h index e5e006a..447adf9 100644 --- a/src/object.h +++ b/src/object.h @@ -1,5 +1,16 @@ -#if !defined(__MODELS_H__) -#define __MODELS_H__ +/* +** Copyright (c) 2010 Michael Dvorkin +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +*/ +#if !defined(__OBJECT_H__) +#define __OBJECT_H__ typedef struct _Header { char signature[3]; diff --git a/src/pit.c b/src/pit.c index cc9ec6c..ac1a346 100644 --- a/src/pit.c +++ b/src/pit.c @@ -1,3 +1,14 @@ +/* +** Copyright (c) 2010 Michael Dvorkin +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +*/ #include #include #include diff --git a/src/pit.h b/src/pit.h index 21cd2f8..ec8deaf 100644 --- a/src/pit.h +++ b/src/pit.h @@ -1,3 +1,14 @@ +/* +** Copyright (c) 2010 Michael Dvorkin +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +*/ #if !defined(__PIT_H__) #define __PIT_H__ #define PIT_VERSION "0.1.0" diff --git a/src/project.c b/src/project.c index 71942ac..226331f 100644 --- a/src/project.c +++ b/src/project.c @@ -1,3 +1,14 @@ +/* +** Copyright (c) 2010 Michael Dvorkin +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +*/ #include #include #include @@ -70,14 +81,14 @@ static void project_list(POptions po) pit_db_load(); if (projects->number_of_records > 0) { - pf = pit_pager_initialize(PAGER_PROJECT, 0, projects->number_of_records); + pf = pit_format_initialize(FORMAT_PROJECT, 0, projects->number_of_records); for_each_project(pp) { if ((po->project.name && !stristr(pp->name, po->project.name)) || (po->project.status && !stristr(pp->status, po->project.status))) continue; - pit_pager_print(pf, (char *)pp); + pit_format(pf, (char *)pp); } - pit_pager_flush(pf); + pit_format_flush(pf); } } diff --git a/src/table.c b/src/table.c index 55f54cc..8ed4610 100644 --- a/src/table.c +++ b/src/table.c @@ -1,3 +1,19 @@ +/* +** Copyright (c) 2010 Michael Dvorkin +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +*/ + +/* +** Sqlite probably is a great backend alternative for pit. I just +** figured I would have more fun writing it myself. +*/ #include #include #include @@ -197,15 +213,15 @@ char *pit_table_insert(PTable pt, char *record) register char **pi = table_available_index(pt); *pi = pr; /* - ** Update record id if the table has primary key. The id must be the first - ** record field of type "unsigned long". + ** Update record id if the table has primary key. The id must + ** be the first record field of type "unsigned long". */ pt->auto_increment++; *(int *)*pi = pt->auto_increment; } /* - ** Update created_at and/or updated_at which must be last one or two record - ** fields of type "time_t". + ** Update created_at and/or updated_at which must be last one or + ** two record fields of type "time_t". */ if (HAS_CREATED_AT(pt) || HAS_UPDATED_AT(pt)) { *(time_t *)(pr + pt->record_size - sizeof(time_t)) = now; @@ -229,7 +245,7 @@ char *pit_table_current(PTable pt) */ char *pit_table_mark(PTable pt, int id) { - return pit_table_find(pt, pt->current = id); + return pit_table_find(pt, pt->current = id); /* <-- Assign and pass as parameter */ } /* diff --git a/src/table.h b/src/table.h index 4e1353f..71d622c 100644 --- a/src/table.h +++ b/src/table.h @@ -1,3 +1,14 @@ +/* +** Copyright (c) 2010 Michael Dvorkin +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +*/ #if !defined(__TABLE_H__) #define __TABLE_H__ diff --git a/src/task.c b/src/task.c index 73198d5..33e1f67 100644 --- a/src/task.c +++ b/src/task.c @@ -1,3 +1,14 @@ +/* +** Copyright (c) 2010 Michael Dvorkin +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +*/ #include #include #include @@ -229,7 +240,7 @@ void pit_task_list(POptions po, PProject pp) if (!tasks) pit_db_load(); if (tasks->number_of_records > 0) { - PFormat pf = pit_pager_initialize(PAGER_TASK, (pp ? 4 : 0), tasks->number_of_records); + PFormat pf = pit_format_initialize(FORMAT_TASK, (pp ? 4 : 0), tasks->number_of_records); if (!pp) pp = (PProject)pit_table_current(projects); for_each_task(pt) { @@ -242,9 +253,9 @@ void pit_task_list(POptions po, PProject pp) (po->task.time && pt->time < po->task.time) || (po->task.time_max && pt->time > po->task.time_max)) )) continue; - pit_pager_print(pf, (char *)pt); + pit_format(pf, (char *)pt); } - pit_pager_flush(pf); + pit_format_flush(pf); } } diff --git a/src/util.c b/src/util.c index 82dbe61..7254df0 100644 --- a/src/util.c +++ b/src/util.c @@ -1,3 +1,14 @@ +/* +** Copyright (c) 2010 Michael Dvorkin +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the Simplified BSD License (also +** known as the "2-Clause License" or "FreeBSD License".) +** +** This program is distributed in the hope that it will be useful, +** but without any warranty; without even the implied warranty of +** merchantability or fitness for a particular purpose. +*/ #include #include #include diff --git a/test/pit_date.rb b/test/pit_date.rb index 8dc5083..e9e4577 100644 --- a/test/pit_date.rb +++ b/test/pit_date.rb @@ -1,4 +1,14 @@ -module Pit +# Copyright (c) 2010 Michael Dvorkin +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the Simplified BSD License (also +# known as the "2-Clause License" or "FreeBSD License".) +# +# This program is distributed in the hope that it will be useful, +# but without any warranty; without even the implied warranty of +# merchantability or fitness for a particular purpose. + +module PitTest module Date def should_parse_alpha_dates diff --git a/test/pit_note.rb b/test/pit_note.rb index 293507b..5d5c602 100644 --- a/test/pit_note.rb +++ b/test/pit_note.rb @@ -1,5 +1,16 @@ -module Pit +# Copyright (c) 2010 Michael Dvorkin +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the Simplified BSD License (also +# known as the "2-Clause License" or "FreeBSD License".) +# +# This program is distributed in the hope that it will be useful, +# but without any warranty; without even the implied warranty of +# merchantability or fitness for a particular purpose. + +module PitTest module Note + def should_not_segfault `#{@pit} p -c test` `#{@pit} t -c test` @@ -21,5 +32,6 @@ module Pit `#{@pit} n -e #{n} xxx` end end + end end diff --git a/test/pit_project.rb b/test/pit_project.rb index 1b2244d..610afb5 100644 --- a/test/pit_project.rb +++ b/test/pit_project.rb @@ -1,4 +1,14 @@ -module Pit +# Copyright (c) 2010 Michael Dvorkin +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the Simplified BSD License (also +# known as the "2-Clause License" or "FreeBSD License".) +# +# This program is distributed in the hope that it will be useful, +# but without any warranty; without even the implied warranty of +# merchantability or fitness for a particular purpose. + +module PitTest module Project def should_create_project @@ -27,5 +37,6 @@ module Pit `#{@pit} project`.should_not.match /[\s|\*] 2:/m `#{@pit} project`.should.match /\s 1:/m end + end end diff --git a/test/pit_task.rb b/test/pit_task.rb index aa8ad7e..e72a463 100644 --- a/test/pit_task.rb +++ b/test/pit_task.rb @@ -1,4 +1,14 @@ -module Pit +# Copyright (c) 2010 Michael Dvorkin +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the Simplified BSD License (also +# known as the "2-Clause License" or "FreeBSD License".) +# +# This program is distributed in the hope that it will be useful, +# but without any warranty; without even the implied warranty of +# merchantability or fitness for a particular purpose. + +module PitTest module Task def should_do_cascading_task_delete diff --git a/test/pit_test.rb b/test/pit_test.rb index c3eca2b..f2fad0e 100755 --- a/test/pit_test.rb +++ b/test/pit_test.rb @@ -1,7 +1,17 @@ #!/usr/bin/env ruby # +# Copyright (c) 2010 Michael Dvorkin +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the Simplified BSD License (also +# known as the "2-Clause License" or "FreeBSD License".) +# +# This program is distributed in the hope that it will be useful, +# but without any warranty; without even the implied warranty of +# merchantability or fitness for a particular purpose. + BASE = File.dirname(File.expand_path(__FILE__)) -require "#{BASE}/pit_should" +require "#{BASE}/tiny_should" require "#{BASE}/pit_date" require "#{BASE}/pit_project" require "#{BASE}/pit_task" @@ -33,10 +43,10 @@ class PitTestRunner `#{@pit} init -f` end - include Pit::Date - include Pit::Project - include Pit::Task - include Pit::Note + include PitTest::Date + include PitTest::Project + include PitTest::Task + include PitTest::Note end PitTestRunner.run diff --git a/test/pit_should.rb b/test/tiny_should.rb similarity index 63% rename from test/pit_should.rb rename to test/tiny_should.rb index b7385df..6cfffe4 100644 --- a/test/pit_should.rb +++ b/test/tiny_should.rb @@ -1,10 +1,17 @@ -class Hand < RuntimeError - def oops(msg) - puts "\n#{msg} in #{self.backtrace[1].sub(':', ' line ')}" - end -end +# Copyright (c) 2010 Michael Dvorkin +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the Simplified BSD License (also +# known as the "2-Clause License" or "FreeBSD License".) +# +# This program is distributed in the hope that it will be useful, +# but without any warranty; without even the implied warranty of +# merchantability or fitness for a particular purpose. -class String +# I am well aware there is Test::Unit, minitest, rspec, shoulda, +# bacon and a dozen of other testing frameworks. I just had fun +# writing this one and frankly that's all I need for basic testing. +module TinyShould def should def self.equal(expected) raise Hand unless self == expected @@ -42,6 +49,16 @@ class String end end +class Hand < RuntimeError + def oops(msg) + puts "\n#{msg} in #{self.backtrace[1].sub(':', ' line ')}" + end +end + +class String + include TinyShould +end + if $0 == __FILE__ "123".should.equal "123" "123".should.equal "321" @@ -55,5 +72,3 @@ if $0 == __FILE__ "abc".should_not.match /xyz/ "abc".should_not.match /abc/ end - -