diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2019-11-17 14:11:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-17 14:11:55 +0200 |
commit | bb4bd7ab56e137c2e473e7febadba8617221c4d8 (patch) | |
tree | dbf661b7c5c330ff56d60955bd110cc6d96d1520 /test cases | |
parent | 894bf56346c667cf454972e59458f65c73323f79 (diff) | |
parent | 0cb48cdc793dfce8c5eeb17e447cbe169e1836d7 (diff) | |
download | meson-bb4bd7ab56e137c2e473e7febadba8617221c4d8.zip meson-bb4bd7ab56e137c2e473e7febadba8617221c4d8.tar.gz meson-bb4bd7ab56e137c2e473e7febadba8617221c4d8.tar.bz2 |
Merge pull request #6150 from scivision/fsexpand
fs module; make more robust, dedupe code, add method, add type anno & check
Diffstat (limited to 'test cases')
-rw-r--r-- | test cases/common/227 fs module/meson.build | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/test cases/common/227 fs module/meson.build b/test cases/common/227 fs module/meson.build index 515b3e2..3c452d0 100644 --- a/test cases/common/227 fs module/meson.build +++ b/test cases/common/227 fs module/meson.build @@ -1,11 +1,13 @@ project('fs module test') +is_windows = build_machine.system() == 'windows' + fs = import('fs') assert(fs.exists('meson.build'), 'Existing file reported as missing.') assert(not fs.exists('nonexisting'), 'Nonexisting file was found.') -if build_machine.system() != 'windows' and build_machine.system() != 'cygwin' +if not is_windows and build_machine.system() != 'cygwin' assert(fs.is_symlink('a_symlink'), 'Symlink not detected.') assert(not fs.is_symlink('meson.build'), 'Regular file detected as symlink.') endif @@ -18,4 +20,53 @@ assert(fs.is_dir('subprojects'), 'Dir not detected correctly.') assert(not fs.is_dir('meson.build'), 'File detected as a dir.') assert(not fs.is_dir('nonexisting'), 'Bad path detected as a dir.') +assert(fs.is_dir('~'), 'expanduser not working') +assert(not fs.is_file('~'), 'expanduser not working') + +original = 'foo.txt' +new = fs.replace_suffix(original, '.ini') +assert(new == 'foo.ini', 'replace_suffix failed') + +original = 'foo' +new = fs.replace_suffix(original, '.ini') +assert(new == 'foo.ini', 'replace_suffix did not add suffix to suffixless file') + +original = 'foo.dll.a' +new = fs.replace_suffix(original, '.so') +assert(new == 'foo.dll.so', 'replace_suffix did not only modify last suffix') + +original = 'foo.dll' +new = fs.replace_suffix(original, '') +assert(new == 'foo', 'replace_suffix did not only delete last suffix') + +# `/` on windows is interpreted like `.drive` which in general may not be `c:/` +# the files need not exist for fs.replace_suffix() +original = is_windows ? 'j:/foo/bar.txt' : '/foo/bar.txt' +new_check = is_windows ? 'j:\\foo\\bar.ini' : '/foo/bar.ini' + +new = fs.replace_suffix(original, '.ini') +assert(new == new_check, 'absolute path replace_suffix failed') + +# -- hash + +md5 = fs.hash('subdir/subdirfile.txt', 'md5') +sha256 = fs.hash('subdir/subdirfile.txt', 'sha256') +assert(md5 == 'd0795db41614d25affdd548314b30b3b', 'md5sum did not match') +assert(sha256 == 'be2170b0dae535b73f6775694fffa3fd726a43b5fabea11b7342f0605917a42a', 'sha256sum did not match') + +# -- size + +size = fs.size('subdir/subdirfile.txt') +assert(size == 19, 'file size not found correctly') + +# -- are filenames referring to the same file? +f1 = 'meson.build' +f2 = 'subdir/../meson.build' +assert(fs.samefile(f1, f2), 'samefile not realized') +assert(not fs.samefile(f1, 'subdir/subdirfile.txt'), 'samefile known bad comparison') + +if not is_windows and build_machine.system() != 'cygwin' + assert(fs.samefile('a_symlink', 'meson.build'), 'symlink samefile fail') +endif + subdir('subdir') |