Skip to content

Commit 687ce7d

Browse files
committed
fixed gui test examples to not run in gui mode if switch not given. added test summary in manifest
1 parent 29cc567 commit 687ce7d

9 files changed

Lines changed: 208 additions & 108 deletions

File tree

.github/workflows/docker.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ jobs:
220220
run: |
221221
SUMMARY_FILE="${GITHUB_STEP_SUMMARY:-$RUNNER_TEMP/manifest_summary.md}"
222222
echo "MANIFEST_SUMMARY_FILE=$SUMMARY_FILE" >> "$GITHUB_ENV"
223-
224223
{
225224
echo "## \`${IMAGE}:${TAG}\`"
226225
echo ""
@@ -245,6 +244,36 @@ jobs:
245244
echo "docker run --rm -it \$VPORTS \$VNC_BIND \$VNC_PASS \$GEO_FLAGS ${IMAGE}:${TAG}"
246245
echo '```'
247246
} >> "$SUMMARY_FILE"
247+
{
248+
echo ""
249+
echo "## Tests"
250+
echo ""
251+
252+
TEST_LOG="${{ runner.temp }}/artifacts/${{ matrix.logs_dir }}/logs/test.log"
253+
254+
if [[ -f "$TEST_LOG" ]]; then
255+
echo '```'
256+
# Always include the final Ok/Fail lines
257+
OK_FAIL="$(tail -n 2 "$TEST_LOG")"
258+
259+
# If there is a "Summary of Failures:" section, include it (without duplicating Ok/Fail)
260+
if grep -q '^Summary of Failures:' "$TEST_LOG"; then
261+
# Print from "Summary of Failures:" up to the line before "Ok:"
262+
# (failures may be empty; this will still print the header if present)
263+
sed -n '/^Summary of Failures:/,/^Ok:/p' "$TEST_LOG" | sed '$d'
264+
echo ""
265+
else
266+
echo "Summary of Failures:"
267+
echo "(none)"
268+
echo ""
269+
fi
270+
271+
echo "$OK_FAIL"
272+
echo '```'
273+
else
274+
echo "_No test log found at:_ \`$TEST_LOG\`"
275+
fi
276+
} >> "$SUMMARY_FILE"
248277
249278
# Also save a copy inside the workspace for artifact upload
250279
mkdir -p "$GITHUB_WORKSPACE/summaries"

ci/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@ esac
9292

9393
echo " > Running meson test with options:" "${meson_args[@]}" | tee -a "$test_log"
9494
meson test "${meson_args[@]}" >> "$test_log"
95-
echo " - Successful: $(grep -m1 'Ok:' "$test_log" | awk '{print $2}')"
96-
echo " - Failures: $(grep -m1 'Fail:' "$test_log" | awk '{print $2}')"
95+
echo " - Successful: $(grep -m1 'Ok:' "$test_log" | awk '{print $2}')" | tee -a "$test_log"
96+
echo " - Failures: $(grep -m1 'Fail:' "$test_log" | awk '{print $2}')" | tee -a "$test_log"
9797
echo " > Complete test log: $test_log"

g4dialog/examples/g4dialog_example.cc

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,52 @@
1212
#include <QTimer>
1313

1414
int main(int argc, char* argv[]) {
15-
16-
QApplication app(argc, argv);
17-
18-
auto gopts =std::make_shared<GOptions>(argc, argv, g4dialog::defineOptions());
19-
20-
auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, G4DIALOG_LOGGER);
15+
// Initialize options and logging
16+
auto gopts = std::make_shared<GOptions>(argc, argv, g4dialog::defineOptions());
17+
auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, G4DIALOG_LOGGER);
18+
auto gui = gopts->getSwitch("gui");
19+
auto timeout = gopts->getScalarDouble("tt");
20+
int ret = EXIT_SUCCESS;
21+
22+
log->info(0, "Starting g4dialog example...");
23+
24+
// Optional GUI setup (only if --gui is passed)
25+
QApplication* app = nullptr;
26+
QMainWindow* window = nullptr;
27+
28+
if (gui) {
29+
log->info(0, "g4dialog", "Running in GUI mode...");
30+
app = new QApplication(argc, argv);
31+
window = new QMainWindow();
32+
window->setWindowTitle(QString::fromUtf8("displayUI example"));
33+
}
2134

2235
auto visManager = new G4VisExecutive;
2336
visManager->Initialize();
2437

