-
Notifications
You must be signed in to change notification settings - Fork 2.4k
meson: add tests #1044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
meson: add tests #1044
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# SPDX-FileCopyrightText: 2021 Andrea Pappacoda | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
gtest_dep = dependency('gtest', main: true) | ||
openssl = find_program('openssl') | ||
test_conf = files('test.conf') | ||
|
||
key_pem = custom_target( | ||
'key_pem', | ||
output: 'key.pem', | ||
command: [openssl, 'genrsa', '-out', '@OUTPUT@', '2048'] | ||
) | ||
|
||
temp_req = custom_target( | ||
'temp_req', | ||
input: key_pem, | ||
output: 'temp_req', | ||
command: [openssl, 'req', '-new', '-batch', '-config', test_conf, '-key', '@INPUT@', '-out', '@OUTPUT@'] | ||
) | ||
|
||
cert_pem = custom_target( | ||
'cert_pem', | ||
input: [temp_req, key_pem], | ||
output: 'cert.pem', | ||
command: [openssl, 'x509', '-in', '@INPUT0@', '-days', '3650', '-req', '-signkey', '@INPUT1@', '-out', '@OUTPUT@'] | ||
) | ||
|
||
cert2_pem = custom_target( | ||
'cert2_pem', | ||
input: key_pem, | ||
output: 'cert2.pem', | ||
command: [openssl, 'req', '-x509', '-config', test_conf, '-key', '@INPUT@', '-sha256', '-days', '3650', '-nodes', '-out', '@OUTPUT@', '-extensions', 'SAN'] | ||
) | ||
|
||
rootca_key_pem = custom_target( | ||
'rootca_key_pem', | ||
output: 'rootCA.key.pem', | ||
command: [openssl, 'genrsa', '-out', '@OUTPUT@', '2048'] | ||
) | ||
|
||
rootca_cert_pem = custom_target( | ||
'rootca_cert_pem', | ||
input: rootca_key_pem, | ||
output: 'rootCA.cert.pem', | ||
command: [openssl, 'req', '-x509', '-new', '-batch', '-config', files('test.rootCA.conf'), '-key', '@INPUT@', '-days', '1024', '-out', '@OUTPUT@'] | ||
) | ||
|
||
client_key_pem = custom_target( | ||
'client_key_pem', | ||
output: 'client.key.pem', | ||
command: [openssl, 'genrsa', '-out', '@OUTPUT@', '2048'] | ||
) | ||
|
||
client_temp_req = custom_target( | ||
'client_temp_req', | ||
input: client_key_pem, | ||
output: 'client_temp_req', | ||
command: [openssl, 'req', '-new', '-batch', '-config', test_conf, '-key', '@INPUT@', '-out', '@OUTPUT@'] | ||
) | ||
|
||
client_cert_pem = custom_target( | ||
'client_cert_pem', | ||
input: [client_temp_req, rootca_cert_pem, rootca_key_pem], | ||
output: 'client.cert.pem', | ||
command: [openssl, 'x509', '-in', '@INPUT0@', '-days', '370', '-req', '-CA', '@INPUT1@', '-CAkey', '@INPUT2@', '-CAcreateserial', '-out', '@OUTPUT@'] | ||
) | ||
|
||
# Copy test files to the build directory | ||
configure_file(input: 'ca-bundle.crt', output: 'ca-bundle.crt', copy: true) | ||
configure_file(input: 'image.jpg', output: 'image.jpg', copy: true) | ||
subdir(join_paths('www', 'dir')) | ||
subdir(join_paths('www2', 'dir')) | ||
subdir(join_paths('www3', 'dir')) | ||
|
||
test( | ||
'main', | ||
executable( | ||
'main', | ||
'test.cc', | ||
dependencies: [ | ||
cpp_httplib_dep, | ||
gtest_dep | ||
] | ||
), | ||
depends: [ | ||
key_pem, | ||
cert_pem, | ||
cert2_pem, | ||
rootca_key_pem, | ||
rootca_cert_pem, | ||
client_key_pem, | ||
client_cert_pem | ||
], | ||
workdir: meson.current_build_dir(), | ||
timeout: 300 | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SPDX-FileCopyrightText: 2021 Andrea Pappacoda | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
configure_file(input: 'index.html', output: 'index.html', copy: true) | ||
configure_file(input: 'test.abcde', output: 'test.abcde', copy: true) | ||
configure_file(input: 'test.html', output: 'test.html', copy: true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# SPDX-FileCopyrightText: 2021 Andrea Pappacoda | ||
Tachi107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
configure_file(input: 'index.html', output: 'index.html', copy: true) | ||
configure_file(input: 'test.html', output: 'test.html', copy: true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# SPDX-FileCopyrightText: 2021 Andrea Pappacoda | ||
Tachi107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
configure_file(input: 'index.html', output: 'index.html', copy: true) | ||
configure_file(input: 'test.html', output: 'test.html', copy: true) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove this file from 'test/www/dir' directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I can't.
The "old" tests are run in-tree, and require
ca-bundle.crt
,image.jpg
www/dir*/*
to be ran.In-tree builds are disallowed in Meson (and discouraged in CMake), so it is necessary to copy the required files in the build directory to recreate the same directory structure as the one found in the source tree (that is,
test/ca-bundle.crt
→build/test/ca-bundle.crt
, etc). Copying files to the build dir is accomplished by theconfigure_file(input: 'filename', output: 'filename', copy: true)
function, where the input is a file name relative to the same directory as the currentmeson.build
file. Copying a file from a subdirectory is not allowed, as Meson guaranties that a file in a certain file in the build dir (likebuild/test/www/dir/index.html
) has to come from the same path of the source tree (test/www/dir/index.html
).This makes debugging easier, but obviously has the downside of having to create a
meson.build
file in the same dir as the files you want to copy. So I can't remove these three files :/Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'www', 'www2' and 'www3' are just htdocs folders, and I may add more such folders like 'www4' in the future. I would not like to remember adding 'meson.build' file each time I add a new data directory, and it puts an extra burden on me. I personally don't care for testing on Meson build system when testing, because I only use just plain 'Make' files and it's enough. (CMake in this project just focus on build and install, but not test.)
So I am thinking not to accept this pull request. Sorry for my decision, but thanks for your efforts so far and understanding my situation!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your concern, but don't worry, the worst that could happen if you don't add the meson.build file is a failed test, better than no tests at all :)
I've committed to maintain the Meson part of this repo, so if something Meson-related has issues I'll fix it as soon as possible (the same way @sum01 is the "maintainer" of the CMake portion of cpp-httplib).
If for whatever reason I stop maintaining something that needs to be updated (like the tests) you're always free to remove it (like you did with CMake some time ago).
Having tests that ensure that Meson users do not use a broken build of the library (when not using the header-only version) are important to ensure that cpp-httplib will always work fine for everyone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad to see your willingness! I'll merge it.