Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5db19ae
[bfops/consolidate-default-tests]: C++/Rust schema compare tests
bfops Jul 29, 2026
1b08167
[bfops/consolidate-default-tests]: [revert this] strip down CI
bfops Jul 29, 2026
de11ccf
[bfops/consolidate-default-tests]: fix
bfops Jul 29, 2026
b1e810a
[bfops/consolidate-default-tests]: fix
bfops Jul 29, 2026
d292c68
[bfops/test-suite-fixes]: fix non-forwarded option
bfops Jul 29, 2026
d22a17e
[bfops/test-suite-fixes]: fix
bfops Jul 29, 2026
73c4b6f
[bfops/test-suite-fixes]: review
bfops Jul 29, 2026
18e7aa1
[bfops/test-suite-fixes]: review
bfops Jul 29, 2026
65d2b3e
[bfops/test-suite-fixes]: review
bfops Jul 29, 2026
c439c83
[bfops/test-suite-fixes]: restore comments
bfops Jul 29, 2026
563b102
[bfops/test-suite-fixes]: review
bfops Jul 29, 2026
5c9a37c
[bfops/test-suite-fixes]: review
bfops Jul 29, 2026
b1c18f1
[bfops/consolidate-default-tests]: Merge remote-tracking branch 'orig…
bfops Jul 29, 2026
3e7258b
[bfops/consolidate-default-tests]: revert
bfops Jul 29, 2026
a7e8636
[bfops/consolidate-default-tests]: WIP tests
bfops Jul 29, 2026
28b04f5
[bfops/consolidate-default-tests]: fixes
bfops Jul 29, 2026
2e66dcc
[bfops/consolidate-default-tests]: comment out
bfops Jul 29, 2026
cccd876
[bfops/consolidate-default-tests]: empty
bfops Jul 29, 2026
fa604aa
[bfops/consolidate-default-tests]: empty
bfops Jul 29, 2026
d95227d
[bfops/consolidate-default-tests]: empty
bfops Jul 29, 2026
b0f93a4
[bfops/consolidate-default-tests]: moar fix
bfops Jul 29, 2026
b3ec5f3
Apply suggestion from @bfops
bfops Jul 29, 2026
d75c708
[bfops/consolidate-default-tests]: actually comment
bfops Jul 29, 2026
0139f87
[bfops/consolidate-default-tests]: Merge branch 'bfops/consolidate-de…
bfops Jul 29, 2026
ba86014
[bfops/consolidate-default-tests]: more comment out
bfops Jul 29, 2026
60caa8f
[bfops/consolidate-default-tests]: fix C#
bfops Jul 29, 2026
89a4110
[bfops/consolidate-default-tests]: C# f32s
bfops Jul 29, 2026
fd633dd
[bfops/consolidate-default-tests]: comment
bfops Jul 29, 2026
c8cf4f3
[bfops/consolidate-default-tests]: negative and positive floating points
bfops Jul 29, 2026
42e0b98
[bfops/consolidate-default-tests]: cargo fmt
bfops Jul 29, 2026
42b607d
[bfops/consolidate-default-tests]: comments
bfops Jul 29, 2026
757f729
Merge branch 'master' into bfops/consolidate-default-tests
bfops Jul 30, 2026
5c5f6bb
[bfops/consolidate-default-tests]: update comments
bfops Jul 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
311 changes: 311 additions & 0 deletions crates/smoketests/tests/smoketests/column_defaults.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
use spacetimedb_smoketests::{
random_string, require_dotnet, require_emscripten, require_pnpm, ModuleLanguage, Smoketest,
};

