fktn-k / fkYAML

A C++ header-only YAML library
MIT License
69 stars 7 forks source link

Tutorial case #262

Closed burgreen closed 10 months ago

burgreen commented 10 months ago

Description

First, thank you for sharing this library.

In the tutorial instructions: target_link_library(example PRIVATE fkYAML::fkYAML) needs to be changed to target_link_libraries(example PRIVATE fkYAML::fkYAML)

When running the first test case to read the novels YAML file. I get this error on a Mac with the main 0.3.0 branch: libc++abi: terminating due to uncaught exception of type fkyaml::v0_3_0::parse_error: parse_error: Invalid character found in a negative number token. (at line 2, column 2) Abort trap: 6

Reproduction steps

See above

Expected vs. actual results

See above

Minimal code example

No response

Error messages

No response

Compiler and operating system

clang 14, mac darwin

Library version

0.3.0

Validation

fktn-k commented 10 months ago

@burgreen
Thanks for sharing issues you faced.

target_link_library(example PRIVATE fkYAML::fkYAML) needs to be changed to target_link_libraries(example PRIVATE fkYAML::fkYAML)

You're right...Sorry for your inconvenience. I'll fix the typo soon.


As for the error, I've built and run a tutorial on ubuntu22.04 with gcc-11.4.0 & clang 14.0.0 and no errors emitted in both debug/release modes.
But I met build errors when I built the tutorial on Windows10 with Visual Studio 16 2019 and had to made the following changes:

from (where)

template <typename ItrType>
static basic_node deserialize(ItrType&& begin, ItrType&& end)
{
    return deserializer_type().deserialize(
        detail::input_adapter(std::forward<ItrType>(begin), std::forward<ItrType>(end)));
}

to

template <typename ItrType>
static basic_node deserialize(ItrType begin, ItrType end)
{
    return deserializer_type().deserialize(
        detail::input_adapter(std::move(begin), std::move(end)));
}

Since I don't have any macOS environment locally, it would be very helpful if you could check if the changes above fix the error on your environment as well.

burgreen commented 10 months ago

Thanks for your reply. That change made behavior worse.

For the original novels.yaml file, it gives: libc++abi: terminating due to uncaught exception of type fkyaml::v0_3_0::parse_error: parse_error: Invalid character found in a negative number token. (at line 2, column 2)

For a simpler yaml file:

novels:
    title: Robinson Crusoe
    author: Daniel Defoe
    year: 1678

The previous source code worked fine. With the suggested change, it fails with: libc++abi: terminating due to uncaught exception of type fkyaml::v0_3_0::type_error: type_error: operator[] is unavailable for a scalar node. type=string

I am using: set(CMAKE_CXX_STANDARD 17)

C++11 will give the same errors.

$ gcc --version
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: x86_64-apple-darwin22.5.0
Thread model: posix
fktn-k commented 10 months ago

@burgreen
That's weired... I can successfully run the tutorial app with the simpler yaml file as well.
Did you check if you can compile and run the unit tests on your environment?
You can check that with commands like:

$ cd path/to/fkYAML
$ mkdir build && cd build
$ cmake .. -DCMAKE_BUILD_TYPE=Debug -DFK_YAML_BUILD_TEST=ON
$ cmake --build . --config Debug
$ ctest -C Debug --output-on-failure

If the unit tests failed, you would have to add some configurations for your environment.

Also, I just want to make sure your yaml file is encoded either in UTF-8, UTF-16 or UTF-32, since the other encodings are not supported and could produce unexpected situations.

fktn-k commented 10 months ago

@burgreen

Did you check if you can compile and run the unit tests on your environment?

It's turned out that the compiler you're using has not yet been used in any workflows because the runner image for macOS 13 (Ventura), the only image which pre-installs Apple Clang 14.0.3 according to the docs here, is in the beta stage.
So I created a trial branch to check if the unit tests pass successfully with newer Apple Clang compilers installed in the macOS-13 image.
Given the result, fkYAML should work on your environment too...

burgreen commented 10 months ago

My xcode version is definitely 14.3.1. I am not sure why my gcc/clang --version is showing 14.0.3.

I recompiled using branch trial/ci_with_macos13

$ ctest -X Debug --output-on-failure
Test project /Volumes/work/pkgs/git/fkYAML
No tests were found!!!

??? Your test results for mac-latest shows same No tests were found!!! result.

$ 0--build/test/unit_test/fkYAMLUnitTest
===============================================================================
All tests passed (4540 assertions in 209 test cases)

Yet, the tutorial code still gives errors.

For original novels.yaml: libc++abi: terminating due to uncaught exception of type fkyaml::v0_3_0::parse_error: parse_error: Detected duplication in mapping keys. (at line 5, column 2)

And for simpler yaml: Runs fine.

Here is my test.cpp:

#include <fstream>
#include <iostream>
#include <fkYAML/node.hpp>

int main()
{
    {
    std::ifstream ifs("simple.yaml");
    fkyaml::node root = fkyaml::node::deserialize(ifs);
    auto& novel_node = root["novels"];
    std::cout << novel_node["title"].get_value_ref<std::string&>() << std::endl;
    }

    std::ifstream ifs("novels.yaml");
std::cout << "here1" << std::endl;

    fkyaml::node root = fkyaml::node::deserialize(ifs);
std::cout << "here2" << std::endl;

    for (auto& novel_node : root["novels"])
    {
        std::cout << novel_node["title"].get_value_ref<std::string&>() << std::endl;
    }
std::cout << "here3" << std::endl;

    return 0;
}
burgreen commented 10 months ago

Weird. It is working now. No clue what I changed. Sorry, I know that is zero help for debugging the previous issue.

fktn-k commented 10 months ago

@burgreen Weired... but good to hear it's working!
If you happen to recall what's changed and that should be noted in the tutorial, let me know.
I'll just keep the weiredness in mind for now.

And thanks for reporting no tests being executed in the macos-latest jobs.
It seems that compile warning/error stop building unit tests.
I'll take a closer look at it later.

fktn-k commented 10 months ago

@burgreen
Two issues you reported in this issue have been fixed:

Thanks for your coorporation!

fktn-k commented 10 months ago

I'll close this issue since I think all the fixable issues have been addressed.
Feel free to reopen it if I miss something or something related to this issue is found.