|
| 1 | +/* |
| 2 | + This file is part of solidity. |
| 3 | +
|
| 4 | + solidity is free software: you can redistribute it and/or modify |
| 5 | + it under the terms of the GNU General Public License as published by |
| 6 | + the Free Software Foundation, either version 3 of the License, or |
| 7 | + (at your option) any later version. |
| 8 | +
|
| 9 | + solidity is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + GNU General Public License for more details. |
| 13 | +
|
| 14 | + You should have received a copy of the GNU General Public License |
| 15 | + along with solidity. If not, see <http://www.gnu.org/licenses/>. |
| 16 | +*/ |
| 17 | +// SPDX-License-Identifier: GPL-3.0 |
| 18 | + |
| 19 | +/// Unit tests for the CommonIO routines. |
| 20 | + |
| 21 | +#include <libsolutil/CommonIO.h> |
| 22 | + |
| 23 | +#include <test/Common.h> |
| 24 | +#include <test/FilesystemUtils.h> |
| 25 | +#include <test/TemporaryDirectory.h> |
| 26 | +#include <test/libsolidity/util/SoltestErrors.h> |
| 27 | + |
| 28 | +#include <boost/test/unit_test.hpp> |
| 29 | +#include <boost/filesystem.hpp> |
| 30 | + |
| 31 | +#include <fstream> |
| 32 | +#include <string> |
| 33 | + |
| 34 | +using namespace std; |
| 35 | +using namespace solidity::test; |
| 36 | + |
| 37 | +namespace solidity::util::test |
| 38 | +{ |
| 39 | + |
| 40 | +BOOST_AUTO_TEST_SUITE(CommonIOTest) |
| 41 | + |
| 42 | +BOOST_AUTO_TEST_CASE(readFileAsString_regular_file) |
| 43 | +{ |
| 44 | + TemporaryDirectory tempDir("common-io-test-"); |
| 45 | + createFileWithContent(tempDir.path() / "test.txt", "ABC\ndef\n"); |
| 46 | + |
| 47 | + BOOST_TEST(readFileAsString((tempDir.path() / "test.txt").string()) == "ABC\ndef\n"); |
| 48 | +} |
| 49 | + |
| 50 | +BOOST_AUTO_TEST_CASE(readFileAsString_directory) |
| 51 | +{ |
| 52 | + TemporaryDirectory tempDir("common-io-test-"); |
| 53 | + BOOST_CHECK_THROW(readFileAsString(tempDir.path().string()), NotAFile); |
| 54 | +} |
| 55 | + |
| 56 | +BOOST_AUTO_TEST_CASE(readFileAsString_symlink) |
| 57 | +{ |
| 58 | + TemporaryDirectory tempDir("common-io-test-"); |
| 59 | + createFileWithContent(tempDir.path() / "test.txt", "ABC\ndef\n"); |
| 60 | + |
| 61 | + if (!createSymlinkIfSupportedByFilesystem("test.txt", tempDir.path() / "symlink.txt")) |
| 62 | + return; |
| 63 | + |
| 64 | + BOOST_TEST(readFileAsString((tempDir.path() / "symlink.txt").string()) == "ABC\ndef\n"); |
| 65 | +} |
| 66 | + |
| 67 | +BOOST_AUTO_TEST_SUITE_END() |
| 68 | + |
| 69 | +} // namespace solidity::util::test |
0 commit comments