mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-31 06:42:07 +00:00
Fix unit-test segfault on missing shipped profile in sparse CI checkout
The Unit Tests job sparse-checks-out only .github/scripts/tests, so the baked-in absolute PROFILES_DIR was missing at runtime; the shipped-profile test then read a non-existent JSON and null-dereferenced in opt_string. Check out resources/ in the unit-test job, and guard the test helper to skip when the profile is absent and require the key before dereferencing.
This commit is contained in:
6
.github/workflows/unit_tests.yml
vendored
6
.github/workflows/unit_tests.yml
vendored
@@ -28,11 +28,15 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v7
|
uses: actions/checkout@v7
|
||||||
with:
|
with:
|
||||||
# tests/data is referenced by absolute path (TEST_DATA_DIR).
|
# Tests reach outside tests/ at runtime: tests/data (TEST_DATA_DIR) and
|
||||||
|
# resources/profiles (PROFILES_DIR) by baked-in absolute path, plus
|
||||||
|
# resources/info (nozzle data) via resources_dir() during a real slice.
|
||||||
|
# Check out all of resources/ so no test hits a missing-file path.
|
||||||
sparse-checkout: |
|
sparse-checkout: |
|
||||||
.github
|
.github
|
||||||
scripts
|
scripts
|
||||||
tests
|
tests
|
||||||
|
resources
|
||||||
- name: Apt-Install Dependencies
|
- name: Apt-Install Dependencies
|
||||||
if: runner.os == 'Linux' && !vars.SELF_HOSTED
|
if: runner.os == 'Linux' && !vars.SELF_HOSTED
|
||||||
uses: ./.github/actions/apt-install-deps
|
uses: ./.github/actions/apt-install-deps
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
#include "libslic3r/Print.hpp"
|
#include "libslic3r/Print.hpp"
|
||||||
#include "libslic3r/ModelArrange.hpp"
|
#include "libslic3r/ModelArrange.hpp"
|
||||||
|
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include "test_helpers.hpp"
|
#include "test_helpers.hpp"
|
||||||
|
|
||||||
using namespace Slic3r;
|
using namespace Slic3r;
|
||||||
@@ -723,11 +725,19 @@ static std::string slice_two_object_bbl(DynamicPrintConfig &config)
|
|||||||
// The real change_filament_gcode of a shipped "<printer> 0.4 nozzle" machine profile.
|
// The real change_filament_gcode of a shipped "<printer> 0.4 nozzle" machine profile.
|
||||||
static std::string shipped_change_filament_gcode(const std::string &printer)
|
static std::string shipped_change_filament_gcode(const std::string &printer)
|
||||||
{
|
{
|
||||||
const std::string path = std::string(PROFILES_DIR) + "/BBL/machine/Bambu Lab " + printer + " 0.4 nozzle.json";
|
const std::string path = std::string(PROFILES_DIR) + "/BBL/machine/Bambu Lab " + printer + " 0.4 nozzle.json";
|
||||||
|
// PROFILES_DIR is an absolute path baked in at build time; a sparse test checkout
|
||||||
|
// without resources/ leaves it missing. Skip rather than dereference a config that
|
||||||
|
// never loaded - this is the only fff_print test that reads a shipped profile.
|
||||||
|
if (!boost::filesystem::exists(path))
|
||||||
|
SKIP("shipped profile not present in this checkout: " << path);
|
||||||
DynamicPrintConfig config;
|
DynamicPrintConfig config;
|
||||||
std::map<std::string, std::string> key_values;
|
std::map<std::string, std::string> key_values;
|
||||||
std::string reason;
|
std::string reason;
|
||||||
config.load_from_json(path, ForwardCompatibilitySubstitutionRule::Enable, key_values, reason);
|
config.load_from_json(path, ForwardCompatibilitySubstitutionRule::Enable, key_values, reason);
|
||||||
|
// Fail loudly on a malformed/renamed profile instead of null-dereferencing in opt_string.
|
||||||
|
INFO("profile: " << path << (reason.empty() ? "" : (" load reason: " + reason)));
|
||||||
|
REQUIRE(config.has("change_filament_gcode"));
|
||||||
return config.opt_string("change_filament_gcode");
|
return config.opt_string("change_filament_gcode");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user