const EXPECTED_DEFAULTS: &[(&str, &str)] = &[
Comment thread
gefjon marked this conversation as resolved.
("bool_value", "true"),
("u8_value", "8"),
// TODO: uncomment this once negative defaults are fixed in Rust
// https://github.com/clockworklabs/SpacetimeDB/issues/5622
//("i8_value", "-8"),
("u16_value", "16"),
// TODO: uncomment this once negative defaults are fixed in Rust
// https://github.com/clockworklabs/SpacetimeDB/issues/5622
//("i16_value", "-16"),
("u32_value", "32"),
// TODO: uncomment this once negative defaults are fixed in Rust
// https://github.com/clockworklabs/SpacetimeDB/issues/5622
//("i32_value", "-32"),

// TODO: uncomment once u64s are fixed.
// https://github.com/clockworklabs/SpacetimeDB/issues/5623
//("u64_value", "64"),

// TODO: uncomment this once negative defaults are fixed in Rust
// https://github.com/clockworklabs/SpacetimeDB/issues/5622
//("i64_value", "-64"),

// TODO: uncomment once floats are fixed in C# and f32s are fixed in Rust
// https://github.com/clockworklabs/SpacetimeDB/issues/5624
// https://github.com/clockworklabs/SpacetimeDB/issues/5627
//("f32_positive_value", "32.5"),

// TODO: uncomment once floats are fixed in C#, f32s are fixed in Rust, and negative defaults are fixed in Rust
// https://github.com/clockworklabs/SpacetimeDB/issues/5624
// https://github.com/clockworklabs/SpacetimeDB/issues/5627
// https://github.com/clockworklabs/SpacetimeDB/issues/5622
//("f32_negative_value", "-32.5"),
("f64_positive_value", "64.25"),
// TODO: uncomment once negative defaults are fixed in Rust
// https://github.com/clockworklabs/SpacetimeDB/issues/5622
//("f64_negative_value", "-64.25"),

// TODO: uncomment this once string default values are fixed in Rust
//("string_value", r#""default string""#),
Comment on lines +8 to +44

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For any of these commented-out cases that you don't intend to fix before merging this PR, please update the issue to mention that the test should be uncommented when completed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fixes in #5630 turned out to be pretty small, and you discovered that we've actually fixed all 4 bugs - what do you think about merging #5630 into this one?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess strings are still outstanding but will be fixed by #5562 . Yeah, happy to merge #5630 into this PR.

];

fn test_defaults(test: &mut Smoketest, publish_updated: impl FnOnce(&mut Smoketest)) {
test.sql("INSERT INTO defaults_test_table (id) VALUES (1)").unwrap();
publish_updated(test);

for &(column, expected) in EXPECTED_DEFAULTS {
let output = test
.sql(&format!("SELECT {column} FROM defaults_test_table WHERE id = 1"))
.unwrap();
let actual = output.lines().last().unwrap().trim();
assert_eq!(actual, expected, "incorrect default for column {column}");
}
}

fn test_source_defaults(language: ModuleLanguage, project_name: &str, initial: &str, updated: &str) {
let mut test = Smoketest::builder().autopublish(false).build();
let database_name = format!("column-defaults-{project_name}-{}", random_string());
let initial_project_name = format!("{project_name}-initial");
let updated_project_name = format!("{project_name}-updated");
test.publish()
.name(&database_name)
.source(language, &initial_project_name, initial)
.run()
.unwrap();

test_defaults(&mut test, |test| {
test.publish()
.current_database()
.unwrap()
.break_clients(true)
.source(language, &updated_project_name, updated)
.run()
.unwrap();
});
}

#[test]
fn test_rust_column_defaults() {
let mut test = Smoketest::builder().module_code(RUST_INITIAL).build();
test_defaults(&mut test, |test| {
test.write_module_code(RUST_UPDATED).unwrap();
test.publish()
.current_database()
.unwrap()
.break_clients(true)
.run()
.unwrap();
});
}

#[test]
fn test_typescript_column_defaults() {
require_pnpm!();
test_source_defaults(
ModuleLanguage::TypeScript,
"column-defaults-ts",
TYPESCRIPT_INITIAL,
TYPESCRIPT_UPDATED,
);
}

#[test]
fn test_csharp_column_defaults() {
require_dotnet!();
test_source_defaults(
ModuleLanguage::CSharp,
"column-defaults-csharp",
CSHARP_INITIAL,
CSHARP_UPDATED,
);
}

#[test]
fn test_cpp_column_defaults() {
require_emscripten!();
test_source_defaults(ModuleLanguage::Cpp, "column-defaults-cpp", CPP_INITIAL, CPP_UPDATED);
}

const RUST_INITIAL: &str = r#"
#[spacetimedb::table(accessor = defaults_test_table, public)]
pub struct DefaultsTestTable {
pub id: u32,
}
"#;

const RUST_UPDATED: &str = r#"
#[spacetimedb::table(accessor = defaults_test_table, public)]
pub struct DefaultsTestTable {
pub id: u32,
#[default(true)]
pub bool_value: bool,
// #[default(-8)]
// pub i8_value: i8,
#[default(8)]
pub u8_value: u8,
// #[default(-16)]
// pub i16_value: i16,
#[default(16)]
pub u16_value: u16,
// #[default(-32)]
// pub i32_value: i32,
#[default(32)]
pub u32_value: u32,
// #[default(-64)]
// pub i64_value: i64,
// #[default(64)]
// pub u64_value: u64,
#[default(32.5)]
pub f32_positive_value: f32,
// #[default(-32.5)]
// pub f32_negative_value: f32,
#[default(64.25)]
pub f64_positive_value: f64,
// #[default(-64.25)]
// pub f64_negative_value: f64,
// #[default("default string")]
// pub string_value: String,
}
"#;

const TYPESCRIPT_INITIAL: &str = r#"
import { schema, t, table } from "spacetimedb/server";

const defaultsTestTable = table(
{ name: "defaults_test_table", public: true },
{ id: t.u32() }
);

