<commit_before>defmodule FarmbotOs.AvrdudeTest do
  use ExUnit.Case

  use Mimic

  setup :verify_on_exit!

  test "works" do
    File.touch("/tmp/wow")

    expect(Avrdude.MuonTrapAdapter, :cmd, fn cmd, args, opts ->
      assert cmd == "avrdude"

      assert args == [
               "-patmega2560",
               "-cwiring",
               "-P/dev/null",
               "-b115200",
               "-D",
               "-V",
               "-Uflash:w:/tmp/wow:i"
             ]

      assert opts == [
               into: %IO.Stream{
                 device: :standard_io,
                 line_or_bytes: :line,
                 raw: false
               },
               stderr_to_stdout: true
             ]
    end)

    Avrdude.flash("/tmp/wow", "null", fn ->
      "YOLO"
    end)
  end
end<commit_msg>Test AVRDude edge cases<commit_after>defmodule FarmbotOs.AvrdudeTest do
  use ExUnit.Case

  use Mimic

  setup :verify_on_exit!

  test "failure handling" do
    reset_fn = fn ->
      raise RuntimeError, "foo"
    end

    expect(FarmbotCore.LogExecutor, :execute, 1, fn log ->
      msg = log.message
      assert String.contains?(msg, "%RuntimeError{message: \"foo\"}")
    end)

    Avrdude.call_reset_fun(reset_fn)
  end

  test "works" do
    File.touch("/tmp/wow")

    expect(Avrdude.MuonTrapAdapter, :cmd, fn cmd, args, opts ->
      assert cmd == "avrdude"

      assert args == [
               "-patmega2560",
               "-cwiring",
               "-P/dev/null",
               "-b115200",
               "-D",
               "-V",
               "-Uflash:w:/tmp/wow:i"
             ]

      assert opts == [
               into: %IO.Stream{
                 device: :standard_io,
                 line_or_bytes: :line,
                 raw: false
               },
               stderr_to_stdout: true
             ]
    end)

    Avrdude.flash("/tmp/wow", "null", fn ->
      "YOLO"
    end)
  end

  test "handles /dev file names, also" do
    File.touch("/tmp/wow")

    expect(Avrdude.MuonTrapAdapter, :cmd, fn cmd, args, opts ->
      assert cmd == "avrdude"

      assert args == [
               "-patmega2560",
               "-cwiring",
               "-P/dev/null",
               "-b115200",
               "-D",
               "-V",
               "-Uflash:w:/tmp/wow:i"
             ]

      assert opts == [
               into: %IO.Stream{
                 device: :standard_io,
                 line_or_bytes: :line,
                 raw: false
               },
               stderr_to_stdout: true
             ]
    end)

    Avrdude.flash("/tmp/wow", "/dev/null", fn ->
      "YOLO"
    end)
  end
end
{'fraction_non_alphanumeric': 0.12697814619442352, 'fraction_numerical': 0.011680482290881688, 'mean_word_length': 1.2386172006745362, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1557206', 'n_tokens_mistral': 889, 'n_tokens_neox': 825, 'n_words': 173}