-
Nick Draper authored
Update copyright headers in all files Squashed commit of the following: * First version of a script to manage copyright statements re #23468 * Neatened up script, added comments re #23488 * move script to tools directory re #23488 * small script changes and a couple of manual file changes re #23488 * Minor chnage to whitespace detection in regex re #23488 * Add an excluded directory re #23488 * remove a repeasted copyright statement in a file re #23488 * Don't comsume the comment end if it is on the same line re #23488 * fix error in new copright parsing re #23488 * remove double copyrifght entry re #23488 * Improve handling of old copyrights at the start of comments re #23488 * remove empty comments re #23488 * exclude gsoapgenerated directories re #23488 * Sort out greedy line matching re #23488 * improve empty comment removal re #23488 * improve false positives re #23488 * impressive speedup by limiting regex matching length re #23488 * remove evil invisible non ascii character Also upadte the copyright at the same time re #23488 * resolve multiple copyrights in a single file re #23488 * resolve an issue with new statement detection re #23488 * another unprintable unicode character re #23488 * pep updates and cmake the new copyright fit clang format re #23488 * update already done new format headers re #23488 * wrong type of bracket re #23488 * Update class_maker and friends re #23488 * Update all copyright statements re #23488 * clang format re #23488 * flake8 warnings re #23488 * Flake8 warnings re #23488 * Exclude .cmake.in and rb.in files re #23488 * replace missing line re #23488 * exclude .py.in files as they are flasely recognized as C++ re #23488 * another setp.py.in re #23488 * another .py.in correction re #23488 * Hopefully the last of the .py.in files re #23488 * resolve utf-8 encoding of python files and changed ABINS checksum re #23488 * updates to unit tests that reference line numbers re #23488 * remaining unit test files and other fixes re #23488
Nick Draper authoredUpdate copyright headers in all files Squashed commit of the following: * First version of a script to manage copyright statements re #23468 * Neatened up script, added comments re #23488 * move script to tools directory re #23488 * small script changes and a couple of manual file changes re #23488 * Minor chnage to whitespace detection in regex re #23488 * Add an excluded directory re #23488 * remove a repeasted copyright statement in a file re #23488 * Don't comsume the comment end if it is on the same line re #23488 * fix error in new copright parsing re #23488 * remove double copyrifght entry re #23488 * Improve handling of old copyrights at the start of comments re #23488 * remove empty comments re #23488 * exclude gsoapgenerated directories re #23488 * Sort out greedy line matching re #23488 * improve empty comment removal re #23488 * improve false positives re #23488 * impressive speedup by limiting regex matching length re #23488 * remove evil invisible non ascii character Also upadte the copyright at the same time re #23488 * resolve multiple copyrights in a single file re #23488 * resolve an issue with new statement detection re #23488 * another unprintable unicode character re #23488 * pep updates and cmake the new copyright fit clang format re #23488 * update already done new format headers re #23488 * wrong type of bracket re #23488 * Update class_maker and friends re #23488 * Update all copyright statements re #23488 * clang format re #23488 * flake8 warnings re #23488 * Flake8 warnings re #23488 * Exclude .cmake.in and rb.in files re #23488 * replace missing line re #23488 * exclude .py.in files as they are flasely recognized as C++ re #23488 * another setp.py.in re #23488 * another .py.in correction re #23488 * Hopefully the last of the .py.in files re #23488 * resolve utf-8 encoding of python files and changed ABINS checksum re #23488 * updates to unit tests that reference line numbers re #23488 * remaining unit test files and other fixes re #23488
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
FileValidatorTest.h 3.77 KiB
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source
// & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
#ifndef FILEVALIDATORTEST_H_
#define FILEVALIDATORTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidKernel/FileValidator.h"
#include <Poco/File.h>
using namespace Mantid::Kernel;
class FileValidatorTest : public CxxTest::TestSuite {
public:
void testConstructors() {
// empty constructor
FileValidator v1;
TS_ASSERT_EQUALS(v1.allowedValues().size(), 0);
// one with a vector of extensions
FileValidator v2({"raw", "RAW"});
// File extensions are converted to lowercase so should have one unique
// extension
TS_ASSERT_EQUALS(v2.allowedValues().size(), 1);
}
void testPassesOnExistentFile() {
// Create two files, one with the extension within the validator and one
// without
const std::string file_stub = "scratch.";
const std::string ext1 = "txt";
const std::string ext2 = "raw";
Poco::File txt_file(file_stub + ext1);
Poco::File raw_file(file_stub + ext2);
try {
txt_file.createFile();
raw_file.createFile();
} catch (std::exception &) {
TS_FAIL(
"Error creating test file for \"testPassesOnExistentFile\" test.");
}
// FileValidator will suggest txt files as correct extension
std::vector<std::string> vec(1, "txt");
FileValidator v1(vec);
TS_ASSERT_EQUALS(v1.isValid(txt_file.path()), "");
// Not correct extension but the file exists so we allow it
TS_ASSERT_EQUALS(v1.isValid(raw_file.path()), "");
txt_file.remove();
raw_file.remove();
}
void testPassesForMoreComplicatedExtensions() {
// More general test cases (Refs #1302)
const std::string file_stub = "scratch";
const std::string ext1 = ".tar.gz";
const std::string ext2 = "_event.dat";
Poco::File txt_file(file_stub + ext1);
Poco::File raw_file(file_stub + ext2);
try {
txt_file.createFile();
raw_file.createFile();
} catch (std::exception &) {
TS_FAIL("Error creating test file for "
"\"testPassesForMoreComplicatedExtensions\" test.");
}
// FileValidator will suggest txt files as correct extension
std::vector<std::string> vec(1, ".tar.gz");
FileValidator v1(vec);
TS_ASSERT_EQUALS(v1.isValid(txt_file.path()), "");
// Not correct extension but the file exists so we allow it
TS_ASSERT_EQUALS(v1.isValid(raw_file.path()), "");
txt_file.remove();
raw_file.remove();
}
void testFailsOnNonexistentFile() {
std::string NoFile("myJunkFile_hgfvj.cpp");
std::vector<std::string> vec{"cpp"};
FileValidator v(vec);
TS_ASSERT_EQUALS(v.isValid(NoFile), "File \"" + NoFile + "\" not found");
}
void testPassesOnNonexistentFile() {
std::string NoFile("myJunkFile_hgfvj.cpp");
std::vector<std::string> vec{"cpp"};
FileValidator v(vec, false);
TS_ASSERT_EQUALS(v.isValid(NoFile), "");
}
void testFailsOnEmptyFileString() {
FileValidator file_val;
TS_ASSERT_EQUALS(file_val.isValid(""), "File \"\" not found");
}
void testCanWrite() {
std::string filename("myJunkFile_hgfvj.cpp");
// file existance is optional
FileValidator v1(std::vector<std::string>(), false, true);
TS_ASSERT_EQUALS(v1.isValid(""), "Cannot write to empty filename");
TS_ASSERT_EQUALS(v1.isValid(filename), "");
// file existance is required
FileValidator v2(std::vector<std::string>(), true, true);
TS_ASSERT_EQUALS(v2.isValid(""), "File \"\" not found");
TS_ASSERT_EQUALS(v2.isValid(filename),
"File \"" + filename + "\" not found");
}
};
#endif /*FILEVALIDATORTEST_H_*/