Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
embedding example now also a test
  • Loading branch information
Drew O'Meara committed Feb 11, 2022
commit 835e6b0067513db9e95a56fbb92f2ff3c063f566
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ cover.out

# tests
builtin/testfile
examples/embedding/embedding
18 changes: 18 additions & 0 deletions examples/embedding/embedding-test-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

Welcome to a gpython embedded example,
where your wildest Go-based python dreams come true!

==========================================================
Python 3.4 (github.com/go-python/gpython)
go1.17.6 on darwin amd64
==========================================================

Spring Break itinerary:
Stop 1: Miami, Florida | 7 nights
Stop 2: Mallorca, Spain | 3 nights
Stop 3: Ibiza, Spain | 14 nights
Stop 4: Monaco | 12 nights
### Made with Vacaton 1.0 by Fletch F. Fletcher

I bet Monaco will be the best!

45 changes: 45 additions & 0 deletions examples/embedding/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"bytes"
"os"
"os/exec"
"testing"
)

const embeddingTestOutput = "embedding-test-output.txt"
Comment thread
drew-512 marked this conversation as resolved.
Outdated

func TestEmbeddedExample(t *testing.T) {

cmd := exec.Command("go", "build", ".")
Comment thread
drew-512 marked this conversation as resolved.
Outdated
err := cmd.Run()
if err != nil {
t.Fatalf("failed to compile embedding example: %v", err)
}

out := new(bytes.Buffer)
cmd = exec.Command("./embedding", "mylib-demo.py")
Comment thread
drew-512 marked this conversation as resolved.
Outdated
cmd.Stdout = out

err = cmd.Run()
if err != nil {
t.Fatalf("failed to run embedding binary: %v", err)
}

resetTest := false // true
testOutput := out.Bytes()
if resetTest {
err = os.WriteFile(embeddingTestOutput, testOutput, 0644)
if err != nil {
t.Fatalf("failed to write test output: %v", err)
}
} else {
Comment thread
drew-512 marked this conversation as resolved.
Outdated
mustMatch, err := os.ReadFile(embeddingTestOutput)
if err != nil {
t.Fatalf("failed read %q", embeddingTestOutput)
}
if !bytes.Equal(testOutput, mustMatch) {
t.Fatalf("embedded test output did not match accepted output from %q", embeddingTestOutput)
}
}
Comment thread
drew-512 marked this conversation as resolved.
}