From 5275c0ce602dc499a3b1524059cd3b45194f56b6 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 18 Oct 2014 14:41:12 -0400 Subject: [PATCH] TW-1441 - TW-1441 task import continues happily if filename doesn't exist. --- ChangeLog | 1 + src/commands/CmdImport.cpp | 9 ++++++--- src/l10n/eng-USA.h | 1 + src/l10n/epo-RUS.h | 1 + src/l10n/esp-ESP.h | 1 + src/l10n/fra-FRA.h | 1 + src/l10n/ita-ITA.h | 1 + src/l10n/pol-POL.h | 1 + src/l10n/por-PRT.h | 1 + test/tw-1441.t | 30 ++++++++++++++++++++++++++++++ 10 files changed, 44 insertions(+), 3 deletions(-) create mode 100755 test/tw-1441.t diff --git a/ChangeLog b/ChangeLog index 335ab7e0c..e5edb7a59 100644 --- a/ChangeLog +++ b/ChangeLog @@ -168,6 +168,7 @@ Testing). - TW-1428 Add support for color.uda.. rules. - TW-1436 Parser hangs when multiple slashes are used. +- TW-1441 task import continues happily if filename doesn't exist. - Removed deprecated 'echo.command' setting, in favor of the 'header' and 'affected' verbosity tokens. - Removed deprecated 'edit.verbose' setting, in favor of the 'edit' verbosity diff --git a/src/commands/CmdImport.cpp b/src/commands/CmdImport.cpp index 1c6a68e93..2f5595732 100644 --- a/src/commands/CmdImport.cpp +++ b/src/commands/CmdImport.cpp @@ -61,12 +61,15 @@ int CmdImport::execute (std::string& output) std::vector ::iterator word; for (word = words.begin (); word != words.end (); ++word) { - std::string file = *word; - std::cout << format (STRING_CMD_IMPORT_FILE, file) << "\n"; + File incoming (*word); + if (! incoming.exists ()) + throw format (STRING_CMD_IMPORT_MISSING, *word); + + std::cout << format (STRING_CMD_IMPORT_FILE, *word) << "\n"; // Load the file. std::vector lines; - File::read (file, lines); + incoming.read (lines); std::vector ::iterator line; for (line = lines.begin (); line != lines.end (); ++line) diff --git a/src/l10n/eng-USA.h b/src/l10n/eng-USA.h index 3dd41e6cb..593f6e4a7 100644 --- a/src/l10n/eng-USA.h +++ b/src/l10n/eng-USA.h @@ -460,6 +460,7 @@ #define STRING_CMD_IMPORT_SUMMARY "Imported {1} tasks." #define STRING_CMD_IMPORT_NOFILE "You must specify a file to import." #define STRING_CMD_IMPORT_FILE "Importing '{1}'" +#define STRING_CMD_IMPORT_MISSING "File '{1}' not found." #define STRING_TASK_NO_DESC "Annotation is missing a description: {1}" #define STRING_TASK_NO_ENTRY "Annotation is missing an entry date: {1}" #define STRING_CMD_SYNC_USAGE "Synchronizes data with the Taskserver" diff --git a/src/l10n/epo-RUS.h b/src/l10n/epo-RUS.h index 6bac1bb66..a319cfab1 100644 --- a/src/l10n/epo-RUS.h +++ b/src/l10n/epo-RUS.h @@ -460,6 +460,7 @@ #define STRING_CMD_IMPORT_SUMMARY "Importis {1} taskojn." #define STRING_CMD_IMPORT_NOFILE "Vi devas specifi kiu dosieron import." #define STRING_CMD_IMPORT_FILE "Importanta '{1}'" +#define STRING_CMD_IMPORT_MISSING "File '{1}' not found." #define STRING_TASK_NO_DESC "Komento havas mankon de priskribo: {1}" #define STRING_TASK_NO_ENTRY "Komento havas mankon de enskrib-dato: {1}" #define STRING_CMD_SYNC_USAGE "Sinkronigas datumojn kun la Taskserver" diff --git a/src/l10n/esp-ESP.h b/src/l10n/esp-ESP.h index af3eb69c8..41172eeba 100644 --- a/src/l10n/esp-ESP.h +++ b/src/l10n/esp-ESP.h @@ -468,6 +468,7 @@ #define STRING_CMD_IMPORT_SUMMARY "Importadas {1} tareas." #define STRING_CMD_IMPORT_NOFILE "Debe especificar un archivo a importar." #define STRING_CMD_IMPORT_FILE "Importando '{1}'" +#define STRING_CMD_IMPORT_MISSING "File '{1}' not found." #define STRING_TASK_NO_DESC "La anotación carece de descripción: {1}" #define STRING_TASK_NO_ENTRY "La anotación carece de fecha de entrada: {1}" diff --git a/src/l10n/fra-FRA.h b/src/l10n/fra-FRA.h index 958fd8ed7..a66b485f4 100644 --- a/src/l10n/fra-FRA.h +++ b/src/l10n/fra-FRA.h @@ -459,6 +459,7 @@ #define STRING_CMD_IMPORT_SUMMARY "Imported {1} tasks." #define STRING_CMD_IMPORT_NOFILE "You must specify a file to import." #define STRING_CMD_IMPORT_FILE "Importing '{1}'" +#define STRING_CMD_IMPORT_MISSING "File '{1}' not found." #define STRING_TASK_NO_DESC "Annotation is missing a description: {1}" #define STRING_TASK_NO_ENTRY "Annotation is missing an entry date: {1}" #define STRING_CMD_SYNC_USAGE "Synchronizes data with the Taskserver" diff --git a/src/l10n/ita-ITA.h b/src/l10n/ita-ITA.h index ae1c40e71..cb5cb00e6 100644 --- a/src/l10n/ita-ITA.h +++ b/src/l10n/ita-ITA.h @@ -460,6 +460,7 @@ #define STRING_CMD_IMPORT_SUMMARY "Importati {1} task." #define STRING_CMD_IMPORT_NOFILE "Specificare il file da importare." #define STRING_CMD_IMPORT_FILE "Importazione di '{1}'" +#define STRING_CMD_IMPORT_MISSING "File '{1}' not found." #define STRING_TASK_NO_DESC "Annotazione senza descrizione: {1}" #define STRING_TASK_NO_ENTRY "Annotazione senza data di immissione: {1}" #define STRING_CMD_SYNC_USAGE "Sincronizza i dati con il Taskserver" diff --git a/src/l10n/pol-POL.h b/src/l10n/pol-POL.h index aa36d4aff..c2dccd103 100644 --- a/src/l10n/pol-POL.h +++ b/src/l10n/pol-POL.h @@ -460,6 +460,7 @@ #define STRING_CMD_IMPORT_SUMMARY "Zaimportowano {1} zadań." #define STRING_CMD_IMPORT_NOFILE "Musisz podać plik do zaimportowania." #define STRING_CMD_IMPORT_FILE "Importowanie '{1}'" +#define STRING_CMD_IMPORT_MISSING "File '{1}' not found." #define STRING_TASK_NO_DESC "Komentarz nie posiada treści: {1}" #define STRING_TASK_NO_ENTRY "Komentarz nie posiada daty utworzenia: {1}" #define STRING_CMD_SYNC_USAGE "Synchronizuje dane z serwerem zadań" diff --git a/src/l10n/por-PRT.h b/src/l10n/por-PRT.h index 37daad0b4..900905cfe 100644 --- a/src/l10n/por-PRT.h +++ b/src/l10n/por-PRT.h @@ -460,6 +460,7 @@ #define STRING_CMD_IMPORT_SUMMARY "Importadas {1} tarefas." #define STRING_CMD_IMPORT_NOFILE "Necessita especificar o ficheiro a importar." #define STRING_CMD_IMPORT_FILE "A importar '{1}'" +#define STRING_CMD_IMPORT_MISSING "File '{1}' not found." #define STRING_TASK_NO_DESC "Descrição da anotação em falta: {1}" #define STRING_TASK_NO_ENTRY "Data de entrada da anotação em falta: {1}" #define STRING_CMD_SYNC_USAGE "Sincroniza dados com o Taskserver" diff --git a/test/tw-1441.t b/test/tw-1441.t new file mode 100755 index 000000000..23f430719 --- /dev/null +++ b/test/tw-1441.t @@ -0,0 +1,30 @@ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- + +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 TestBug1441(TestCase): + def setUp(self): + self.t = Task() + + def test_import_filename(self): + """import fails if file doesn't exist""" + command = ("import", "somefile", "otherfile") + code, out, err = self.t.runError(command) + + self.assertIn("File 'somefile' not found.", err) + self.assertIn("File 'otherfile' not found.", err) + + +if __name__ == "__main__": + from simpletap import TAPTestRunner + unittest.main(testRunner=TAPTestRunner()) + +# vim: ai sts=4 et sw=4