export default schema({ defaultsTestTable });
"#;

const TYPESCRIPT_UPDATED: &str = r#"
import { schema, t, table } from "spacetimedb/server";

const defaultsTestTable = table(
{ name: "defaults_test_table", public: true },
{
id: t.u32(),
bool_value: t.bool().default(true),
i8_value: t.i8().default(-8),
u8_value: t.u8().default(8),
i16_value: t.i16().default(-16),
u16_value: t.u16().default(16),
i32_value: t.i32().default(-32),
u32_value: t.u32().default(32),
i64_value: t.i64().default(-64n),
u64_value: t.u64().default(64n),
f32_positive_value: t.f32().default(32.5),
f32_negative_value: t.f32().default(-32.5),
f64_positive_value: t.f64().default(64.25),
f64_negative_value: t.f64().default(-64.25),
string_value: t.string().default("default string"),
}
);

export default schema({ defaultsTestTable });
"#;

const CSHARP_INITIAL: &str = r#"
using SpacetimeDB;

public static partial class Module
{
[Table(Accessor = "defaults_test_table", Public = true)]
public partial struct DefaultsTestTable
{
public uint id;
}
}
"#;

const CSHARP_UPDATED: &str = r#"
using SpacetimeDB;

public static partial class Module
{
[Table(Accessor = "defaults_test_table", Public = true)]
public partial struct DefaultsTestTable
{
public uint id;
[Default(true)] public bool bool_value;
[Default((sbyte)-8)] public sbyte i8_value;
[Default((byte)8)] public byte u8_value;
[Default((short)-16)] public short i16_value;
[Default((ushort)16)] public ushort u16_value;
[Default(-32)] public int i32_value;
[Default(32U)] public uint u32_value;
[Default(-64L)] public long i64_value;
[Default(64UL)] public ulong u64_value;
//[Default(32.5f)] public float f32_positive_value;
//[Default(-32.5f)] public float f32_negative_value;
[Default(64.25)] public double f64_positive_value;
[Default(-64.25)] public double f64_negative_value;
[Default("default string")] public string string_value;
}
}
"#;

const CPP_INITIAL: &str = r#"
#include "spacetimedb.h"

using namespace SpacetimeDB;

struct DefaultsTestTable {
uint32_t id;
};
SPACETIMEDB_STRUCT(DefaultsTestTable, id)
SPACETIMEDB_TABLE(DefaultsTestTable, defaults_test_table, Public)
"#;

const CPP_UPDATED: &str = r#"
#include "spacetimedb.h"

using namespace SpacetimeDB;

struct DefaultsTestTable {
uint32_t id;
bool bool_value;
int8_t i8_value;
uint8_t u8_value;
int16_t i16_value;
uint16_t u16_value;
int32_t i32_value;
uint32_t u32_value;
int64_t i64_value;
uint64_t u64_value;
float f32_positive_value;
float f32_negative_value;
double f64_positive_value;
double f64_negative_value;
std::string string_value;
};
SPACETIMEDB_STRUCT(
DefaultsTestTable,
id,
bool_value,
i8_value,
u8_value,
i16_value,
u16_value,
i32_value,
u32_value,
i64_value,
u64_value,
f32_positive_value,
f32_negative_value,
f64_positive_value,
f64_negative_value,
string_value
)
SPACETIMEDB_TABLE(DefaultsTestTable, defaults_test_table, Public)
FIELD_Default(defaults_test_table, bool_value, true)
FIELD_Default(defaults_test_table, i8_value, int8_t(-8))
FIELD_Default(defaults_test_table, u8_value, uint8_t(8))
FIELD_Default(defaults_test_table, i16_value, int16_t(-16))
FIELD_Default(defaults_test_table, u16_value, uint16_t(16))
FIELD_Default(defaults_test_table, i32_value, int32_t(-32))
FIELD_Default(defaults_test_table, u32_value, uint32_t(32))
FIELD_Default(defaults_test_table, i64_value, int64_t(-64))
FIELD_Default(defaults_test_table, u64_value, uint64_t(64))
FIELD_Default(defaults_test_table, f32_positive_value, float(32.5))
FIELD_Default(defaults_test_table, f32_negative_value, float(-32.5))
FIELD_Default(defaults_test_table, f64_positive_value, double(64.25))
FIELD_Default(defaults_test_table, f64_negative_value, double(-64.25))
FIELD_Default(defaults_test_table, string_value, std::string("default string"))
"#;
1 change: 1 addition & 0 deletions crates/smoketests/tests/smoketests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod call;
mod change_host_type;
mod cli;
mod client_connection_errors;
mod column_defaults;
mod confirmed_reads;
mod connect_disconnect_from_cli;
mod create_project;
Expand Down
Loading