<commit_before>package main

import (
	"testing"
)

func TestListen(t *testing.T) {
	// The net package predates wrapped errors and such, and
	// as such is inconvenient. So we divide tests into error-full
	// and error-free.

	// All these tests expect err to be non-nil.
	var tests = []struct {
		network string
		port    string
	}{
		{"blarg", "17010"},
		{"vsock", "xyz"},
	}

	for _, tt := range tests {
		_, err := listen(tt.network, tt.port)
		if err == nil {
			t.Errorf("Listen(%v, %v): nil != some error", tt.network, tt.port)
			continue
		}
	}

	// These should all work.
	var oktests = []struct {
		network string
		port    string
	}{
		{"tcp", "17010"},
		{"tcp4", "17010"},
		{"tcp6", "17010"},
		// Damn. Can't easily test this b/c environments vary so much.
		//{"vsock", "17010"},
		{"unix", "@foobar"},
	}

	for _, tt := range oktests {
		ln, err := listen(tt.network, tt.port)
		if err != nil {
			t.Errorf("Listen(%v, %v): err != nil", tt.network, tt.port)
			continue
		}
		if ln == nil {
			t.Errorf("Listen(%v, %v): ln is nil, not non-nil", tt.network, tt.port)
			continue
		}
		if err := ln.Close(); err != nil {
			t.Errorf("%v.Close: %v != nil", ln, err)
		}
	}
}
<commit_msg>Handle no IPv4 or vsock in serve_test<commit_after>package main

import (
	"errors"
	"os"
	"syscall"
	"testing"
)

func TestListen(t *testing.T) {
	// The net package predates wrapped errors and such, and
	// as such is inconvenient. So we divide tests into error-full
	// and error-free.

	// All these tests expect err to be non-nil.
	var tests = []struct {
		network string
		port    string
	}{
		{"blarg", "17010"},
		{"vsock", "xyz"},
	}

	for _, tt := range tests {
		_, err := listen(tt.network, tt.port)
		if err == nil {
			t.Errorf("Listen(%v, %v): nil != some error", tt.network, tt.port)
			continue
		}
	}

	// These should all work.
	var oktests = []struct {
		network string
		port    string
	}{
		{"tcp", "17010"},
		{"tcp4", "17010"},
		{"tcp6", "17010"},
		{"vsock", "17010"},
		{"unix", "@foobar"},
	}

	for _, tt := range oktests {
		ln, err := listen(tt.network, tt.port)
		if err != nil {
			var sysErr *os.SyscallError
			if errors.As(err, &sysErr) && sysErr.Err == syscall.EAFNOSUPPORT {
				// e.g. no ipv4 or vsock
				continue;
			}
			t.Errorf("Listen(%v, %v): err != nil", tt.network, tt.port)
			continue
		}
		if ln == nil {
			t.Errorf("Listen(%v, %v): ln is nil, not non-nil", tt.network, tt.port)
			continue
		}
		if err := ln.Close(); err != nil {
			t.Errorf("%v.Close: %v != nil", ln, err)
		}
	}
}

{'fraction_non_alphanumeric': 0.18181818181818182, 'fraction_numerical': 0.02203856749311295, 'mean_word_length': 2.788375558867362, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3271332', 'n_tokens_mistral': 1096, 'n_tokens_neox': 949, 'n_words': 287}