From 2c4ac33942e557de0bcc2b4d0c5e5fc8de32de2a Mon Sep 17 00:00:00 2001 From: Ivan De Marino Date: Mon, 8 Aug 2011 23:42:11 +0100 Subject: [PATCH 1/2] Filesystem API: completed the "Tests" API group from CommonJS/Filesystem definition. * Tests provided in "fs-spec-04.js" * I also slightly enriched the "jasmine-console.js" reporter to get a bit more info --- src/filesystem.cpp | 22 ++++++++++++ src/filesystem.h | 11 +++--- test/fs-spec-04.js | 70 +++++++++++++++++++++++++++++++++++++ test/lib/jasmine-console.js | 24 ++++++------- test/run-tests.js | 1 + 5 files changed, 109 insertions(+), 19 deletions(-) create mode 100644 test/fs-spec-04.js diff --git a/src/filesystem.cpp b/src/filesystem.cpp index e3f3f7e2..d0e2b77c 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -142,6 +142,7 @@ QVariant FileSystem::lastModified(const QString &path) const return QVariant(QDateTime()); } +// Tests bool FileSystem::exists(const QString &path) const { return QFile::exists(path); @@ -157,6 +158,27 @@ bool FileSystem::isFile(const QString &path) const return QFileInfo(path).isFile(); } +bool FileSystem::isAbsolute(const QString &path) const { + return QFileInfo(path).isAbsolute(); +} + +bool FileSystem::isExecutable(const QString &path) const { + return QFileInfo(path).isExecutable(); +} + +bool FileSystem::isLink(const QString &path) const { + return QFileInfo(path).isSymLink(); +} + +bool FileSystem::isReadable(const QString &path) const { + return QFileInfo(path).isReadable(); +} + +bool FileSystem::isWritable(const QString &path) const { + return QFileInfo(path).isWritable(); +} + +// Directory bool FileSystem::makeDirectory(const QString &path) const { return QDir().mkdir(path); diff --git a/src/filesystem.h b/src/filesystem.h index eb998011..f9d9bb8f 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -113,12 +113,11 @@ public slots: bool exists(const QString &path) const; bool isDirectory(const QString &path) const; bool isFile(const QString &path) const; - // - isAbsolute() - // - isExecutable() - // - isLink() - // - isMount() - // - isReadable() - // - isWritable() + bool isAbsolute(const QString &path) const; + bool isExecutable(const QString &path) const; + bool isReadable(const QString &path) const; + bool isWritable(const QString &path) const; + bool isLink(const QString &path) const; }; #endif // FILESYSTEM_H diff --git a/test/fs-spec-04.js b/test/fs-spec-04.js new file mode 100644 index 00000000..c8be011b --- /dev/null +++ b/test/fs-spec-04.js @@ -0,0 +1,70 @@ +describe("Tests Files API", function() { + var ABSENT_DIR = "absentdir04", + ABSENT_FILE = "absentfile04", + TEST_DIR = "testdir04", + TEST_FILE = "testfile04", + TEST_FILE_PATH = TEST_DIR + fs.separator + TEST_FILE, + TEST_CONTENT = "test content", + START_CWD = null; + + it("should create some temporary file and directory", function(){ + fs.makeDirectory(TEST_DIR); + fs.write(TEST_FILE_PATH, TEST_CONTENT, "w"); + }); + + it("should confirm that test file and test dir exist, while the absent ones don't", function(){ + expect(fs.exists(TEST_FILE_PATH)).toBeTruthy(); + expect(fs.exists(TEST_DIR)).toBeTruthy(); + expect(fs.exists(ABSENT_FILE)).toBeFalsy(); + expect(fs.exists(ABSENT_DIR)).toBeFalsy(); + }); + + it("should confirm that the temporary directory is infact a directory, while the absent one doesn't", function(){ + expect(fs.isDirectory(TEST_DIR)).toBeTruthy(); + expect(fs.isDirectory(ABSENT_DIR)).toBeFalsy(); + }); + + it("should confirm that the temporary file is infact a file, while the absent one doesn't", function(){ + expect(fs.isFile(TEST_FILE_PATH)).toBeTruthy(); + expect(fs.isFile(ABSENT_FILE)).toBeFalsy(); + }); + + it("should confirm that a relative path is not absolute, while an absolute one is", function(){ + var absPath = fs.absolute(TEST_FILE_PATH); + + expect(fs.isAbsolute(TEST_FILE_PATH)).toBeFalsy(); + expect(fs.isAbsolute(absPath)).toBeTruthy(); + }); + + it("should confirm that temporary file is readable, writable and non-executable, while absent file is none of those", function(){ + expect(fs.isReadable(TEST_FILE_PATH)).toBeTruthy(); + expect(fs.isWritable(TEST_FILE_PATH)).toBeTruthy(); + expect(fs.isExecutable(TEST_FILE_PATH)).toBeFalsy(); + + expect(fs.isReadable(ABSENT_FILE)).toBeFalsy(); + expect(fs.isWritable(ABSENT_FILE)).toBeFalsy(); + expect(fs.isExecutable(ABSENT_FILE)).toBeFalsy(); + }); + + it("should confirm that temporary directory is readable, writable and executable, while absent dir is none of those", function(){ + expect(fs.isReadable(TEST_DIR)).toBeTruthy(); + expect(fs.isWritable(TEST_DIR)).toBeTruthy(); + expect(fs.isExecutable(TEST_DIR)).toBeTruthy(); + + expect(fs.isReadable(ABSENT_DIR)).toBeFalsy(); + expect(fs.isWritable(ABSENT_DIR)).toBeFalsy(); + expect(fs.isExecutable(ABSENT_DIR)).toBeFalsy(); + }); + + it("should confirm that neither temporary file/dir or absent file/dir are links", function(){ + expect(fs.isLink(TEST_DIR)).toBeFalsy(); + expect(fs.isLink(TEST_FILE_PATH)).toBeFalsy(); + expect(fs.isLink(ABSENT_DIR)).toBeFalsy(); + expect(fs.isLink(ABSENT_FILE)).toBeFalsy(); + }); + + it("should delete the temporary directory and file", function(){ + fs.removeTree(TEST_DIR); + }); + +}); \ No newline at end of file diff --git a/test/lib/jasmine-console.js b/test/lib/jasmine-console.js index e65be81b..cac03eed 100644 --- a/test/lib/jasmine-console.js +++ b/test/lib/jasmine-console.js @@ -40,12 +40,12 @@ jasmine.ConsoleReporter = function(print, doneCallback, showColors) { newline(); } - function greenDot() { - print(greenStr(".")); + function greenPass() { + print(greenStr("PASS")); } - function redF() { - print(redStr("F")); + function redFail() { + print(redStr("FAIL")); } function yellowStar() { @@ -76,10 +76,8 @@ jasmine.ConsoleReporter = function(print, doneCallback, showColors) { function specFailureDetails(suiteDescription, specDescription, stackTraces) { newline(); print(suiteDescription + " " + specDescription); - newline(); for (var i = 0; i < stackTraces.length; i++) { print(indent(stackTraces[i], 2)); - newline(); } } @@ -92,8 +90,6 @@ jasmine.ConsoleReporter = function(print, doneCallback, showColors) { newline(); print(colorF(specs + " " + plural(language.spec, specs) + ", " + failed + " " + plural(language.failure, failed))); - newline(); - newline(); } function greenSummary(specs, failed) { @@ -126,10 +122,14 @@ jasmine.ConsoleReporter = function(print, doneCallback, showColors) { var results = spec.results(); if (results.skipped) { yellowStar(); - } else if (results.passed()) { - greenDot(); } else { - redF(); + if (results.passed()) { + print('#' + spec.id + ' ' + spec.suite.description + ': ' + spec.description); + greenPass(); + } else { + print(redStr('#' + spec.id + ' ' + spec.suite.description + ': ' + spec.description)); + redFail(); + } } }; @@ -161,8 +161,6 @@ jasmine.ConsoleReporter = function(print, doneCallback, showColors) { } this.reportRunnerResults = function(runner) { - newline(); - eachSpecFailure(this.suiteResults, function(suiteDescription, specDescription, stackTraces) { specFailureDetails(suiteDescription, specDescription, stackTraces); }); diff --git a/test/run-tests.js b/test/run-tests.js index 7464e75c..b545a573 100644 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -7,6 +7,7 @@ phantom.injectJs("./phantom-spec.js"); phantom.injectJs("./fs-spec-01.js"); //< Filesystem Specs 01 (Basic) phantom.injectJs("./fs-spec-02.js"); //< Filesystem Specs 02 (Attributes) phantom.injectJs("./fs-spec-03.js"); //< Filesystem Specs 02 (Paths) +phantom.injectJs("./fs-spec-04.js"); //< Filesystem Specs 02 (Tests) // Launch tests var jasmineEnv = jasmine.getEnv(); From 512de8c9b1ae86fd8951d9a99dfaf015b39d790d Mon Sep 17 00:00:00 2001 From: Ivan De Marino Date: Mon, 8 Aug 2011 23:46:56 +0100 Subject: [PATCH 2/2] Fixed typo. --- test/run-tests.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/run-tests.js b/test/run-tests.js index b545a573..03d355e4 100644 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -6,8 +6,8 @@ phantom.injectJs("./lib/jasmine-console.js"); phantom.injectJs("./phantom-spec.js"); phantom.injectJs("./fs-spec-01.js"); //< Filesystem Specs 01 (Basic) phantom.injectJs("./fs-spec-02.js"); //< Filesystem Specs 02 (Attributes) -phantom.injectJs("./fs-spec-03.js"); //< Filesystem Specs 02 (Paths) -phantom.injectJs("./fs-spec-04.js"); //< Filesystem Specs 02 (Tests) +phantom.injectJs("./fs-spec-03.js"); //< Filesystem Specs 03 (Paths) +phantom.injectJs("./fs-spec-04.js"); //< Filesystem Specs 04 (Tests) // Launch tests var jasmineEnv = jasmine.getEnv();