25-
// main window and controls
26-
auto window = new QMainWindow();
27-
window->setWindowTitle(QString::fromUtf8("displayUI example"));
28-
29-
auto g4dialog = new G4Dialog(gopts, window);
30-
window->setCentralWidget(g4dialog);
31-
32-
log->info(0, "g4 dialog example started");
33-
int ret = EXIT_SUCCESS;
34-
35-
if (gopts->getSwitch("gui")) {
38+
// If GUI, show the window and run Qt loop
39+
if (gui) {
40+
auto *g4dialog = new G4Dialog(gopts, window);
41+
window->setCentralWidget(g4dialog);
3642
window->show();
3743

38-
// --- quit after 0.5 s ---
39-
QTimer::singleShot(500, &app, &QCoreApplication::quit); // ⬅️ key line :contentReference[oaicite:0]{index=0}
44+
// quit after timeout
45+
QTimer::singleShot(timeout, [] {
46+
QCoreApplication::quit(); // stop the event loop
47+
});
48+
49+
ret = QApplication::exec();
4050

41-
ret = QApplication::exec(); // returns when the timer fires
51+
delete g4dialog;
52+
delete window;
53+
delete app;
54+
}
55+
else {
56+
// CLI mode
57+
log->info(0, "Running g4dialog in command line mode...");
4258
}
4359

44-
delete g4dialog;
45-
delete window;
4660
delete visManager;
4761

4862
return ret;
49-
5063
}

g4display/examples/g4display_example.cc

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,24 @@
1616
#include <QTimer>
1717

1818
int main(int argc, char* argv[]) {
19-
2019
// Initialize options and logging
21-
auto gopts = std::make_shared<GOptions>(argc, argv, g4display::defineOptions());
22-
auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, G4DISPLAY_LOGGER);
20+
auto gopts = std::make_shared<GOptions>(argc, argv, g4display::defineOptions());
21+
auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, G4DISPLAY_LOGGER);
22+
auto gui = gopts->getSwitch("gui");
23+
auto timeout = gopts->getScalarDouble("tt");
24+
int ret = EXIT_SUCCESS;
2325

2426
log->info(0, "Starting g4display example...");
2527

2628
// Optional GUI setup (only if --gui is passed)
2729
QApplication* app = nullptr;
2830
QMainWindow* window = nullptr;
2931

