pantry/projects/github.com/TartanLlama/expected/package.yml

60 lines
1.3 KiB
YAML
Raw Normal View History

2023-08-09 18:27:04 +03:00
distributable:
url: https://github.com/TartanLlama/expected/archive/refs/tags/v{{version}}.tar.gz
strip-components: 1
versions:
github: TartanLlama/expected
aka: tl-expected
build:
dependencies:
tea.xyz/gx/cc: c99
tea.xyz/gx/make: '*'
cmake.org: ^3
working-directory: build
script:
- cmake ..
-DCMAKE_INSTALL_PREFIX={{prefix}}
-DCMAKE_BUILD_TYPE=Release
- make --jobs {{ hw.concurrency }} install
test:
dependencies:
tea.xyz/gx/cc: c99
fixture: |
#include <iostream>
#include <tl/expected.hpp>
tl::expected<int, std::string> divide(int a, int b) {
if (b == 0) {
return tl::make_unexpected("Division by zero");
}
return a / b;
}
int main() {
auto result = divide(10, 5);
if (result) {
std::cout << "Result: " << *result << std::endl;
} else {
std::cout << "Error: " << result.error() << std::endl;
}
result = divide(2, 0);
if (result) {
std::cout << "Result: " << *result << std::endl;
} else {
std::cout << "Error: " << result.error() << std::endl;
}
return 0;
}
script: |
mv $FIXTURE b.cpp
c++ b.cpp -std=c++17
out="$(./a.out)"
test "$out" = "Result: 2
Error: Division by zero"