File: system_spec.cr

package info (click to toggle)
crystal 1.14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 24,384 kB
  • sloc: javascript: 6,400; sh: 695; makefile: 269; ansic: 121; python: 105; cpp: 77; xml: 32
file content (29 lines) | stat: -rw-r--r-- 920 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require "./spec_helper"
require "system"

describe System do
  describe "hostname" do
    # can't use backtick in interpreted code (#12241)
    pending_interpreted "returns current hostname" do
      shell_hostname = `hostname`.strip
      pending! "`hostname` command was unsuccessful" unless $?.success?

      hostname = System.hostname
      hostname.should eq(shell_hostname)
    end
  end

  describe "cpu_count" do
    # can't use backtick in interpreted code (#12241)
    pending_interpreted "returns current CPU count" do
      shell_cpus =
        {% if flag?(:win32) %}
          ENV["NUMBER_OF_PROCESSORS"].to_i
        {% elsif flag?(:unix) %}
          `getconf _NPROCESSORS_ONLN 2>/dev/null || nproc --all 2>/dev/null || grep -sc '^processor' /proc/cpuinfo || sysctl -n hw.ncpu 2>/dev/null`.to_i
        {% end %}
      cpu_count = System.cpu_count
      cpu_count.should eq(shell_cpus)
    end
  end
end