30-
if (gopts->getSwitch("gui")) {
32+
if (gui) {
3133
log->info(0, "g4display", "Running in GUI mode...");
3234
app = new QApplication(argc, argv);
3335
window = new QMainWindow();
34-
window->setWindowTitle(QString::fromUtf8("displayUI example"));
36+
window->setWindowTitle(QString::fromUtf8("g4display example"));
3537
}
3638

3739
auto visManager = new G4VisExecutive;
@@ -40,36 +42,30 @@ int main(int argc, char* argv[]) {
4042
auto g4SceneProperties = new G4SceneProperties(gopts);
4143

4244
// If GUI, show the window and run Qt loop
43-
if (gopts->getSwitch("gui")) {
45+
if (gui) {
4446
auto g4display = new G4Display(gopts, window);
4547
window->setCentralWidget(g4display);
4648
window->show();
4749

48-
/* ---------- quit after 0.5s ---------- */
49-
QTimer::singleShot(500, [] {
50+
// quit after timeout
51+
QTimer::singleShot(timeout, [] {
5052
QCoreApplication::quit(); // stop the event loop
5153
});
5254

53-
int appResult = QApplication::exec();
55+
ret = QApplication::exec();
5456

5557
// Clean up GUI resources
5658
delete g4display;
5759
delete window;
5860
delete app;
59-
60-
// Clean up Geant4 and custom logic
61-
delete g4SceneProperties;
62-
delete visManager;
63-
64-
return appResult;
6561
}
66-
67-
// CLI mode
68-
log->info(0, "Running g4display in command line mode...");
69-
62+
else {
63+
// CLI mode
64+
log->info(0, "Running g4display in command line mode...");
65+
}
7066

7167
delete g4SceneProperties;
7268
delete visManager;
7369

74-
return EXIT_SUCCESS;
70+
return ret;
7571
}

gboard/examples/gboard_example.cc

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,53 @@
1212
#include <QTimer>
1313

1414
int main(int argc, char* argv[]) {
15-
16-
QApplication app(argc, argv);
17-
18-
auto gopts =std::make_shared<GOptions>(argc, argv, gboard::defineOptions());
19-
auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, GBOARD_LOGGER);
15+
// Initialize options and logging
16+
auto gopts = std::make_shared<GOptions>(argc, argv, gboard::defineOptions());
17+
auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, GBOARD_LOGGER);
18+
auto gui = gopts->getSwitch("gui");
19+
auto timeout = gopts->getScalarDouble("tt");
20+
int ret = EXIT_SUCCESS;
21+
22+
log->info(0, "Starting gboard example...");
23+
24+
// Optional GUI setup (only if --gui is passed)
25+
QApplication* app = nullptr;
26+
QMainWindow* window = nullptr;
27+
28+
if (gui) {
29+
log->info(0, "gboard", "Running in GUI mode...");
30+
app = new QApplication(argc, argv);
31+
window = new QMainWindow();
32+
window->setWindowTitle(QString::fromUtf8("displayUI example"));
33+
}
2034

2135
auto visManager = new G4VisExecutive;
2236
visManager->Initialize();
2337

24-
// main window and controls
25-
auto window = new QMainWindow();
26-
window->setWindowTitle(QString::fromUtf8("displayUI example"));
27-
28-
auto* gboard = new GBoard(gopts, window);
29-
window->setCentralWidget(gboard);
30-
31-
auto gui_session = std::make_unique<GUI_Session>(gopts, gboard);
32-
33-
log->info(0, "gboard example started");
34-
int ret = EXIT_SUCCESS;
35-
36-
if (gopts->getSwitch("gui")) {
38+
// If GUI, show the window and run Qt loop
39+
if (gui) {
40+
auto* gboard = new GBoard(gopts, window);
41+
auto gui_session = std::make_unique<GUI_Session>(gopts, gboard);
42+
window->setCentralWidget(gboard);
3743
window->show();
3844

39-
// --- quit after 0.5 s ---
40-
QTimer::singleShot(500, &app, &QCoreApplication::quit); // ⬅️ key line :contentReference[oaicite:0]{index=0}
45+
// quit after timeout
46+
QTimer::singleShot(timeout, [] {
47+
QCoreApplication::quit(); // stop the event loop
48+
});
49+
50+
ret = QApplication::exec();
4151

42-
ret = QApplication::exec(); // returns when the timer fires
52+
delete gboard;
53+
delete window;
54+
delete app;
55+
}
56+
else {
57+
// CLI mode
58+
log->info(0, "Running gboard in command line mode...");
4359
}
4460

45-
delete gboard;
46-
delete window;
4761
delete visManager;
4862

4963
return ret;
50-
5164
}

gqtbuttonswidget/examples/gqtbuttons_example.cc

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,49 @@
11
// gQtButtonsWidget
2-
#include "qapplication.h"
2+
//#include "qapplication.h"
3+
#include "gQtButtonsWidget_options.h"
34
#include "gQtButtonsWidget.h"
45

5-
// gemc
6-
#include "goptions.h"
7-
86
// qt
7+
#include <QApplication>
8+
#include <QMainWindow>
99
#include <QTimer>
1010

11-
1211
int main(int argc, char* argv[]) {
13-
// options not used
14-
auto gopts =std::make_shared<GOptions>(argc, argv, GOptions("hello"));
12+
// Initialize options and logging
13+
auto gopts = std::make_shared<GOptions>(argc, argv, GOptions("hello"));
14+
auto gui = gopts->getSwitch("gui");
1515
auto timeout = gopts->getScalarDouble("tt");
16+
int ret = EXIT_SUCCESS;
1617

17-
QApplication app(argc, argv);
18+
// Optional GUI setup (only if --gui is passed)
19+
QApplication* app = nullptr;
1820

19-
std::vector<std::string> bicons;
21+
if (gui) {
22+
app = new QApplication(argc, argv);
23+
}
2024

2125
// notice path must match the path in the qrc file
26+
std::vector<std::string> bicons;
2227
bicons.emplace_back(":/images/firstButton");
2328
bicons.emplace_back(":/images/secondButton");
2429

25-
int ret = EXIT_SUCCESS;
2630

27-
if (gopts->getSwitch("gui")) {
31+
if (gui) {
2832
GQTButtonsWidget window(128, 128, bicons);
2933
window.show();
30-
// --- quit after 0.5 s ---
31-
QTimer::singleShot(timeout, &app, &QCoreApplication::quit); // ⬅️ key line :contentReference[oaicite:0]{index=0}
3234

33-
ret = QApplication::exec(); // returns when the timer fires
35+
// quit after timeout
36+
QTimer::singleShot(timeout, [] {
37+
QCoreApplication::quit(); // stop the event loop
38+
});
39+
40+
ret = QApplication::exec();
41+
42+
// Clean up GUI resources
43+
delete app;
44+
}
45+
else {
46+
// CLI mode
3447
}
3548

3649
return ret;

0 commit comments

Comments
 (0)