Debian Codegraph @

internal/emit_test.go

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 //go:build !no_antithesis_sdk
2
3 package internal
4
5 import (
6 "encoding/json"
7 "os"
8 "testing"
9 )
10
11 var test_result bool
12
13 func TestLocalHandlerFileOutput(t *testing.T) {
14 path := os.TempDir() + string(os.PathSeparator) + "antithesis-test.log"
15 os.Setenv(localOutputEnvVar, path)
16 defer os.Unsetenv(localOutputEnvVar)
17 handler = openLocalHandler()
18 Json_data(map[string]string{
19 "test": "output",
20 })
21 handler.(*localHandler).outputFile.Close()
22 data, err := os.ReadFile(path)
23 if err != nil {
24 panic(err)
25 }
26 var result map[string]string
27 if err = json.Unmarshal(data, &result); err != nil {
28 panic(err)
29 }
30 if result["test"] != "output" {
31 panic("JSON does not roundtrip")
32 }
33 }
34
35 func TestLocalHandlerNop(t *testing.T) {
36 os.Setenv(localOutputEnvVar, "")
37 defer os.Unsetenv(localOutputEnvVar)
38 handler = openLocalHandler()
39 Json_data(map[string]string{
40 "test": "output",
41 })
42 h, valid := handler.(*localHandler)
43 if !valid {
44 panic("Not using the local handler")
45 }
46 if h.outputFile != nil {
47 panic("Should not be outputting to file")
48 }
49 }
50
51 func TestVoidstarHandlerErr1(t *testing.T) {
52 _, err := openSharedLib("path-not-exists")
53 if err == nil {
54 panic("Should failed to load library")
55 }
56 }
57
58 func TestVoidstarHandlerErr2(t *testing.T) {
59 _, err := openSharedLib(os.Args[0])
60 if err == nil {
61 panic("Should failed to load library")
62 }
63 }
64
65 func TestVoidstarHandlerErr3(t *testing.T) {
66 _, err := openSharedLib("libc.so.6")
67 if err == nil {
68 panic("Should failed to load library")
69 }
70 }