From af1a266670d040d2f4083ff309d732d648afba2a Mon Sep 17 00:00:00 2001 From: Angelos Mouzakitis Date: Tue, 10 Oct 2023 14:33:42 +0000 Subject: Add submodule dependency files Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec --- meson/test cases/common/220 fs module/meson.build | 144 +++++++++++++++++++++ .../common/220 fs module/subdir/meson.build | 6 + .../common/220 fs module/subdir/subdirfile.txt | 1 + .../220 fs module/subprojects/subbie/meson.build | 11 ++ .../subprojects/subbie/subprojectfile.txt | 1 + .../subprojects/subbie/subsub/meson.build | 3 + .../subprojects/subbie/subsub/subsubfile.txt | 1 + 7 files changed, 167 insertions(+) create mode 100644 meson/test cases/common/220 fs module/meson.build create mode 100644 meson/test cases/common/220 fs module/subdir/meson.build create mode 100644 meson/test cases/common/220 fs module/subdir/subdirfile.txt create mode 100644 meson/test cases/common/220 fs module/subprojects/subbie/meson.build create mode 100644 meson/test cases/common/220 fs module/subprojects/subbie/subprojectfile.txt create mode 100644 meson/test cases/common/220 fs module/subprojects/subbie/subsub/meson.build create mode 100644 meson/test cases/common/220 fs module/subprojects/subbie/subsub/subsubfile.txt (limited to 'meson/test cases/common/220 fs module') diff --git a/meson/test cases/common/220 fs module/meson.build b/meson/test cases/common/220 fs module/meson.build new file mode 100644 index 000000000..7d10eb5fa --- /dev/null +++ b/meson/test cases/common/220 fs module/meson.build @@ -0,0 +1,144 @@ +project('fs module test') + +is_windows = build_machine.system() == 'windows' + +fs = import('fs') + +f = files('meson.build') + +assert(fs.exists('meson.build'), 'Existing file reported as missing.') +assert(not fs.exists('nonexisting'), 'Nonexisting file was found.') + +if not is_windows and build_machine.system() != 'cygwin' + # Symlinks on Windows have specific requirements including: + # * Meson running under Python >= 3.8 + # * Windows user permissions to create symlinks, and/or Windows in Developer mode + # so at this time the symlink test is skipped for Windows. + symlink = meson.current_build_dir() / 'a_symlink' + run_command('ln', '-s', meson.current_source_dir() / 'meson.build', symlink) + assert(fs.is_symlink(symlink), 'Symlink not detected.') + assert(not fs.is_symlink('meson.build'), 'Regular file detected as symlink.') + assert(not fs.is_symlink(f[0]), 'Regular file detected as symlink.') +endif + +assert(fs.is_file('meson.build'), 'File not detected as a file.') +assert(not fs.is_file('subprojects'), 'Directory detected as a file.') +assert(not fs.is_file('nonexisting'), 'Bad path detected as a file.') + +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('~'), 'home directory not detected') +assert(not fs.is_file('~'), 'home directory detected as file') + +# -- expanduser +assert(fs.expanduser('~') != '~','expanduser failed') +assert(fs.expanduser('~/foo').endswith('foo'), 'expanduser with tail failed') + +# -- as_posix +assert(fs.as_posix('/') == '/', 'as_posix idempotent') +assert(fs.as_posix('\\') == '/', 'as_posix simple') +assert(fs.as_posix('\\\\') == '/', 'as_posix simple') +assert(fs.as_posix('foo\\bar/baz') == 'foo/bar/baz', 'as_posix mixed slash') + +# -- is_absolute +winabs = 'q:/foo' +unixabs = '/foo' +if is_windows + assert(fs.is_absolute(winabs), 'is_absolute windows not detected') + assert(not fs.is_absolute(unixabs), 'is_absolute unix false positive') +else + assert(fs.is_absolute(unixabs), 'is_absolute unix not detected') + assert(not fs.is_absolute(winabs), 'is_absolute windows false positive') +endif + +# -- replace_suffix + +original = 'foo' +assert(fs.replace_suffix(original, '') == original, 'replace_suffix idempotent') +assert(fs.replace_suffix(f[0], '') == 'meson', 'replace_suffix trim') + +original = 'foo.txt' +new = fs.replace_suffix(original, '.ini') +assert(new == 'foo.ini', 'replace_suffix failed') + +new = fs.replace_suffix(f[0], '.ini') +assert(new == 'meson.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') + +f = files('subdir/subdirfile.txt') +md5 = fs.hash(f[0], 'md5') +assert(md5 == 'd0795db41614d25affdd548314b30b3b', 'md5sum did not match') +sha256 = fs.hash(f[0], 'sha256') +assert(sha256 == 'be2170b0dae535b73f6775694fffa3fd726a43b5fabea11b7342f0605917a42a', 'sha256sum did not match') + +# -- size + +size = fs.size('subdir/subdirfile.txt') +assert(size == 19, 'file size not found correctly') + +size = fs.size(f[0]) +assert(size == 19, 'file size not found correctly') + +# -- are filenames referring to the same file? +f1 = 'meson.build' +f2 = 'subdir/../meson.build' +assert(fs.is_samepath(f1, f2), 'is_samepath not detecting same files') +assert(fs.is_samepath(meson.source_root(), 'subdir/..'), 'is_samepath not detecting same directory') +assert(fs.is_samepath(meson.project_source_root(), 'subdir/..'), 'is_samepath not detecting same directory') +assert(fs.is_samepath(meson.project_build_root(), meson.current_build_dir() / 'subdir/..'), 'is_samepath not detecting same directory') +assert(fs.is_samepath(meson.global_source_root(), meson.current_source_dir()), 'is_samepath not detecting same directory') +assert(fs.is_samepath(meson.global_build_root(), meson.current_build_dir()), 'is_samepath not detecting same directory') +assert(not fs.is_samepath(f1, 'subdir/subdirfile.txt'), 'is_samepath known bad comparison') +assert(not fs.is_samepath('not-a-path', f2), 'is_samepath should not error if path(s) do not exist') + +f = files('meson.build', 'subdir/../meson.build') +assert(fs.is_samepath(f[0], f[1]), 'is_samepath not detercting same files') + +if not is_windows and build_machine.system() != 'cygwin' + assert(fs.is_samepath(symlink, 'meson.build'), 'symlink is_samepath fail') +endif + +# parts of path +assert(fs.parent('foo/bar') == 'foo', 'failed to get dirname') +if not is_windows +assert(fs.parent(f[1]) == 'subdir/..', 'failed to get dirname') +else +assert(fs.parent(f[1]) == 'subdir\..', 'failed to get dirname') +endif +assert(fs.name('foo/bar') == 'bar', 'failed to get basename') +assert(fs.name(f[1]) == 'meson.build', 'failed to get basename') +assert(fs.name('foo/bar/baz.dll.a') == 'baz.dll.a', 'failed to get basename with compound suffix') +assert(fs.stem('foo/bar/baz.dll') == 'baz', 'failed to get stem with suffix') +assert(fs.stem('foo/bar/baz.dll.a') == 'baz.dll', 'failed to get stem with compound suffix') + +subdir('subdir') + +subproject('subbie') diff --git a/meson/test cases/common/220 fs module/subdir/meson.build b/meson/test cases/common/220 fs module/subdir/meson.build new file mode 100644 index 000000000..0cd2475e9 --- /dev/null +++ b/meson/test cases/common/220 fs module/subdir/meson.build @@ -0,0 +1,6 @@ +subdirfiles = files('subdirfile.txt') +assert(fs.exists('subdirfile.txt'), 'Subdir file lookup is broken.') +assert(fs.is_samepath(meson.project_source_root(), '..'), 'is_samepath not detecting same directory') +assert(fs.is_samepath(meson.project_build_root(), meson.current_build_dir() / '..'), 'is_samepath not detecting same directory') + +assert(fs.is_samepath(subdirfiles[0], 'subdirfile.txt'), 'is_samepath not detecting same directory when using File and str') diff --git a/meson/test cases/common/220 fs module/subdir/subdirfile.txt b/meson/test cases/common/220 fs module/subdir/subdirfile.txt new file mode 100644 index 000000000..bcf7cc04b --- /dev/null +++ b/meson/test cases/common/220 fs module/subdir/subdirfile.txt @@ -0,0 +1 @@ +I have no content. diff --git a/meson/test cases/common/220 fs module/subprojects/subbie/meson.build b/meson/test cases/common/220 fs module/subprojects/subbie/meson.build new file mode 100644 index 000000000..f1e21ea10 --- /dev/null +++ b/meson/test cases/common/220 fs module/subprojects/subbie/meson.build @@ -0,0 +1,11 @@ +project('subbie') + +fs = import('fs') + +assert(fs.exists('subprojectfile.txt'), 'Subproject root file not found.') +assert(fs.is_samepath(meson.project_source_root(), meson.current_source_dir()), 'is_samepath not detecting same directory') +assert(fs.is_samepath(meson.project_build_root(), meson.current_build_dir()), 'is_samepath not detecting same directory') +assert(fs.is_samepath(meson.global_source_root(), meson.current_source_dir() / '../..'), 'is_samepath not detecting same directory') +assert(fs.is_samepath(meson.global_build_root(), meson.current_build_dir() / '../..'), 'is_samepath not detecting same directory') + +subdir('subsub') diff --git a/meson/test cases/common/220 fs module/subprojects/subbie/subprojectfile.txt b/meson/test cases/common/220 fs module/subprojects/subbie/subprojectfile.txt new file mode 100644 index 000000000..bedb84cc4 --- /dev/null +++ b/meson/test cases/common/220 fs module/subprojects/subbie/subprojectfile.txt @@ -0,0 +1 @@ +I'm not empty. So there's at least that. diff --git a/meson/test cases/common/220 fs module/subprojects/subbie/subsub/meson.build b/meson/test cases/common/220 fs module/subprojects/subbie/subsub/meson.build new file mode 100644 index 000000000..4ac68aea5 --- /dev/null +++ b/meson/test cases/common/220 fs module/subprojects/subbie/subsub/meson.build @@ -0,0 +1,3 @@ +assert(fs.exists('subsubfile.txt'), 'Subproject subdir lookup failed.') +assert(fs.is_samepath(meson.project_source_root(), meson.current_source_dir() / '..'), 'is_samepath not detecting same directory') +assert(fs.is_samepath(meson.project_build_root(), meson.current_build_dir() / '..'), 'is_samepath not detecting same directory') diff --git a/meson/test cases/common/220 fs module/subprojects/subbie/subsub/subsubfile.txt b/meson/test cases/common/220 fs module/subprojects/subbie/subsub/subsubfile.txt new file mode 100644 index 000000000..2d5120d66 --- /dev/null +++ b/meson/test cases/common/220 fs module/subprojects/subbie/subsub/subsubfile.txt @@ -0,0 +1 @@ +Thank you for looking inside me. -- cgit 1.2.3-korg