Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test failure: tests::test_programs::path_14_test_programs_objects_blis ... FAILED #1

Open
ttiimm opened this issue Jun 4, 2024 · 2 comments

Comments

@ttiimm
Copy link
Contributor

ttiimm commented Jun 4, 2024

Saw the following issue on checkout and running cargo test.

---- tests::test_programs::path_14_test_programs_objects_blis stdout ----
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Snapshot Summary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Snapshot file: src/snapshots/blis__tests__test_programs__objects.blis.stdout.snap
Snapshot: test_programs/objects.blis.stdout
Source: src/lib.rs:62
Input file: test_programs/objects.blis
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
func main() {
    let one = Counter.new("uno");
    let two = Counter.new("dos");

    println(one);
    println(one.id, one.name);

    println(two);
    println(two.id, two.name);

    // Eventually, gradual typing will let you prevent this. But for now...
    one.two = two;
    two.one = one;

    println(one.two);
    println(one["two"]);
    println(two.one);
    println(two["one"]);

    println(Counter.new);
    println(one.incr);
    println(one.add);
    println(two.incr);
    println(two.add);
}

let id = 0;

type Counter with {
    func new(name) {
        id = id + 1;

        Counter {
            id = id,
            name = name,
            count = 0,
        }
    }

    func self.incr() {
        self.add(1);
    }

    func self.add(delta) {
        self.count = self.count + delta;
    }
}

main();

─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
-old snapshot
+new results
────────────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    8     8 │ <closure new 0x000000000002>
    9     9 │ <bound method incr 0x000000000004>
   10    10 │ <bound method add 0x000000000005>
   11    11 │ <bound method incr 0x000000000006>
   12       │-<bound method add 0x000000000007>
         12 │+<bound method add 0x000000000006>
────────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
@ttiimm
Copy link
Contributor Author

ttiimm commented Jun 4, 2024

Ahh, did I need to run with the gc_tombstone feature? eg. cargo test --features='gc_tombstone'?

@jdkaplan
Copy link
Owner

jdkaplan commented Jun 4, 2024

Ahh, did I need to run with the gc_tombstone feature? eg. cargo test --features='gc_tombstone'?

Yup, that's it! I usually run cargo make test to get this task because I'm reviewing snapshots. (You can get the cargo make subcommand via cargo-run-bin configured in this repo or from cargo-make itself.)

Those instructions will definitely go in the contributor guide that I've (slowly 😅) been working on. But for now, here's a quick explanation of what's happening:

The snapshots only work as test data if they're deterministic and reproducible. Since objects currently print as their memory locations, I chose to rewrite those IDs into small integers.

But then the garbage collector shows up! The gc_tombstone feature changes the GC to not reuse freed memory. Instead of releasing the memory, it replaces the contents with a special "tombstone" object that panics if it ever gets used. That way, object IDs (memory addresses) never get reused, and we can uniquely identify any object printed in the tests.


I'll leave this open as a reminder to at least one of these things:

  • Make cargo test work without doing anything special
  • Document "how to run tests" as part of a CONTRIBUTING.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants