-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add runtime testing for C++ (#1364)
* test: add c++ runtime tests Signed-off-by: Kartik Jolapara <[email protected]> * chore: add generating and testing scripts Signed-off-by: Kartik Jolapara <[email protected]> * chore: add README.md and .gitignore for c++ runtime tests Signed-off-by: Kartik Jolapara <[email protected]> * fix: Complete the issues with json parsing in c++ runtime testing Signed-off-by: Kartik Jolapara <[email protected]> * feat: add ci workflow for c++ runtime testing Signed-off-by: Kartik Jolapara <[email protected]> * fix: change .gitignore Signed-off-by: Kartik Jolapara <[email protected]> * fix: clean unnecessary testing of the own implementation of serialization Signed-off-by: Kartik Jolapara <[email protected]> * chore: comment and remote json utility from c++ runtime testing for now not needed Signed-off-by: Kartik Jolapara <[email protected]> * fix: Remove hardcoded libraries and include git submodule in the c++ runtime testing Signed-off-by: Kartik Jolapara <[email protected]> * fix: clone git submodule in cpp runtime testing Signed-off-by: Kartik Jolapara <[email protected]> * fix: update submodule cloning in github workflow Signed-off-by: Kartik Jolapara <[email protected]> --------- Signed-off-by: Kartik Jolapara <[email protected]> Co-authored-by: Jonas Lagoni <[email protected]>
- Loading branch information
1 parent
d7ccab8
commit 84b0e37
Showing
9 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,32 @@ | ||
name: Runtime testing C++ models | ||
on: | ||
push: | ||
pull_request: | ||
types: [opened, reopened, synchronize, ready_for_review] | ||
paths: | ||
- 'src/generators/cplusplus/**' | ||
- 'test/runtime/runtime-cplusplus/**' | ||
- 'test/runtime/**cplusplus**' | ||
|
||
jobs: | ||
test: | ||
name: Runtime testing C++ Models | ||
if: "github.event.pull_request.draft == false &&!((github.actor == 'asyncapi-bot' && startsWith(github.event.pull_request.title, 'ci: update global workflows')) || (github.actor == 'asyncapi-bot' && startsWith(github.event.pull_request.title, 'chore(release):')) || (github.actor == 'allcontributors' && startsWith(github.event.pull_request.title, 'docs: add')))" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14 | ||
- name: Build library | ||
run: npm install && npm run build:prod | ||
- name: Setup Cpp (C++ / C) | ||
uses: aminya/[email protected] | ||
- name: Generate C++ models | ||
run: npm run generate:runtime:cplusplus | ||
- name: Clone git submodules | ||
run: git submodule update --init --recursive | ||
- name: Run runtime tests | ||
run: npm run test:runtime:cplusplus |
This file contains 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,3 @@ | ||
[submodule "test/runtime/runtime-cplusplus/src/utils/doctest"] | ||
path = test/runtime/runtime-cplusplus/src/utils/doctest | ||
url = https://github.com/doctest/doctest |
This file contains 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 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,12 @@ | ||
import { execCommand } from '../blackbox/utils/Utils'; | ||
import path from 'path'; | ||
|
||
jest.setTimeout(50000); | ||
|
||
test('C++ runtime testing', async () => { | ||
const compileCommand = `cd ${path.resolve( | ||
__dirname, | ||
'./runtime-cplusplus/src' | ||
)} && c++ -std=c++17 -o AddressTest.out AddressTest.cpp && ./AddressTest.out`; | ||
await execCommand(compileCommand); | ||
}); |
This file contains 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,15 @@ | ||
import { CplusplusFileGenerator } from '../../src'; | ||
import path from 'path'; | ||
import input from './generic-input.json'; | ||
|
||
const generator = new CplusplusFileGenerator(); | ||
|
||
generator.generateToFiles( | ||
input, | ||
path.resolve( | ||
// eslint-disable-next-line no-undef | ||
__dirname, | ||
'./runtime-cplusplus/src/lib/generated' | ||
), | ||
{ namespace: 'TestNamespace' } | ||
); |
This file contains 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,32 @@ | ||
# Prerequisites | ||
*.d | ||
|
||
# Compiled Object files | ||
*.slo | ||
*.lo | ||
*.o | ||
*.obj | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Compiled Dynamic libraries | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
# Fortran module files | ||
*.mod | ||
*.smod | ||
|
||
# Compiled Static libraries | ||
*.lai | ||
*.la | ||
*.a | ||
*.lib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app |
This file contains 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,9 @@ | ||
# Modelina C++ Runtime project | ||
|
||
This is the Modelina C++ runtime project that is used to test the Java-generated code from Modelina at runtime to ensure that everything works as expected. | ||
|
||
Here is how it works: | ||
|
||
- The models are first generated during the build phase of the project, by running the root npm script `npm run generate:runtime:cplusplus`. These models are pre-defined with the [generic input](../generic-input.json). | ||
- The tests are manually added and changed. | ||
- When the project is tested, it tests the generated models at runtime for semantic errors. |
This file contains 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,27 @@ | ||
|
||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN | ||
#include "utils/doctest/doctest/doctest.h" | ||
// #include "utils/nlohmann/json.hpp" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "lib/generated/address.hpp" | ||
|
||
// using json = nlohmann::json; | ||
|
||
TEST_CASE("Should make an object of the generated class") | ||
{ | ||
AsyncapiModels::address address; | ||
address.street_name = "Test address 2"; | ||
address.house_number = 2.0; | ||
address.marriage = true; | ||
address.members = 2.0; | ||
std::vector<std::variant<std::string, double, std::any>> array_type; | ||
array_type.push_back(2.0); | ||
array_type.push_back(std::string("test")); | ||
address.array_type = array_type; | ||
AsyncapiModels::nested_object obj; | ||
obj.test = "test"; | ||
address.nested_object = obj; | ||
} |