diff --git a/.github/workflows/single-file-build-and-test.yml b/.github/workflows/single-file-build-and-test.yml new file mode 100644 index 00000000..262e8b79 --- /dev/null +++ b/.github/workflows/single-file-build-and-test.yml @@ -0,0 +1,50 @@ +# Copyright 2023 Aurora Operations, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: single-file-build-and-test + +on: + push: + branches: + - main + pull_request: + +jobs: + build: + strategy: + matrix: + windows: [windows-2019, windows-2022] + + runs-on: ${{ matrix.windows }} + + steps: + - uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6 #v2.6.0 + + - name: Set up developer command prompt + uses: ilammy/msvc-dev-cmd@cec98b9d092141f74527d0afa6feb2af698cfe89 #v1.12.1 + + - name: Set up python + uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 #v3.1.4 + with: + python-version: '3.10' + + - name: Build single-file package + shell: cmd + run: python tools/bin/make-single-file --units meters seconds --version-id NA > au.hh + + - name: Build and run test + shell: cmd + run: | + cl.exe /std:c++14 single-file-test.cc + single-file-test.exe diff --git a/au/quantity.hh b/au/quantity.hh index fa30a76e..1f706a98 100644 --- a/au/quantity.hh +++ b/au/quantity.hh @@ -142,8 +142,8 @@ class Quantity { template ::value>> - constexpr auto as(NewUnit u) const { - constexpr auto ratio = unit_ratio(unit, u); + constexpr auto as(NewUnit) const { + constexpr auto ratio = unit_ratio(unit, NewUnit{}); using Common = std::common_type_t; constexpr auto NUM = integer_part(numerator(ratio)); @@ -158,7 +158,7 @@ class Quantity { template ::value>> constexpr auto as(NewUnit u) const { - static_assert(implicit_rep_permitted_from_source_to_target(unit, u), + static_assert(implicit_rep_permitted_from_source_to_target(unit, NewUnit{}), "Dangerous conversion: use .as(NewUnit) instead"); return as(u); } diff --git a/single-file-test.cc b/single-file-test.cc new file mode 100644 index 00000000..62e8bd99 --- /dev/null +++ b/single-file-test.cc @@ -0,0 +1,48 @@ +// Copyright 2023 Aurora Operations, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include + +#include "au.hh" + +// This file builds all of the code in the single-file package of Au, and runs some basic tests. +// +// If we find any failures not covered by this file, we can add more test cases as needed. +// +// Note that this file will *not* be built with bazel. It's therefore important that we avoid all +// dependencies outside of the C++14 standard library, and the single-file package of Au itself. + +using namespace au; + +// This ad hoc utility is a stand-in for GTEST, which we can't use here. +template +bool expect_equal(ExpectedT expected, ActualT actual) { + if (expected != actual) { + std::cerr << "Failure! Expected (" << expected << "); Actual (" << actual << ")" + << std::endl; + return false; + } + return true; +} + +int main(int argc, char **argv) { + const std::vector results{ + { + expect_equal((meters / second)(5) * seconds(6), meters(30)), + }, + }; + return std::all_of(std::begin(results), std::end(results), [](auto x) { return x; }) ? 0 : 1; +}